When I insert this program, it says that there is an error in the while loop. It says I need to have something in the parenthesis. What do I put here so that it will run the odometryUpdate before each move?
void driveTo()/*Inputs, speed, location, etc*/
{
while()
{
// update the odometry information
odometryUpdate();
// do things to get you to location
}
}
Also, I apologize for the delayed responses. I am not able to have access to the forums very often, usually twice a week for only a few hours.
The error in the program is because the while loop has no exit condition defined. in driveTo(), we need to start a while loop, drive to the point, and finally exit the loop to allow the robot do the next autonomous command. In order to exit the while loop, you need to make a variable to check against a condition. We call this an exit condition. To expand on this while loop a bit.
void driveTo()/*Inputs, speed, location, etc*/
{
float distance = 10;
while(distance > 5)
{
// update the odometry information
odometryUpdate();
// do things to get you to location
// measure distance to target;
distance = ...;
}
}
If you cut and paste that code in, it will still error out due to the distance = ...; command. As a reminder, I am not showing plug and play code. Every code I have made here literally does nothing if the missing pieces are not filled in. The code examples I have made are intended to show you the rough outline of how the code should flow.
So do I have to define the float x, float y, and float speed then? How do I connect those with my RightDrive, LeftDrive, and BackDrive motors?
void driveTo(float x, float speed)
{
float wheelMotion = RightCurrentValue;
if(wheelMotion == 0)
{
//update the odometry information
odometryUpdate();
// do things to get you to location
// measure distance to target;
}
}
The âRightCurrentValueâ isnât a velocity, its an encoder on the axle. I am really confused with what you mean here, though. Iâm talking about the driveTo function.
Sorry, I misinterpreted your question. To answer this post:
Q1: You donât need to define your parameters separately. Putting them in the method header does that.
Q2: The parameters x and y are usually your target variables. I.E. How far in those directions do you want to go. Speed is the speed the drive goes at. To use those values, your code (in english) could look something like this
void driveTo(parameters here)
while(your encoders are not close to your x and y targets)
{
drive the robot at the speed
}