Auto level off-road buggy, First Arduino project

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
adafruit_support_bill
 
Posts: 88088
Joined: Sat Feb 07, 2009 10:11 am

Re: Auto level off-road buggy, First Arduino project

Post by adafruit_support_bill »

Here's a thread about using an IMU to level a camera platform on a moving motorcycle: http://forums.adafruit.com/viewtopic.php?f=8&t=46515

Wkoffroad
 
Posts: 22
Joined: Fri Feb 14, 2014 11:52 am

Re: Auto level off-road buggy, First Arduino project

Post by Wkoffroad »

Thanks Bill I will try to implement some of the information from that thread this evening , as for code franklin there is none to speak of just the code I pulled to get the 9-DOF sensor spitting out data but after reading the other thread I will have something to show in the next couple of days . And one other question I had a idea to mount the sensor 45 degs to the travel of the buggy so that (in my head) the pitch will control right front and left rear, and the roll will control left front and right rear this way I don't have the problem of controlling multiple bags with pitch and roll . Does this sound like a good idea or a bad idea?

User avatar
adafruit_support_bill
 
Posts: 88088
Joined: Sat Feb 07, 2009 10:11 am

Re: Auto level off-road buggy, First Arduino project

Post by adafruit_support_bill »

That's an interesting approach. Sounds like it should work.

Wkoffroad
 
Posts: 22
Joined: Fri Feb 14, 2014 11:52 am

Re: Auto level off-road buggy, First Arduino project

Post by Wkoffroad »

Great, as soon as I get the auto level function working I will add in a switch for auto level/manual mode and a push button for specific height selection , I really appreciate all the help I am getting from this forum especially you Bill thanks

Wkoffroad
 
Posts: 22
Joined: Fri Feb 14, 2014 11:52 am

Re: Auto level off-road buggy, First Arduino project

Post by Wkoffroad »

auto level test setup seems to be working but is bothered by vibration

Code: Select all

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_9DOF.h>


const int rrup = 22;     //rear right bag up solenoid//
const int rrdown = 24;   //rear right bag down solenoid//
const int rlup = 23;     //rear left bag up solenoid//
const int rldown = 25;   //rear left bag down solenoid//
const int frup = 26;     //front right bag up solenoid//
const int frdown = 28;   //front right bag down solenoid//
const int flup = 27;     //front left bag up solenoid//
const int fldown = 29;   //front left bag down solenoid//

/* Assign a unique ID to the sensors */
Adafruit_9DOF                dof   = Adafruit_9DOF();
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);

/* Update this with the correct SLP for accurate altitude measurements */
float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;

/**************************************************************************/
/*!
    @brief  Initialises all the sensors used by this example
*/
/**************************************************************************/
void initSensors()
{
  if(!accel.begin())
  {
    /* There was a problem detecting the LSM303 ... check your connections */
    Serial.println(F("Ooops, no LSM303 detected ... Check your wiring!"));
    while(1);
  }
}

/**************************************************************************/
/*!

*/
/**************************************************************************/
void setup(void)
{
  pinMode(rrup, OUTPUT);
  pinMode(rrdown, OUTPUT);
  pinMode(rlup, OUTPUT);
  pinMode(rldown, OUTPUT);
  pinMode(frup, OUTPUT);
  pinMode(frdown, OUTPUT);
  pinMode(flup, OUTPUT);
  pinMode(fldown, OUTPUT);
  
  
  Serial.begin(115200);
  Serial.println(F("Adafruit 9 DOF Pitch/Roll/")); Serial.println("");
  
  /* Initialise the sensors */
  initSensors();
}

/**************************************************************************/
/*!
    @brief  Constantly check the roll/pitch/heading/altitude/temperature
*/
/**************************************************************************/
void loop(void)
{
  sensors_event_t accel_event;
  sensors_vec_t   orientation;

  /* Calculate pitch and roll from the raw accelerometer data */
  accel.getEvent(&accel_event);
  if (dof.accelGetOrientation(&accel_event, &orientation))
  {
    /* 'orientation' should have valid .roll and .pitch fields */
    Serial.print(F("Roll: "));
    Serial.print(orientation.roll);
    Serial.print(F("; "));
    Serial.print(F("Pitch: "));
    Serial.print(orientation.pitch);
    Serial.print(F("; "));
 /**************************************************************************/
/*!
    adjust bag soleniods based on tilt
*/
/**************************************************************************/   
    
    
  }
   if (orientation.pitch> 2) {
    digitalWrite(rrup, HIGH);
  } 
  else {
    digitalWrite(rrup,LOW); 
  }

   if (orientation.pitch< -2) {
    digitalWrite(rrdown, HIGH);
  } 
  else {
    digitalWrite(rrdown,LOW); 
  }
  if (orientation.pitch> 2) {
    digitalWrite(fldown, HIGH);
  } 
  else {
    digitalWrite(fldown,LOW); 
  }

   if (orientation.pitch< -2) {
    digitalWrite(flup, HIGH);
  } 
  else {
    digitalWrite(flup,LOW); 
  }
  if (orientation.roll> 2) {
    digitalWrite(rldown, HIGH);
  } 
  else {
    digitalWrite(rldown,LOW); 
  }

   if (orientation.roll< -2) {
    digitalWrite(rlup, HIGH);
  } 
  else {
    digitalWrite(rlup,LOW); 
  }
  if (orientation.roll> 2) {
    digitalWrite(frup, HIGH);
  } 
  else {
    digitalWrite(frup,LOW); 
  }

   if (orientation.roll< -2) {
    digitalWrite(frdown, HIGH);
  } 
  else {
    digitalWrite(frdown,LOW); 
  }
  Serial.println(F(""));
  delay(0500);
}
the majority of this code is from the pitchrolltest code for the 9-dof sensor i am using but as i said it works like it should except when i tap the breadboard the LEDs i am using as solenoid stand-ins jump around.

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: Auto level off-road buggy, First Arduino project

Post by Franklin97355 »

You probably need to implement something like this. http://en.wikipedia.org/wiki/Kalman_filter Check out code they use on quadcopters for place holding.

User avatar
adafruit_support_bill
 
Posts: 88088
Joined: Sat Feb 07, 2009 10:11 am

Re: Auto level off-road buggy, First Arduino project

Post by adafruit_support_bill »

A Kalman filter may be overkill for this application, but some kind of filtering is probably required. You can make a simple low-pass filter by taking the average of the last 'n' readings. You can adjust the size of 'n' to tune the response.

User avatar
jcgoodman
 
Posts: 107
Joined: Thu Jan 23, 2014 6:03 pm

Re: Auto level off-road buggy, First Arduino project

Post by jcgoodman »

I like autoregressive filters. Easier to implement than a moving average, and fewer nasty technical surprises.

Code: Select all

int filterstrength = 10  // Roughly how many samples contribute to the filtered output.  Bigger = smoother
filteredpitch = ((filterstrength -1)* filteredpitch + orientation.pitch) / filterstrength
filteredroll = ((filterstrength -1)* filteredroll + orientation.pitch) / filterstrength
If you make filterstrength greater than 1000 , you might want to make filteredpitch a double precision float.

Wkoffroad
 
Posts: 22
Joined: Fri Feb 14, 2014 11:52 am

Re: Auto level off-road buggy, First Arduino project

Post by Wkoffroad »

I will try these filtering methods tonight and report what i find, Thanks

Wkoffroad
 
Posts: 22
Joined: Fri Feb 14, 2014 11:52 am

Re: Auto level off-road buggy, First Arduino project

Post by Wkoffroad »

Ok looks like filtering will do the trick i will need to do more testing on the full scale buggy when the time comes also i have added my auto level code to a while loop and have a switch connected for my manual/auto control it seems to work well . Now for more component questions i am considering a I2c relay board or switching transisters for driving the solenoids. i have read all the pros and cons of both but can not make a decision , what would you use or is there another choice ?

User avatar
adafruit_support_bill
 
Posts: 88088
Joined: Sat Feb 07, 2009 10:11 am

Re: Auto level off-road buggy, First Arduino project

Post by adafruit_support_bill »

I'd go with MOSFETs. http://www.adafruit.com/products/355
Relays are noisy, (relatively) slow and have a finite lifetime (typically ~100K actuations).

You would drive it like the diagram below (The resistor is not required with the MOSFET linked above)
Don't forget the diode. It protects the device from the inductive spike when the solenoid is de-energized.

Image

Wkoffroad
 
Posts: 22
Joined: Fri Feb 14, 2014 11:52 am

Re: Auto level off-road buggy, First Arduino project

Post by Wkoffroad »

now you have me wanting to do something else i have never done build my own circuit board, is there a way to build it so i could use i2c if not no big deal i have the outputs . I feel this project will evolve quite a bit before the buggy hits the first trail i am already thinking about touch screen and color display :D

User avatar
adafruit_support_bill
 
Posts: 88088
Joined: Sat Feb 07, 2009 10:11 am

Re: Auto level off-road buggy, First Arduino project

Post by adafruit_support_bill »

Code: Select all

now you have me wanting to do something else i have never done build my own circuit board, is there a way to build it so i could use i2c
I have just the chip(s) for you! :D
http://www.adafruit.com/products/593
http://www.adafruit.com/products/732

Wkoffroad
 
Posts: 22
Joined: Fri Feb 14, 2014 11:52 am

Re: Auto level off-road buggy, First Arduino project

Post by Wkoffroad »

so i could use one of those chips (the 732 bigger is better) and 16 of the MOSFETs and build my own 16 port i2c MOSFET board ?

Wkoffroad
 
Posts: 22
Joined: Fri Feb 14, 2014 11:52 am

Re: Auto level off-road buggy, First Arduino project

Post by Wkoffroad »

Is there any reason I couldn't put a led in parallel with the gate of each MOSFET

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”