# Finding the Distance

OK, so I am trying to find out if it is possible to figure out how far the robot has moved based on the time the motor has been turning and what value the motor is (0=full reverse 127=neutral 255=full forward). But I am not sure if it is a) possible or if it is possible b) what does the formula look like?

Here is the code I have so far, I am not too sure how the “timer” function works (could someone please explain it?), and obviously the motor divided by time (motor / time ) formula is not correct.

``````
int motor;
int distance;
int time;

while ( 1 )
{
StartTimer ( 1 ) ; // start timer 1
time = GetTimer ( 1 ) ; // get timer 1
motor = GetRxInput ( 1 , 1 ) ;
distance = ( motor / time ) ; // user code
// I have all of my variables print so I can view all the data
PrintToScreen ( "The Robot has moved%d\n" , (int)distance ) ; // should print to screen the distance the robot has traveled
PrintToScreen ( "The motor position is%d\n" , (int)motor ) ; // should print the value of the motor (0-255)
PrintToScreen ( "The robot has been moving for%d\n" , (int)time ) ; // should print the time that the robot has been moving
}

``````

Any help would be appreciated. Also, I am trying to do this without the use of any sensors…

What are you coding this in?

What is your goal, and how will you know if you succeed?
Not much accuracy is possible without a sensor. (closed loop)
Optical wheel sensor kit would work well for this.

To drive in a specific pattern in autonomous mode,
as best you can in open loop mode, without a sensor,
try setting up a list of driving commands with wait between them.
Run the program and adjust the wait times to get the desired behavior.
It will be tricky to do a turn in skid-steer mode, even with optical encoders,
because of the uncertainty in the amount of skidding.

If you want to keep dead-reconning position of during OperatorControl,
things that will help will be to

1. always drive full speed or zero speed,
2. Dont change speeds often, ie let motor come to full speed.
With the above, it seems likely you could use a table lookup, or develop a formula for how much distance you have transversed on each drive segment.
The table will have to include the start/stop accel/decel time factor, as well as the length of time at top speed.

EasyC Pro

To be honest I just want to be able to do this. I don’t have actual plans for using it, though if I get something working I could find a use… But I will probably still end up using dead reckoning with a bunch of waits for any type of auto mode without any sensors.

just to ask, where did you get EasyC Pro?

Also, I edited my code, I still don’t think it will do what I want it to, but its all a bot cleaner.

``````
int motor;
int distance;
int time;

motor = GetRxInput ( 1 , 1 ) ;
while ( motor = 1 )
{
StartTimer ( 1 ) ;
time = GetTimer ( 1 ) ;
distance = ( motor / time ) ;
// I have all of my variables print so I can view all the data
PrintToScreen ( "The Robot has moved%d\n" , (int)distance ) ; // should print to screen the distance the robot has traveled
PrintToScreen ( "The motor position is%d\n" , (int)motor ) ; // should print the value of the motor (0-255)
if ( motor = 0 )
{
StopTimer ( 1 ) ;
PrintToScreen ( "The robot has been moving for%d\n" , (int)time ) ; // should print the time the robot has been moving
}
}
``````