Ultrasonic motion tracking

Correct me if I’m wrong but I think there is a way to control a VEX robot with motion controls. And no, I’m not talking about the accelerometers in the joystick.

By using the ultrasonic sensor, you are able to detect objects that are close and far away. Therefore, have the sensor ignore objects that are X distance away, and follow objects that are closer than that distance. if the object goes out of its line of sight, have it pause and either:

A) wait for the object to come back into view.
or
B) scan and search for the object.

Overall its simple enough to do but easy enough to mess up. I’m currently testing to see if my theory is correct but if anyone has any code to share please do.

This should certainly be possible and in the case of A, not difficult. B however would be quite a bit more difficult. I think scanning would be tricky as it implies to me actively moving the sensors until you detect something in range. Not impossible, just difficult. You would have to mount the sensors on a movable device that could sense what direction it was facing when it detected the object, then move the robot in that direction. Not impossible, but difficult.

A single sensor is pretty much for “distance to a target”. To do location well, you really need two sensors, they can be used to locate a part (both sensors on), or detect when a part has moved out of range. (if one sensor loses detection, then drive that side faster until detection by both occurs again). It’s very much like using line trackers. With only one sensor, your scan to re-acquire the target will be wrong half the time, and there’s not really time to deal with spinning 360° to find your target.

You can try to see if you can treat the ultrasonic sensor as a line tracking sensor where maybe the ultrasonic sensor will follow the edge of the object nearby??? I’m not sure but it’ll take a long time to figure it all out with just one ultrasonic sensor. Like maybe something like this with 2 ultrasonic sensors, where the left one(This will be placed on the middle of the robot) is used to make the robot stay the correct distance and the right one(Will be placed right of the middle ultrasonic sensor) is used to stay on target:


If distance of the left sensor is closer than 20 inches{//See if an object is in range
 if the distance of the right sensor is closer than 20 inches{//If robot is too far left of the object
  Turn Right
 }
 else if the distance of the left sensor is farther than 10 inches{//If robot is farther than desired distance
  Drive forward
 }
 else if the distance of the left sensor is closer than 9 inches{//If robot is closer than desired distance
  Drive backward
 }
else{//When all is perfect
Stop Motors
}
}
else{//Search for an object nearby or see if object is too far right
 Turn Left
}

Actually this won’t be a typical driving robot. I’m using these sensors to control a robotics arm that I built for a senior project. I’ve attached a picture of the arm in this post for reference. As of right now I have two sensors. One for left / right, the other for up/down. However, I’m having problems with it detecting my hand and not the other sensor. Is there a way to have two dead-zones for the sensors? (one for outside and one for the center)
IMG_1013.JPG

OK I just finished programming it and here is the code:

while(SensorValue(Sonar1) < 11) //left
		{
			motor[base] = -30;
		}
		while(SensorValue(Sonar1) > 20) //right
		{
			motor[base] = 30;
		}
		if (SensorValue(Sonar1) >= 12 || SensorValue(Sonar1) <= 19 ||
			SensorValue(Sonar2) >= 13 || SensorValue(Sonar2) <= 19 ||
	    SensorValue(Sonar1) == -1 && SensorValue(Sonar2)== -1) // no input / zero'd
		{
			motor[base] = 0;
			motor[elbow] = 0;
		}
		while(SensorValue(Sonar2) < 12) //down
		{
			motor[elbow] = -30;
		}
		while(SensorValue(Sonar2) > 20) //up
		{
			motor[elbow] = 35;
		}

after testing it, here are the results:

  • before starting, make sure your “hand” is in the dead zone (its a 8x7 rectangle).
  • for some reason, the sensors have trouble detecting my hand so I used a pole instead.
  • when stopping, make sure your “hand” is in the dead zone otherwise it won’t stop.

So does anyone have any ideas of how to improve it?