I use my bike to get around in the city where I live. This is an awesome way to transport your self, but when it is dark it can be hard for other people to see your signals and understand where you are going. I had an idea of putting lights on the clothes to shine lights when breaking or holding out your arm to signal a turn, like on a car.
I wanted to prototype a blinking light that is automatically triggered when I hold out my arm. One way of doing this would be to use gyros and accelerometers to track the motion and position of a point on the bikers arm. When the system detects that the arm has moved out from the "handle position", a light should blink. Preferably it should be a small device that can be strapped around the wrist.
The Crazyflie is the perfect platform for this prototype. It has the sensors needed and with the LED-ring deck there are powerful LEDs to flash.
The prototype is intended to be used on the right arm, strapped around the wrist on the top side of the arm. Remove the motors from the Crazyflie and mount the LED-ring on the bottom (as always). Use a rubber band to strap the Crazyflie upside-down (LED-ring facing outwards) to your wrist, front pointing towards your hand.
This tutorial assumes that you know how to use the Crazyradio to connect to your Crazyflie, as well as how to flash new firmware to it. If you need help, take a look at www.bitcraze.io.
The easiest way to understand the data we get from the sensors is to use the PC client. Connect the Crazyflie and open the Settings->Logging configuration menu. Create configurations for gyros and accelerometers.
Go to the Plotter tab and choose the configuration you want to examine. Move your arm from "handle position" to 90 degrees out from your body. Here are the graphs from my sensors.
The prototype is implemented as a LED-ring effect. I simply get accelerometer and gyro data from the logging system and check that acc.y < -0.5 and acc.z > 0.5 and that all accelerometers > 80. When the right conditions are met, the LED ring is turned on and off 4 times.
This sort of works sometimes, but it seems as the accelerator data is lagging behind the gyro data, so the condition is not met every time. Improvement is required.
We need to use the history some how to make this work. A very simple way to do this is to use an exponential moving average. OK, I added
gyroHist = gyroHist * 0.8 + logGetFloat(gyroXId) + logGetFloat(gyroYId) + logGetFloat(gyroYId);
By adding the gyroHist to the logging system, I can again plot it in the PC client. Simply add this to your file
LOG_GROUP_START(ring2)LOG_ADD(LOG_FLOAT, gyroHist, &gyroHist)LOG_GROUP_STOP(ring2)
and it will be available in the client.
When I try it out it looks like this
The final implementation is attached to the project. Everything goes into the dec/drivers/src/ledring12.c file
When trying out the prototype, remember to put the Crazyflie on a level surface when booting to calibrate the sensors (the front right LED should blink twice a second when calibrated).
The algorithm is not fool proof but I think it serves its purpose of showing that the visibility improves a lot with lights on your clothes.