Go Down

Topic: Suggestions for accelerometers, gyroscopes, and GPS receivers? (Read 3309 times) previous topic - next topic


Suggestions for accelerometers, gyroscopes, and GPS receivers? I would like to build a model car that is self-driving, much like the car in Knight Rider TV show.


Well there are modules which combine I2C accel's and gyro's on eBay that are cheap and seem fine (I've an LSM330 one like this: http://www.ebay.co.uk/itm/6DOF-IMU-LSM330DL-LSM330-sensor-board-for-RC-robots-FPV-projects-/260946248174?pt=Radio_Control_Vehicles&hash=item3cc19bc1ee).  They may be 3.3V or 5.0V but not a big problem with I2C if you don't mix voltages on the I2C bus.

There are also 9DOF modules (accel/gyro/magnetometer) which might be worth considering (GPS can only give direction once moving).

GPS receivers - probably any modern module will be OK for outdoor use - look for cheap and the voltage you'd prefer (and whether you want separate antenna or integral).
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]


A magnetometer to provide the direction the car is pointed would be more valuable on a car than an accelerometer or gyroscope. An accelerometer would tell you when the car is accelerating or if it flipped over, but a gyroscope would be pretty useless unless you're planning on doing flips or such.

You can find a few parts on eBay that include both a voltage regulator and an I2C level translator to make them fully 5V compatible. If the item does not state it is 5V logic compatible then be aware that you will damage it with a 5V Arduino if you do not add your own level translation.


Gyroscope would help steering on short scales no problem.  So long as you use 6DoF you can maintain a good inertia frame reference (apart from translational and rotational drift).  In a car you know your speed so its only rotational drift needs correcting - magnetometer helps there, or GPS when moving.  Magnetometers can be totally confused by large steel objects of course, gyros are not.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]


I got a GY-80 device a little while back,   and after a lot of messing around I managed to get it to work,  so I guess you could try one of those.


Code: [Select]

void UpdateServos()
    //Digital inputs TX code helper
    //TxVal[8] |= (digitalRead(5) << 0);//joy 2 push
    //TxVal[8] |= (digitalRead(6) << 1);//pb
    //TxVal[8] |= (digitalRead(7) << 2);//slide
    //TxVal[8] |= (digitalRead(8) << 3);//toggle
    //Throttle TxVal[1]
    //Rotary pot TxVal[2] 
    //Joy 1 X TxVal[3]
    //Joy 1 Y TxVal[4]
    //Joy 2 X TxVal[5]
    //Joy 2 Y TxVal[6]
    //rssi TxVal[7]
    //digital TxVal[8]
    //micros() TxVal[9]
    //Use the pot as the gain for all channels for now   
    float GainPot = (float)(TxVal[2]) * 0.001f;   
    //Get the target values from the TX   
    int PitchTarg =  (TxVal[3] / 10);
    int RollTarg =  (TxVal[4] / 10);
    int YawTarg =  (TxVal[6] / 10);
    //Prime the Target WOZ values 
    if(PitchTargWOZ == 9999)
      PitchTargWOZ = PitchTarg;
    if(RollTargWOZ == 9999)
      RollTargWOZ = RollTarg;
    if(YawTargWOZ == 9999)
      YawTargWOZ = YawTarg;
    //Get the Centered target values   
    float PitchTargCentred = (float)(PitchTarg - PitchTargWOZ);
    float RollTargCentred =  (float)(RollTarg - RollTargWOZ);
    float YawTargCentred =  (float)(YawTarg - YawTargWOZ);
    //Calculate gains
    float PitchGain = GainPot * 1.0f;
    float RollGain = GainPot * 1.0f;
    float YawGain = GainPot * 1.0f;
    //Get Gyro values
    float PitchGyro = (float)(AnIn[2] - AnInWOZ[2]);
    float RollGyro = (float)(AnIn[1] - AnInWOZ[1]);
    float YawGyro = (float)(AnIn[0] - AnInWOZ[0]);
    //Calc P error
    float PitchError = (float)PitchTargCentred + PitchGyro;
    float RollError = (float)RollTargCentred + RollGyro;
    float YawError = (float)YawTargCentred + YawGyro;
    //Apply gains
    int PitchTrim = (int)(PitchError * PitchGain);   
    int RollTrim = (int)(RollError * RollGain);   
    int YawTrim = (int)(YawError * YawGain);
    //Constaring trim authority
    PitchTrim = constrain(PitchTrim, -30, 30);
    RollTrim = constrain(RollTrim, -30, 30);
    YawTrim = constrain(YawTrim, -30, 30);
    //Dump the trim value
    if((TxVal[9] & 0x4) == 0)
      PitchTrim = 0;
      RollTrim = 0;
      YawTrim = 0;     
    //Calc flap anglke
    int Flaps = 0;
    //Apply flaps
    if((TxVal[9] & 0x8) != 0)
        Flaps = 25;

Revised Yellow FPV Plane with gyro stability system added, Worked best with analogue inputs from Murata piezo gyro sensors of a dead KK board filtered taking a 10 point average. Yaw compensation is currently not used as there is no rudder presently.

Go Up