To make a headtracker for FatShark Predator FPV goggles to work with a dji Phantom V2 with Tarot T-2D GoPro gimbal.
The dji controller has a pinwheel to control the angle of elevation of the camera. This is attached to an autocentering pot.
The voltages present on the pot pins are 0v and 3.3v for pins 3 and 1 and represent the maximum range for the wiper on pin 2.
Depending on the mode, the mode the gimbal is set to, these represent either the position of the camera or the speed up/down. What we need to do is to provide a dc voltage to pin 2 of the pot between 0v and 3.3v that is proportional to the angle of the FPV goggles.
What can we use to convert the angle of the FPV goggles to a proportional dc voltage?
Well, and MPU6050 accelerometer/gyroscope and an Arduino Nano are small enough to fit inside the goggles and can be powered from the goggles supply.
Extracting an accurate angle from an MPU6050 is not exactly straight forward, but it can be done.
This angle can be outputted to one of the Nano's PWM pins.
A PWM output is not what we want however. We're after a variable dc voltage. Furthermore, the PWM output is 0v or 5v only.
The solution is to integrate the PWM signal, or calculate the area under the pulse and output it as a voltage.
This sounds like a complicated task, but in reality, the solution is very simple.
A low pass filter with a very low cut-off frequency acts like an integrator, and has the added bonus in this application that if we make it with a really low cut-off frequency, it is relatively slow to respond. This gives a smooth output response.
With a suitably high value trim pot acting as a potential divider on the end, we can bring the max output down to the required 3.3v. It's also worth noting that the circuit will never quite reach 0v as there will always be a pulse on the output pin of the Arduino, but we can get enough of a swing on the output to suit our needs.
Since we're using the supply for the FPV goggles to power the Arduino and MPU6050, and we're connecting the output of this to the Phantom controller, we need to give them both a common ground. Only two wires are needed to connect the goggles to the controller. I've used an 1/8" jack lead for this.
Step 1: The Electronics
The schematic says it all really, but it's worth mentioning that I found it easier to mount the Arduino Nano with the MPU6050 in the goggles, and the filter and trim pot, along with a DPDT toggle switch in the controller.
The MPU6050 needs to be firmly attached to the goggles. Araldite did the job for me.
There was just enough room to mount the jack socket, and the Nano is just wedged in the upper side of the goggles.
The three wires that connect the pinwheel pot to the main Phantom controller board are:
Brown - Gnd
Yellow - wiper
Red - 3.3v
At least they are on mine, but I'd suggest taking a meter to them and making sure.
I left the 3.3v one alone, but cut the Gnd and Wiper and connected them through a DPDT toggle switch so I could select between the pinwheel and headtracker inputs.
The Gnd could have been left connected, but it was easier to mount the switch to the chassis and have two wires holding the trackboard to the switch.
Step 2: The Code
Here it is!
The majority of the code is concerned with getting the angle out of the MPU6050, but once that's done, it is just a case of setting limits for the angle:
angle = constrain(angle_y,-90,45);
Mapping it to the full range of the PWM pin:
angleOut = map(angle, -90,45,0,255)
And sending it to the PWM pin:
Step 3: The Output
The three pics show the output of the PWM pin on the left and the filter output on the right.
They show the min (down),max (up) and mid positions of the goggles.