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:

here is the map function

and here is sensor smoothing

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()

void loop()
  for (int i=-100; i<200; i++)
  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:

my accelerometer(tilt + or - variable)

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