We have a challenge in which the Ultrasonic sensor seems to be the most appropriate sensor for 30-seconds autonomous mode. As part of our challenge, we need to pick up objects and drop them off in a different location. I am trying to make the robot sense obstacles and turn:
#pragma config(Sensor, dgtl3, sonarSensor, sensorSONAR_cm)
#pragma config(Motor, port1, leftMotor, tmotorVex393, openLoop, reversed)
#pragma config(Motor, port10, rightMotor, tmotorVex393, openLoop)
task main()
{
int speed; // Will hold a speed for the motors.
int sonar_value; // Will hold the current reading of the sonar sensor.
int distance = 5; // Specified distance to be at 5 centimeters.
while(SensorValue[sonarSensor] > 10) // While greater than 5 cm distance...
{
//...Move Forward
motor[rightMotor] = 63;
motor[leftMotor] = 63;
}
//...Turn
if (SensorValue [sonarSensor] < 8)
{
motor [rightMotor] = -127;
motor [leftMotor] = 127;
wait1Msec (1000);
}
else
{
speed = (sonar_value - distance)*2; // Set 'speed' equal to the 'sonar_value' minus desired 'distance'.
}
}
The robot stops, but it doesn’t turn, what am I missing?