I was using sample programs to get a handle on “line tracking” and the use of sensors.
I wrote code for a physical robot (has latest 1.11 firmware) to follow a black line using the color sensor (grayscale mode, port9) until it bumped an obstacle. I am using RobotC “Natural Language (?)”.
I noticed that when “setRobotType(VexIQClawbot);” is part of the program, the color sensor very briefly turns on and then off quickly. The robot does not line track and goes off course.
I saw a recent forum topic on the color sensor, “Color Sensor not working in Grayscale (7.10.2014) and saw a suggestion to “delete” the “setRobotType” command. When I “commented” out the “setRobotType” command, I noticed that the color sensor stays on for the duration of the program and the robot is able to line track to the obstacle.
Not having the “setRobotType” command affects other program functions. I noticed that not having the “setRobotType” command makes a difference in both the “Virtual World” and with the “Physical Robot”. Is there something I am missing with the use of the color sensor … or … is this situation similar to the bug identified with the RobotC “Graphical” Programming environment ?
Code is listed below :
#pragma config(Sensor, port8, bumpSwitch, sensorVexIQ_Touch)
#pragma config(Sensor, port9, lineDetector, sensorVexIQ_ColorGrayscale)
#pragma config(Motor, motor1, leftMotor, tmotorVexIQ, openLoop, encoder)
#pragma config(Motor, motor6, rightMotor, tmotorVexIQ, openLoop, reversed, encoder)
#pragma config(Motor, motor10, armMotor, tmotorVexIQ, openLoop, encoder)
#pragma config(Motor, motor11, clawMotor, tmotorVexIQ, openLoop, encoder)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//
task main()
{
setRobotType(VexIQClawbot); // Possible Bug ?? Color Sensor stays on (Tracks line) only when “setRobotType” command is commented out
moveMotor(armMotor, 180, degrees, 100); //lift arm
repeatUntil (getBumperValue(bumpSwitch)==1 ) //forward to obstacle
{
if(getColorValue(port9) < 145) // initial threshhold = 145
{
// counter-steer left: if on white tracks RIGHT side of line
setMotor(leftMotor, 30); //Set the leftMotor (motor1)
setMotor(rightMotor, 20); //Set the rightMotor (motor6))
}
else
{
// counter-steer right:
setMotor(leftMotor, 20); //Set the leftMotor (motor1)
setMotor(rightMotor, 30); //Set the rightMotor (motor6)
}
}
stopMultipleMotors(leftMotor, rightMotor,,);
wait (1, seconds);
clearTimer(T1);
while(time1[T1]<=4000) //reverse from obstacle
{
setMotor(leftMotor, -20);
setMotor(rightMotor, -20);
}
}