I am trying to use lineTrackForTime command on claw robot but it seems like the robot just run over the line and can't detect it.
However when I switch to square robot, the lineTrackForTime command worked.
The following code works on the square bot but not on the claw bot.
#pragma config(StandardModel, "RVW SQUAREBOT")
#pragma config(RenamedStdModelSensor, in1, leftline)
#pragma config(RenamedStdModelSensor, in2, centerline)
#pragma config(RenamedStdModelSensor, in3, rightline)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
// already set the line follower sensors and sonar sensor. Didn't rename the Sonar sensor
// set a forward function, will use it with waitInMilliseconds command later
void straight()
{
startMotor(leftMotor,127);
startMotor(rightMotor,127);
}
// set a turnright function, will use it with waitInMilliseconds command later
void turnRight()
{
startMotor(leftMotor,30);
startMotor(rightMotor,-30);
}
task main()
{
// move the robot out of the start area , go straight and turn right
straight();
waitInMilliseconds(2000);
turnRight();
waitInMilliseconds(2700);
// after robot out of start area, keep moving forward until meet the dark line
forward();
//use lineTrackForTime command to make the robot follow the line
lineTrackForTime(45,505,in1,in2,in3);
//after the line ends, robot will keep move forward until the sonar sensor detect the distance to the wall(less than 30cm), then it stops
forward();
untilSonarLessThan();
stop();
}
How can I make the code work with the claw bot to do the line following?
TLDR: Dont shouldnt use PLTW with the claw robot
Why not?
The PLTW for vex has hardcoded motor ports. These ports are 2 & 3 for movement. The square robot does have motors at ports 2 & 3, making it work. However the claw has motors at ports 1 & 10. As I said, these are hardcoded into the software, and would require changing each line. This basically disables your entire program as the forward function wont work as well.
What to do?
Swap to Natural Language 2. It may not have the
lineTrackForTimefunction exactly, but it offerslineTrackLeft&lineTrackRightwhich you can utilize as such(taken from documentation if you need the time ability). This language allows for more flexibility, and if done correctly can be used with both robots(while the PLTW is limited to the square robot).The nice thing about this is that these commands use
setMotorSpeeds(speedSecondary, speedPrimary);instead of having hardcoded values.I would like to not this would also disable the
untilSonarLessThan();function, but this could be easily reimplemented into your main code as such(taken from the source code),Additionally, this disables the
stop()command as well; but this should be replaced withreturn 0;.For further note, the
forward()function is different than in PLTW, but should still work as you intended.What if you want to still use PLTW?
You could directly modify the natural language to change its motor ports. But this is not recommended. All of the commands are hardcoded, and if you do modify it, it will only work for you, and not to anyone else with the program. This would also disable the clawbot's abilities.
However, if you do want to do this, then right click
lineTrackForTime()and clickGo to definition/declarationThen modify it to take motor ports like so.
A better way to do this would create a new function and have this within; and just call this function instead of the normal function, however this would be a hassle if editing a lot of functions. But again, I highly recommend changing langauges.