Hi, newbie to the forum here.
I am running a PLTW class using Vex Natural Language PLTW and Vex Cortex 2.0. We are building 'bots that are supposed to go forward, and if they see an obstacle back up for a time, then pick a random direction (left or right) and then try going forward again. I have even set up an indicator light to check which direction it picked.
Now the issue: I am attempting to put in a code block that says when the bump switch is pressed, the reverse motion stops and the robot will “rest” for 1 second, then start the sequences where it turns.
Anyhow, this is the code. I tried putting the untilbump or SensorValue code in, but the robot seems to not register the switch. So any help would be appreciated – I feel like I am coding “correctly” but the order is wrong.
Another weird behavior is one of the LEDs seems to stay on even though the beginning of the code turns them both off.
(These robots were build and designed by students)
Any guidance is much appreciated.
#pragma config(Sensor, dgtl2, redlight, sensorLEDtoVCC)
#pragma config(Sensor, dgtl5, bumpSwitch, sensorTouch)
#pragma config(Sensor, dgtl9, ultrasonic, sensorSONAR_cm)
#pragma config(Motor, port1, leftMotor, tmotorVex393_HBridge, openLoop)
#pragma config(Motor, port10, rightMotor, tmotorVex393_HBridge, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//
task main()
{int direction; //introduce variable “direction”
direction = 0; // set the variable to zero
repeat(forever)
{turnLEDOff(dgtl2);
turnLEDOff(dgtl3);
stopMotor(leftMotor);
stopMotor(rightMotor);
startMotor(leftMotor,60); //start moving forward
startMotor(rightMotor,60);
untilSonarLessThan(20,dgtl9);
stopMotor(rightMotor);
stopMotor(leftMotor);
startMotor(leftMotor,-30); //start moving backwards
startMotor(rightMotor,-30);
wait(2);
untilBump(dgtl5);
stopMotor(leftMotor);
stopMotor(rightMotor);
direction = random(2);
if (direction == 1)
{
turnLEDOn(dgtl3);
stopMotor(leftMotor);
stopMotor(rightMotor);
startMotor(leftMotor,-20);
startMotor(rightMotor,20);
wait(1.5);}
else
{
turnLEDOn(dgtl2);
stopMotor(leftMotor);
stopMotor(rightMotor);
startMotor(leftMotor,20);
startMotor(rightMotor,-20);
wait(1.5);}
}}