How do I program distance sensor for zumo robot

Hi, does anyone have an idea for how to program the sharp distance analog sensor for the zumo robot v1.2? I have a competition at The NRC in 2 weeks, but I don’t know how to program the arduino uno board for a mini sumo program using the GP2Y0A02YK0F or the GP2Y0A21YK0F. The robot needs to roam for the opponent, then sense for the robot with the distance sensor and attack the robot with the collision detect program. Also, the robot needs to have a border detect function so that it won’t run put of the ring. By the way, if you go to thenrc.org you can find the size of the ring. (It is bigger than the average ring and the robot size maximum is 20cm by 20cm by 20cm) Thanks!

Hello.

I suggest starting with the simpler BorderDetect example that comes with the Zumo Shield Arduino Library. This example has some of the behavior you described already (e.g. roaming around the ring and detecting the edge of the ring). Then after you get it working, you could go back and add the collision detection methods from the SumoCollisionDetect example if you still want to.

You can read the Sharp analog distance sensors using the Arduino’s analogRead() command. How many Sharp analog distance sensors are you using? If you are using one, you could use that to just speed up the robot when it senses the opponent. If you are using two, you could cross reference the sensors with the motors. This way if the right sensor sees the opponent, your left motor would speed up, turning towards it. Similarly, your left sensor could speed up your right motor. Then, if both sensors see the robot, both motors would speed up.

If you try editing the example or writing your own code and run into problems, you can post your code here, and I’d be happy to take a look.

-Brandon

Thanks, I will look into it and report back if I run into any walls!
~LightningAC

How do I make the collision detect program work with the include avr pgmspace in the beginning. The program won’t compile because of this. Any ideas?

Is there a reason you believe #include <avr/pgmspace.h> is causing the problem? Can you post the output from the Arduino IDE when you try to compile the SumoCollisionDetect example? Also, please note that (as noted in the comments of the SumoCollisionDetect code) the LSM303 library is not included in the Zumo shield libraries, so you will need to download and install it separately. If you have not done so, could you try doing that as well?

Brandon

Before when I tested the sumocollisiondetect example, it never worked because the program couldn’t find a library for avr/pgmspace. But when I deleted that line and pressed undo, it for some reason worked. So yeah.

Also, is there anyway to invert the SumoCollisionDetect example so that the sensor reacts to a black line and not a white line? This is only because I have a white field and black border ring, whereas I don’t have an actual sumo ring to test it on?

I am not sure why pgmspace.h is causing a problem compiling, but it seems like it should be fine to remove it or comment that line out if that works for you. I am not the person who wrote that demo, so I am not sure of its original purpose, but it looks like it might not be needed in the current version of the code.

As far as inverting the boarder detection behavior, that code looks at the leftmost and rightmost reflectance sensors, compares them to a threshold, and turns if either value is less than the threshold. You should be able to simply change the greater than to less than in those comparisons (in lines 230 and 235 of the unmodified SumoCollisionDetect example). If this results in some erratic behavior, you might also need to lower the QTR_THRESHOLD value.

Brandon

1 Like