CONTROL
Assuming that your Micro Maestro 6-Channel USB Servo Controller and servos are still wired as they were when you finished the Hardware build, we’ll start by double checking that the Controller is properly configured, then confirm your install of PyCKBot is able to communicate with your hardware.
After that, we’ll briefly demonstrate scripted control (programming your robot to move in a prescribed manner) and dynamic control (piloting your robot in real time).
Controller USB Setup
- Launch the Pololu Maestro Control Center (i.e., MCC) by:
- opening the Terminal Emulator
- Navigating to the Maestro folder (probably by running cd ~/Desktop/maestro-linux), typing ./MaestroControlCenter, and hitting Enter
- Go to the “Serial Settings” tab and make sure that you are using either of the USB settings.
- If you’ve changed anything here, you’ll need to click the “Apply Settings” button in the lower right in order to update the Controller firmware. The button will grey-out and become unclickable once the changes are saved.
- Close the MCC.
Testing-Testing-1-2-3
- Open the Terminal Emulator, navigate to your pyckbot/tests folder (probably by typing cd ~/pyckbot/tests and hitting Enter)
- Type python3 test_pololu.py and hit Enter to run the Controller-specific test script.
- Servo0 should tic-tok once (for the “serial port” test), then tic-tok again (for the “CKBot layer” test). The following output will scroll in the Terminal window:
Direct from serial port test
high
low
off
CKBot layer
on
off
JoyApp layer
After a brief pause a fresh blank “pygame” window will pop open. Tons of stuff will start scrolling madly across the open Terminal windows, Matrix-style, and Serv0 will start tic-toking back and forth, and keep it up basically indefinitely. That’s fine. Click on the pygame window and hit Q (or select the Terminal window and hit Ctrl-c) to kill the script.
NOTE: If the servo doesn’t move at all, it may be because it just happened to already be “zeroed” (unlikely, but possible). Just to be sure, unplug the servo from the Controller board, and then plug it back in. (It will juke a little during both unplugging and re-plugging). Now run test_pololu.py again. If the servo doesn’t move this time, there’s a problem (probably a dead servo or dead batteries).
Scripted Control
- First, launch the Interactive Python Shell (iPython) by typing ipython3 into any open Terminal window
- Now enter the following each on its own line:
- import ckbot.logical as L
- c = L.Cluster(required=[0x80,0x81,0x82],names={0x80:"headfoot", 0x81:"mid", 0x82:"tailfoot"})
- The terminal will reply
Adding ServoModule headfoot
Adding ServoModule mid
Adding ServoModule tailfoot
- Enter c.at.headfoot.set_pos(3000)
- Servo0–the “headfoot”–will move to position 3000
- Repeat step #4 several times, replacing
headfoot
with mid or tailfoot, and replacing 100 with various values between -9000 and 9000. Watch your servos juke and jive! - When you are done, type exit and hit Enter to close iPython and return to the Terminal command line.
We’re clearly just scratching the surface of scripted control. To learn much more about how PyCKBot works, please go work through our intro this library: Make Your Life Easier with PyCKBot
Dynamic Control
- Using your text editor of choice (such as Mousepad—included with Xubuntu—or the command line utility pico) create the script shown below and save it on the Desktop as “dynamic.py” (You can just copy the text from the box below and paste it into your text editor.)
- Next, using the Terminal, navigate to the Desktop and run your script by entering “python3 dynamic.py” (The Terminal may reply with a string of WARNINGs you can ignore.) A fresh blank “pygame” window will pop open. (Tons of stuff will start scrolling madly across the open Terminal windows, Matrix-style. That’s fine.)
- Click on the pygame window, so that it’s in the foreground.
- Hit the a and z keys. The following will happen: The headfoot servo will now move back and forth at your command.
- Click on the pygame window and hit Q (or select the Terminal window and hit Ctrl-c) to kill the script.
- Open dynamic.py in your text editor. Can you:
- Add all three of your servos, controlling each with a different set of keys?
- Give each servo a real name (like “headfoot”) instead of calling it by its default (e.g., “Nx10”)?
- Change the increments your servo rotates with each keystrike?
dynamic.py
from joy.decl import *
ROBOT=dict(required=[0x80])
def on_K_a(evt):
app.robot.at.Nx80.set_pos(9000)
def on_K_z(evt):
app.robot.at.Nx80.set_pos(-9000)
### You need this at the end. It starts the robot and runs your code
from joy import runFlatScript
runFlatScript(locals())
Universal PyCKBot Troubleshooting
If there is something wrong and you’re sure it isn’t hardware related (did you check the batteries?), then it may be the PyCKBot software, which is still being actively developed. The following procedure is always a safe move, and will ensure that you have the latest version of PyCKBot and its vital libraries:
- Download this “public-net-installer” shell script, if you don’t still have it sitting on your Desktop. (Your browser may open it instead of downloading, because the script is a text file. If that happens, you can just save the page to your Desktop as “public-net-installer.sh“)
- Open the Terminal Emulator and navigate to your Desktop (probably by typing cd Desktop and hitting Enter)
- Run the script by typing bash public-net-installer.sh into the Terminal window and hitting Enter. (Get an error? No big deal; the script is gathering many packages from all over the place. An error usually means something was temporarily offline. Just try running the script again.)
- If this doesn’t fix your problem, then zap the pyckbot directory: from the Terminal type rm -rf ~/pyckbot and hit Enter). That’ll kill any lingering gremlins. Now run public-net-installer.sh once more (as per Step #3 in this process) and you’ll have a clean install.
Next Steps
You have hardware and software. You can make them work together. Let’s put it all together and Build a robot that can actually do something.