DOF (Degree Of Freedom) Sensors
When I started this project, I hesitated a lot on what DOF sensors I should buy. It was obvious to me that I would need a 9 degrees of freedom to avoid the infinite rotating effect that 6 DOF would create.
But then I discovered this code with a demo running on Free_IMU. It was perfectly still! Even after many random moves, the Yaw axe seems to be only a few degrees different while the Pitch and Roll stays perfectly level (see the plane picture above if you don't understand the three axes) which is perfectly fine for me for now... In addition, Eulers angles can be calculated with a "home reference position". Very useful for calibrating our sensors!
The schematic of the device is above. Here are the components to build one :
- AirBoard, Arduino FIO or DIY solution. FIO Arduino bootloader runs with an 8MHz crystal (instead of 16MHz on the UNO) which allows it to be used in lower voltage. So if you have an Arduino project running on a battery, it is a great strategy to directly start with a 8MHz board (Or you can use the internal 8Mhz oscillator). Of course if your project needs the full performance of the UNO, this may create problems, but most of them don't...
- MPU 6050, 6DOF sensor which communicates with the Arduino over I2C
- NRF24L01+ Bluetooth chip which communicates with SPI. This board became very famous because of its great manufacturer NORDIC (which is a reference in BT devices) but also because of its amazingly cheap price : less than 1$! If we also consider the fact that it allows multi-channel communication, you have yourself a perfect toy to play with!
- Dip switch to select devices
- Lipo Battery
- Headers and wires to charge the battery and push the program.
For debugging this project, I used several Arduino Airboard from a Kickstarter project. This amazing little board embeds a FIO, a Battery, a power switch, LEDs... Plus, it accepts remote programming over a dedicated BLE chip and a USB dongle. I recommend using those for debugging embedded battery projects, it will save you a lot of time!
Processing test software (Also in Github here) I already talked a bit about the library for the 6DOF sensor. If you want to give it a try, download this code and wire the sensor to an Arduino board. Once processing, start the IMU interface and you can start playing. The "h" key will recalibrate the sensor.
The Euler angles problems & solutions
Playing with 3D object rotations is a hard work. Using Arduino libraries and Pi3D helped me a lot to control the movement for one object. But I am still debugging a bit when the movement of one sensor depend on the movement of another. For example, hands movements depend on arms movements. So the angles of the hands have to be "HANDS_ANGLES - ARMS_ANGLES = REAL_HANDS_ANGLES". As Euler values aren't linear, "-ARMS_ANGLES" isn't the opposite of "ARMS_ANGLES"...
To implement this part, I worked on two solutions :
- SOLUTION 1 : The nodes send only the 4 quaternions on Bluetooth. The central receive and calculate Euler angles. When the quaternions of the hands is received, the Euler is calculated depending on the arms quaternions as "home reference". This solution works, but the central needs more time to calculate.
- SOLUTION 2 : My first choice was to calculate Euler angles inside the nodes and send them over Bluetooth (which is nice because I still have one empty byte on the buffer for the button). In Pi3D I tried to implement the Hands depending on the arm, but it's still not working perfectly right now. If you are interested in this topic, you can take a look on the conversation I had with paddyg here.
As you can see, those 6-DOF sensors are quite precise. But without a compass, they need a YAW calibration. On Free_IMU, the key 'h' set a "home calibration". In my solution, one of the Nunchuck button trigger the "home calibration" in the central. So if your sensors seems to have a wrong orientation, just press the button and take the same position as your avatar when all the angles are "0,0,0". To simplify, I always draw my avatars in the same initial position.
There are a lot of NRF24 libraries online. Some didn't work with my application, and more specifically because of the 6DOF library delay which probably caused synchronization problems... So use this one, it seems to work very well with other libraries ;)
Using multi-transceiver Bluetooth, you are going to need different addresses on each node. That's why the DIP switch is here. You can load the same program in every 6DOF node and only play with the switches to give them different addresses. You forgot to charge one of your nodes? No problem, take another one, set the same DIP address, and that's it!
Sorry, not finished this part yet, I will send some STL 3d print files as soon as I can
Purpose of the device :
- Records the body's movement through the 6DOF sensors over I2C
- Analyses the data and creates the 4 Quaternions to determine the position
- Calculates the three Euler angles. In case a reference point has been defined, the Euler angles will also depend on it
- Casts each Euler angle floats into a byte, so we can send all three in one message (4 bytes buffer limit). This action reduces the number of possible values to 256 per angle... but it speeds up the communication a lot.
- Sends the Buffer
- Enters shortly into Reception Mode, so if a new referencing point has been set, it will be taken into consideration. (This part is changing on the last version)