Sorry about the post in the wrong forum.
However, the documentation you’re looking at is for Vex IQ. Notice how it uses waitUntilMotorStop, which is a function in robotC only when you are in Vex IQ mode. For Vex Cortex, it’s here. After checking the console on a loop, it seems the (integrated motor encoders) are on the right I2C ports.
If I assign a decimal value to an “int” variable, does it round to the nearest integer, or do I need to use float? I heard that the cortex can’t support float, so I didn’t use it. However, if it doesn’t round, the “goal” variable I set should end up being a decimal, so maybe that’s the problem. In the documentation, it’s supposed to be of the long datatype, but I don’t know if it’s necessary as a result to assign it as long, since long (to my knowledge) is just a larger set of integers.
Also, my code again for others:
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, I2C_1, hdleft, sensorQuadEncoderOnI2CPort, , AutoAssign )
#pragma config(Sensor, I2C_2, hdright, sensorQuadEncoderOnI2CPort, , AutoAssign )
#pragma config(Sensor, I2C_3, hdmid, sensorQuadEncoderOnI2CPort, , AutoAssign )
#pragma config(Motor, port3, hdmid, tmotorVex393_MC29, PIDControl, encoderPort, I2C_3)
#pragma config(Motor, port4, hdleft, tmotorVex393_MC29, PIDControl, driveLeft, encoderPort, I2C_1)
#pragma config(Motor, port5, hdright, tmotorVex393_MC29, PIDControl, reversed, driveRight, encoderPort, I2C_2)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
// begin math functions
// begin robot movement functions
void resetEncoders() {
resetMotorEncoder(hdleft);
resetMotorEncoder(hdright);
resetMotorEncoder(hdmid);
}
void forwardDistance(int tenthInch, int speed) // never use 127 motor power, or pid won't be able to adjust
{
//convert "tenthInch" to encoder ticks
int goal = (61 * tenthInch) /10;
//high torque motor ticks per rotation: 627, high speed: 392, turbo speed: 261 all for VEX 393 motors
//circumference of 3.25" omni wheels = 10.20500"
//10.20500" traveled per rotation, which also means 102 tenths of an inch traveled per rotation
//627 ticks per rotation
//61 ticks per inch
moveMotorTarget(hdleft, goal, speed, true); // move hdleft motor until "goal" ticks, at "speed" speed, and coast to a stop (true part)
moveMotorTarget(hdright, goal, speed, true);
while(getMotorTargetCompleted(hdleft) == false || getMotorTargetCompleted(hdright) == false)
{
} //idle loop to wait for moveMotorTarget to complete
}
void backwardDistance(int tenthInch2, int speed2) // never use 127 motor power, or pid won't be able to adjust
{
//convert "tenthInch" to encoder ticks
int goal2 = (61 * tenthInch2) /10;
//high torque motor ticks per rotation: 627, high speed: 392, turbo speed: 261 all for 393s
//circumference of 3.25" omni wheels = 10.20500"
//10.20500" traveled per rotation, which also means 102 tenths of an inch traveled per rotation
//627 ticks per rotation
//61 ticks per inch
wait1Msec(100); //wait for cortex to complete floating point operation because it's bad
moveMotorTarget(hdleft, goal2, -speed2, true);
moveMotorTarget(hdright, goal2, -speed2, true);
while(getMotorTargetCompleted(hdleft) == false || getMotorTargetCompleted(hdright) == false)
{
} // idle loop to wait for moveMotorTarget to complete
}
/*NOTES FOR OTHER TEAMMATES: for the Forward and Backward functions, distance is in tenths of an inch.
If you want to go, say, 10.5 inches, you need to type in 105, because it is in tenths of an inch.
Also, never put in 127 as the speed because PID algorithms won't be able to adjust above that. Use 120 as a maximum and
try to keep it at 100 unless the speed is super necessary. */
task main()
{
//go forward for 12 inches at 100 power (highest power is 127)
forwardDistance(120, 100);
/* reset encoders to 0. (I think I need to reset the encoders, but I am not 100% sure with the
move motor target function, since it might already reset them)*/
resetEncoders();
}