Introduction: Gyro Camera for Motorcycle
As seen in MotoGP Race, the rider is seen riding through corners while laying aside his bike to the left and right. But there is an interesting moment when the motor looks to collapse sideward, the front views remain horizontally. How could that be?
Such onboard camera applies GYRO system, where the camera will be fixed perpendicular to the gravity of the earth.
Step 1: BUILD YOUR OWN GYRO CAMERA
We could build our own Gyro Camera by using GYRO and ACCELEROMETER modules.
They are two separate modules, hence we have to use two modules simultaneously. Then we make Gyro Chip and Accelerometer Chip in one module (there are two chips in one module). In latest version they are made in one chip only, thus minimizing the distortion of movement calculation
In this article, the module is Triple Axis Accelerometer & Gyro Breakout – MPU-6050, which has 3-axis gyroscope and 3-axis accelerometer in one chip, supplied by power of 3.3volt.
In addition to module MPU6050, the following similar modules could also be applied:
• IMU Fusion Board – ADXL345 & IMU3000
• IMU Digital Combo Board – 6 Degrees of Freedom ITG3200/ADXL345
Module MPU6050 with its tiny size of 20mm x 15mm and height of 1.6mm.
The components are:
• Triple Axis Accelerometer & Gyro Breakout – MPU-6050
• Arduino UNO R3
• Digital Servo (use good and powerful servo)
• Breadboard Mini
• 9v Battery + Switch
• Box and other accessories.
If you using different board than Arduino Uno R3, SCL and SDA pins of MPU are also different:
VDD : +3.3V
VIO : +3.3V
GND : GND
SDA : Pin A4 (Arduino Uno, Ethernet) / Pin 20 (Mega2560, Due) / Pin 2 (Leonardo)
SCL : Pin A5 (Arduino Uno, Ethernet) / Pin 21 (Mega2560, Due) / Pin 3 (Leonardo)
Step 2: PROGRAMMING
After having completely assembled, it is time now to upload the program to Arduino.
This circuit is only to drive servo in axis-X only. However, data from Axis Y and Z are still required for the respective Gyroscope and Accelerometer. I tried to combine them by applying Kalman Filter calculation so as to reduce ‘noise’ output from Gyroscope + Accelerometer so that servo movement is smooth and no unwanted movement.
CODE:
/*
GYRO CAMERA - saft7.com
Demonstrates auto-leveling Camera Video by using Gyro & Accelerometer with Arduino
The circuit:
Servo controlled by Arduino, using Gyro and Accelerometer as reference of movement.
Created March 12, 2013
by Firmansyah Saftari
www.saft7.com
This code and complete article can be found at:
http://www.saft7.com/
Programming Language: C++
*/
#include <Servo.h>
Servo xservo;
#include <Wire.h>
#include "Kalman.h"
Kalman kalmanX;
Kalman kalmanY;
uint8_t IMUAddress = 0x68; // MPU6050 Address
/* IMU Data */
int16_t accX;
int16_t accY;
int16_t accZ;
int16_t tempRaw;
int16_t gyroX;
int16_t gyroY;
int16_t gyroZ;
int moveX;
int mapX;
int correctionX;
double accXangle;
double accYangle;
double gyroXangle = 9;
double gyroYangle = 180;
double compAngleX = 90;
double compAngleY = 90;
double kalAngleX;
double kalAngleY;
uint32_t timer;
// ---------- VOID SETUP START -------------- /
void setup() {
Serial.begin(115200);
xservo.attach(10);
Wire.begin();
i2cWrite(0x6B,0x00); // Disable sleep mode
if(i2cRead(0x75,1)[0] != 0x68) { // Read "WHO_AM_I" register
Serial.print(F("MPU-6050 with address 0x"));
Serial.print(IMUAddress,HEX);
Serial.println(F(" is not connected"));
while(1);
}
kalmanX.setAngle(90); // Set starting angle
kalmanY.setAngle(90);
timer = micros();
}
// ---------- VOID SETUP END -------------- /
// ---------------------- VOID LOOP START -------------- /
void loop() {
/* Update all the values */
uint8_t* data = i2cRead(0x3B,14);
accX = ((data[0] << 8) | data[1]);
accY = ((data[2] << 8) | data[3]);
accZ = ((data[4] << 8) | data[5]);
tempRaw = ((data[6] << 8) | data[7]);
gyroX = ((data[8] << 8) | data[9]);
gyroY = ((data[10] << 8) | data[11]);
gyroZ = ((data[12] << 8) | data[13]);
/* Calculate the angls based on the different sensors and algorithm */
accYangle = (atan2(accX,accZ)+PI)*RAD_TO_DEG;
accXangle = (atan2(accY,accZ)+PI)*RAD_TO_DEG;
double gyroXrate = (double)gyroX/131.0;
double gyroYrate = -((double)gyroY/131.0);
gyroXangle += gyroXrate*((double)(micros()-timer)/1000000); // Calculate gyro angle without any filter
gyroXangle += kalmanX.getRate()*((double)(micros()-timer)/1000000); // Calculate gyro angle using the unbiased rate
compAngleX = (0.93*(compAngleX+(gyroXrate*(double)(micros()-timer)/1000000)))+(0.07*accXangle); // Calculate the angle using a Complimentary filter
kalAngleX = kalmanX.getAngle(accXangle, gyroXrate, (double)(micros()-timer)/1000000); // Calculate the angle using a Kalman filter
timer = micros();
mapX = map(kalAngleX, 0, 200, 0, 179); //calculate limitation of servo mechanical
// /////////////////////////////
correctionX = 27; // EDIT THIS VALUE FOR SERVO CORRECTION ANGLE
// ////////////////////////////
moveX = 270 - (kalAngleX) + correctionX;
// ------- SEND TO SERIAL PRINT START ----- /
Serial.print("saft7.com X Pos: ");
Serial.print(moveX);Serial.print("\t");
Serial.print("\n");
// ------- SEND TO SERIAL PRINT END ----- /
// ------- SEND TO SERVO START ----- /
xservo.write(moveX); // Send signal to servo
delay(15); // delay to allow servos to move (ms)
// ------- SEND TO SERVO END ----- /
delay(1); // The accelerometer's maximum samples rate is 1kHz
}
// ---------------------- VOID LOOP END -------------- /
// -- FUNCTIONS START --
void i2cWrite(uint8_t registerAddress, uint8_t data){
Wire.beginTransmission(IMUAddress);
Wire.write(registerAddress);
Wire.write(data);
Wire.endTransmission(); // Send stop
}
uint8_t* i2cRead(uint8_t registerAddress, uint8_t nbytes) {
uint8_t data[nbytes];
Wire.beginTransmission(IMUAddress);
Wire.write(registerAddress);
Wire.endTransmission(false); // Don't release the bus
Wire.requestFrom(IMUAddress, nbytes); // Send a repeated start and then release the bus after reading
for(uint8_t i = 0; i < nbytes; i++)
data[i] = Wire.read();
return data;
}
// -- FUNCTIONS END --
// GYROCAM BY SAFT7.COM //
// END
Step 3: Build the Camera Bracket
Camera bolt was taken from an unused small tripod so as to ease the camera installation.
Arduino Board is installed onto the box plate.
Arduino, Servo and MPU6050 have been installed on the box.
Video of Servo testing on box
Video on the testing of installed camera
Step 4: TIME TO TRY
Let’s ride to try …
Lessons Learned:
• Gyro + accelerometer modules should be installed firmly.
• Calibration of horizontal level should be on flat area
• Use powerful servo.
• Use heavy duty battery so hat power to servo is well supplied.
Good luck.
Saftari
Translated by Taufik Masjhur
This post was originally published on saft7.com in Bahasa Indonesia language.
51 Comments
5 years ago on Step 3
Can I ask why you put the gyro sensor on the rigid part of the mount and not on the camera part? Instead of measuring the angle of lean, you could just control the motor until the camera was level. Open vs Closed feedback loops. I guess in the end, it all works though. I saw one of these gyro cameras on a bike running the Nuremberg track and it was very cool to see. Love the project!
5 years ago on Introduction
Could you use one of these instead to reduce size? http://www.ebay.co.uk/itm/MWC-ATMega328p-MPU6050w-USB-6-Axis-Gyro-accelerometer-Control-Sensor-/201333158182?pt=LH_DefaultDomain_3&hash=item2ee0643126
5 years ago on Introduction
Hey! could I have a ADXL345..but it doesn`t have SDA and SCL pins..only x, y, z pins. Is there a way I can adapt your code for my board?
Thanx for the instructable
Reply 5 years ago on Introduction
Sorry..I was in a hurry. I mean I HAVE a ADXL335 like this:
https://www.fabtolab.com/image/cache/data/Sensors/...
Can I use this one?
Thanks again
5 years ago on Introduction
@saftari : Could you give me the reference of the servo motors used in this project, please? Many thanks
5 years ago on Step 3
Has anyone used any gyroscopic mount (gyro-cam) that works? I'm looking forward to have one for my tracking days!
I have hard this London company www.darewarelabs.com is making one GoPro gyro-mount, due to be released before the summer.
Has anyone heard of them?
Derek
7 years ago on Step 2
First of all, thanks for the awesome write up. I'm trying to compile this code in a sketch and I get the following errors:
sketch_dec22a.ino:25:20: error: Kalman.h: No such file or directory
sketch_dec22a:26: error: 'Kalman' does not name a type
sketch_dec22a:27: error: 'Kalman' does not name a type
sketch_dec22a.ino: In function 'void setup()':
sketch_dec22a:71: error: 'kalmanX' was not declared in this scope
sketch_dec22a:72: error: 'kalmanY' was not declared in this scope
sketch_dec22a.ino: In function 'void loop()':
sketch_dec22a:99: error: 'kalmanX' was not declared in this scope
Do you happen to have any guidance on how to fix them? Thanks!
Reply 6 years ago on Step 2
Hi,..
You should include kalman filter library.
You can download from here https://github.com/TKJElectronics/KalmanFilter
Reply 5 years ago on Introduction
SERVO Y to modify the code where you want it.
thank
Reply 6 years ago on Introduction
Yup! I figured it out a little bit ago and got it working great using a Nano! Thank you again so much for posting the code and instructable!
Reply 6 years ago on Step 2
i know this is far too late and you probably know this now but its because you dont have the kalman library installed
Reply 6 years ago on Introduction
the solucion is simple: you have to put the kalman.h into the library. download it from this page: https://github.com/TKJElectronics/KalmanFilter
select the button called "download ZIP" and then copy the hole holder into the library.
Reply 6 years ago on Introduction
Yup! That worked perfect for me. Got it to operate on an Uno and a Nano board. Probably will do the full build with the Nano. Is there anyway to smooth out the signal a little? Or is that a byproduct of using a servo (jitter) as opposed to a motor? Either way, I definitely appreciate the author taking the time to post up all this, so very helpful!
Reply 6 years ago on Introduction
I have the same problem, did you fix it? please help me, thank you very much.
5 years ago on Introduction
I have heard these guys - www.darewarelabs.com are about to launch their own consumer electronic stabilizer solution for GoPro in a couple of months.
6 years ago on Introduction
Hi,
I'm not such a handy man so can I buy this mount?
6 years ago on Introduction
Hi!, Nice to meet you , I am sam.I got
the problem that about Gyrocam for motor
is I am using the MPU6050+Kalman to install into a motor , If I shake the MPU6050 relatively
strong up and down it just messes it slowly drifts the camera to one side or
the other .it still doesn't work properly. Could you kindly tell me how
to figure the problem out ?
Have a nice day !!!!
6 years ago on Introduction
Good idea, but please it's possible to do a video without these music, because in Germany the censorship block your video. Its sad, I know.
7 years ago on Introduction
keren, bisa di kembangkan nggak ya supaya bisa jadi tugas akhir saya ? hehe trims mohon reply nya yaa
7 years ago on Introduction
Keren mas :)