QTR-8RC reflectance sensor (with Arduino Duemilanove)

Hello Fred,

There is nothing about the code that would limit the value of “motorspeed” to be from 0 to 255. The idea is that you need to convert that value into a pair of motor speeds. For example, you could set m1 to 100 + motorspeed and m2 to 100 - motorspeed, and then limit m1 and m2 to be in the range [0:255].

-Paul

but do not understand how you do it …
I can not make a practical example? motorspeed convert the value of a value from 0 to 255, …

I can not demonstrate this through a practical example? with a piece of code …

Did you see how the original code does it? That code prevents m1Speed and m2Speed from being less than zero, and you should be able to easily add a couple of lines to prevent them from being greater than 255 as well.

-Paul

I tried that with the minimum amount of speed is 0 and could not …
I did:

int m1Speed = M1 + motorspeed;
int m2Speed = M2 - motorspeed;
if (m1Speed < 0)
m1Speed = 0;
if (m2Speed < 0)
m2Speed = 0;

and what did not exceed 255, I’d do the same, but that would not work as a translator, because you would only get the value 0 or 255,

and therefore did not know then how to convert, I could use the function:

val = (map,val,17850,2550,0,255);

but I think this is not possible, because I am wanting to convert a high value in a low value (0 to 17,750) and a low value to high (2550 to 255).

can you help me?

Please use the Code button to include code in your posts.

You can restrict the range to be from 0 to 255 like this:

int m1Speed = M1 + motorspeed;  
int m2Speed = M2 - motorspeed; 
if (m1Speed < 0)  
  m1Speed = 0;  
if (m2Speed < 0)  
  m2Speed = 0;  
if (m1Speed > 255)
  m1Speed = 255;
if (m2Speed > 255)
  m2Speed = 255;

Is that what you need?

-Paul

Paul …
as they say it will not work …
was what I was saying in the previous message, repairs …

I get the following values in the array of sensors: 17850.7550, xxx, 2550, -2550, xxx, xxx, -17,850.

and I want the maximum speed of the motors are when I have the 2550 and -2550, or want to convert to 255 in 2550, and 17,850 to 0! and the same applies in negative values, understand?

to make these as I would with the sugerrir.

255,255,255,255,0,0,0,0

I do not want this!

You can calculate any mathematical function you want with the Arduino, but I have absolutely no idea what you are asking for or why you think our suggestion is not good enough.

It sounds like you really do not understand some basic things about PID. I think you should either read more about it somewhere else, or go back to the first line following example (called “rudimentary line following”) given here. Did you get that one to work already?

-Paul