SpoonBot-demo

Version 16 (Anthony Rowe, 06/24/2007 09:23 pm)

1 1 Anthony Rowe
2 16 Anthony Rowe
h1. Testing a spoonBot
3 1 Anthony Rowe
4 16 Anthony Rowe
5 16 Anthony Rowe
6 1 Anthony Rowe
[[Image(htdocs:images/spoonBot_thumb.jpg)]]
7 3 Anthony Rowe
8 16 Anthony Rowe
spoonBot is a simple differential drive robot with a spoon connected to a servo that allows it to pan and tilt.  See the [[spoonBot|spoonBot-Construction]] page for information about building spoonBot.  The sample program that comes with the latest cc3 distribution contains sample code demonstrating how to move spoonBot as well as run spoonBot Demo mode.  spoonBot Demo mode is similar to the CMUcam2 demo mode only it uses spoonBot to pan and tilt.
9 1 Anthony Rowe
10 1 Anthony Rowe
11 1 Anthony Rowe
12 16 Anthony Rowe
h2. Calibrating spoonBot
13 16 Anthony Rowe
14 16 Anthony Rowe
15 3 Anthony Rowe
Before using spoonBot, you need to calibrate your servo settings.  This is done by setting the following data structure at the top of main:
16 16 Anthony Rowe
<pre>
17 16 Anthony Rowe
<code class="c">
18 16 Anthony Rowe
 // [[SpoonBot]] Calibration Points
19 3 Anthony Rowe
  //   Assume Left = Servo 0
20 3 Anthony Rowe
  //   Assume Right = Servo 1
21 3 Anthony Rowe
  //   Assume Spoon = Servo 2
22 3 Anthony Rowe
  my_cal.left_mid = 71;
23 1 Anthony Rowe
  my_cal.right_mid = 77;
24 1 Anthony Rowe
  my_cal.spoon_down = 100;
25 1 Anthony Rowe
  my_cal.spoon_mid = 202;
26 1 Anthony Rowe
  my_cal.spoon_up = 255;
27 1 Anthony Rowe
  my_cal.left_dir = 1;
28 1 Anthony Rowe
  my_cal.right_dir = -1;
29 1 Anthony Rowe
  my_cal.spoon_dir = 1;
30 1 Anthony Rowe
  // Set the calibration points
31 1 Anthony Rowe
  spoonBot_calibrate (my_cal);
32 16 Anthony Rowe
</code></pre>
33 7 Anthony Rowe
34 16 Anthony Rowe
* Flash the cmucam2 emulation firmware onto the camera
35 16 Anthony Rowe
* Open either the CMUcam3 Frame Grabber or a Terminal Program
36 16 Anthony Rowe
** Using the Frame Grabber, go to the "Settings" panel and drag the servo bars to change values
37 16 Anthony Rowe
** In a terminal, type "sv <servo-id> <servo-value>" to set the servos for example:
38 16 Anthony Rowe
<pre>
39 10 Anthony Rowe
    :sv 0 77
40 5 Anthony Rowe
    ACK
41 16 Anthony Rowe
</code></pre>
42 16 Anthony Rowe
* Find the middle position of Servo's 0 and 1 by adjusting them until the wheels stop
43 16 Anthony Rowe
*** _my_cal.left_mid_ = <value from servo 0>
44 16 Anthony Rowe
*** _my_cal.righ_mid_ = <value from servo 1>
45 16 Anthony Rowe
** Now you need to find the sign of the directions
46 16 Anthony Rowe
*** Looking at spoonBot from the back (spoon towards you) try lowering the servo 0 number which should be the left wheel 
47 16 Anthony Rowe
**** if the servo spins clockwise / backwards (toward you) then _left_dir_ should be set to 1
48 16 Anthony Rowe
**** if the servo spins counter clockwise, _left_dir_ should be set to -1
49 16 Anthony Rowe
*** Repeat for servo 1 (which should be the right wheel from spoonBot's point of view)
50 16 Anthony Rowe
**** if the servo spins clockwise / backwards (toward you) then _right_dir_ should be set to 1
51 16 Anthony Rowe
**** if the servo spins counter clockwise, _right_dir_ should be set to -1
52 16 Anthony Rowe
*** Usually, one servo should be set to negative!
53 16 Anthony Rowe
** Now find the Min, Middle and Max spoon positions by adjusting Servo 2
54 16 Anthony Rowe
*** Min should be the smallest value that pushes the spoon down and hence tilts spoonBot forward
55 16 Anthony Rowe
**** Set _spoon_down_ accordingly
56 16 Anthony Rowe
*** Max is usually 255 and should position spoonBot looking as far up as possible
57 16 Anthony Rowe
**** Set _spoon_up_ accordingly
58 16 Anthony Rowe
*** Middle is the value that makes the servo level
59 16 Anthony Rowe
**** Set _spoon_mid_ accordingly
60 16 Anthony Rowe
*** If Min and Max appear to be reversed, change _spoon_dir_ to -1
61 11 Anthony Rowe
62 11 Anthony Rowe
Once the calibration is done, recompile the project and FLASH the CMUcam3. spoonBot will first go through a sequence of scripted motions to make sure the servos are setup correctly.  Then spoonBot will wait for a button press to begin tracking a color.  Text is displayed over the serial port notifying you of the various stages of operation.
63 11 Anthony Rowe
64 11 Anthony Rowe
The scripted motion should be as follows:
65 16 Anthony Rowe
* Sit Still
66 16 Anthony Rowe
* Look Down
67 16 Anthony Rowe
* Look Up
68 16 Anthony Rowe
* Back to Middle Position
69 16 Anthony Rowe
* Rotate Clockwise (looking from above)
70 16 Anthony Rowe
* Rotate Counter-Clockwise
71 16 Anthony Rowe
* Red-Led off while camera gets ready
72 16 Anthony Rowe
* Red-Led turns on when ready to track
73 1 Anthony Rowe
74 1 Anthony Rowe
If this looks correct, then try holding a brightly colored object a few inches in front of the camera and then press the button.  As you pull the object away, spoonBot should rotate towards it.  Use brightly colored objects that are as uniform in color as possible.  An object like a bright red cloth would work well since it reflects very little light (other than the pure red).  Make sure there is enough lighting in the room.  Try grabbing a frame to see what the conditions look like.
75 1 Anthony Rowe
76 16 Anthony Rowe
*Note: If you wish to disable servos without unplugging them, disconnect the servo-power-jumper.*