Movement Tracker/Follower

Hey everyone - in an attempt to make a robot that follows movement using ultrasonic sensors, I’ve created this code, but I need help.

#pragma config(Sensor, dgtl1,  leftSensor,     sensorSONAR_inch)
#pragma config(Sensor, dgtl3,  middleSensor,   sensorSONAR_inch)
#pragma config(Sensor, dgtl5,  rightSensor,    sensorSONAR_inch)
#pragma config(Motor,  port2,           rightMotor,    tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port3,           leftMotor,     tmotorVex393_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()


int firstValM=SensorValue(middleSensor);//stores the first value for middle sensor
int firstValL=SensorValue(leftSensor);//stores the first value for left sensor
int firstValR=SensorValue(rightSensor);//stores the first value for right sensor

//Start follow
while(SensorValue(middleSensor) < 50 && SensorValue(middleSensor) > 15) //move forward
  if(SensorValue(middleSensor) < firstValM || SensorValue(middleSensor) > firstValM  && SensorValue(middleSensor) > 0)
  }//end if
}//end if

if(SensorValue(middleSensor) == firstValM)

//End follow

}//end while

}//end main

My robot has a chassy similar to the one of the recbot, but with three ultrasonic sensors protruding from the front. One directly forwards at 0 degrees, one oriented right at 45 degrees, and one oriented left at 315 degrees. So far, as soon as said object is within 15-50 inches of the middle ultrasonic sensor and moves, the robot moves forward in an attempt to follow the object (I really need to put encoders on this thing). Forward follow works perfectly. But I just can’t seem to find a way to integrate the forward follow with the left and right ultrasonic sensors (So that when the left sensor senses motion it turns left, when the right sensor senses motion it turns right, etc.). If anyone has any ideas or a solution, I’ll be forever grateful.

I have moved this to the public tech support forum so the community can comment.

1 Like