|
| |||||
|
|
![]() Our software design consists of a single class which implements motor control, touchsensors for bumbers, on/off switch and chase/avoid switch, as well as sonar polling. This main class spawns a separate thread which samples the CMU camera. Upon entering the main class, the sonar, bumpers and switches are initialized and the camera thread is started. After initialization, the main class enters a never- ending loop that constantly checks the values returned from the sonar and the camera and causes the motors to respond accordingly. When events occur on the bumpers and switches, they change the value of booleans associated with each event. The robot begins searching for a red object to track and shoot. If it doesn't see anything within 90cm, it considers there to be no targets and continues to drive in a search pattern, turning in the direction of the last target tracked for a short time and driving slightly forward. Once it acquires a target, it uses the sonar to determine if the target is the to the left or right and drives toward the target until it gets within 20cm. If it determines that the target that it is chasing is a moving target (using changes in the sonar and variations in red color), it switches on a laser to 'paint' the target. If it loses track of the target, or the target appears to remain still for a long time, it turns off the laser and begins searching for a new target in the direction it last saw the previous target.
State Diagram A few problems were encountered while writing the software to control the robot. Since performance wasn't a major concern for us in this robot, we steered clear of complicating the software with threads. However, since we were taking the color value each time through our main loop, the robot was unable to see the target when it moved quickly. We had to use a thread to constantly take color values and report them back to the main class in order to speed up the sample rate of the camera. The original choice for a target color was blue, but the robot was unable to detect blue well. Blue and gray appeared about the same to the camera. We tried to put white LEDs around the camera to improve its color perception, but that didn't help much. We tried lighting up the target with a portable while light bulb, but blue continued to appear gray to the camera. In the end, we decided to use red for the target color. |