map and smooth functions questions...

in regards to my self balance robot project,

could someone show me a example code showing how I could use map and smooth
to take x axis +/- data from my accelerometer(tilt + or - variable) and use map and smooth to change the variable to set pwm to motor shield
can smooth be used with this?

or is there a better solution?

The map() function takes a value that might be in one range and maps it to another range. The value might be a potentiometer reading, in the range 0 to 1023, and the other range might be 0 to 180, to position a servo. The potentiometer reading maps to a servo position, then.

I don't see how the map function is going to help you.

I have no idea what smooth function you are talking about.

It appears that you don't understand what you are getting from your accelerometer, either.

There are a number of projects in the robotics part of the forum that detail building self balancing robots. You need to spend some time there.

sorry that i did not make that more clear..
my setup is the accelerometer on a mini breadboard. if the breadboard is level, I get a reading of 0
if I tilt the board to the left and watch the serial monitor, I see it moving down to -600 reading when the board is at a 35 degree angle
if I tilt the board to the right and watch the serial monitor, I see it moving up to +600 reading
here is the accelerometer pdf from parallax:
http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&ved=0CEIQFjAD&url=http%3A%2F%2Fwww.parallax.com%2Fdl%2Fdocs%2Fprod%2Fcompshop%2FSICMemsicTut.pdf&ei=AFCUUOfwILC70QHp6oDABQ&usg=AFQjCNGu1S53Teo_f2J72k170LaohsiVWQ&sig2=8Cq5SpAdofwzTxurp6Bzxw

here is the map function

and here is sensor smoothing
http://www.arduino.cc/playground/main/smooth

I was just thinking that using these with the accelerometer output to control the motors..
I already have code making the motors move according to the accelerometer output but it is jerky as hell and wont stay balanced at all (but the motors do move the right direction.

be aware that the map() function will not guard against out of range values

simple example that show Celsius to Fahrenheit conversion

//
//    FILE: mapC2F.pde
//  AUTHOR: Rob Tillaart
//    DATE: 2012=NOV-04
//
// PUPROSE: showing that map() works outside of ranges provided
//

void setup()
{
  Serial.begin(9600);
  Serial.println("start...");
}

void loop()
{
  for (int i=-100; i<200; i++)
  {
    Serial.print(i);
    Serial.print(":");
    Serial.println(map(i,0,100,32,212));
  }
  while (1);
}

SO: if the getTempC() returns an errorcode say -1000 , the map() function will just do its math, returning => -1768F :wink:

Use constrain() to constrain a value between two values

Isn't this a job for the Pid library ?

Just thinking out loud, I know PIDs are extremely tricky to work with :wink:

stevecobb76:
my accelerometer(tilt + or - variable)

I think you'll find that accelerometers can only be used to measure tilt when stationary.