-
Notifications
You must be signed in to change notification settings - Fork 3
CamJam Robotics Kit
CamJam EduKit #3 - Robotics
We used Lego to build our chassis, holding the motors in place, with space for the Pi in between.
Other kit we added to what was supplied in the PiHut box:
- Raspberry Pi 3
- we chose the 3 to avoid needing cables as it has built-in Wifi and Bluetooth
- 8GB micro SD card
- This is the Raspbian recommended minimum size
- as we went for Raspbian Jesse Lite, 4GB would proabably have done
- Pocket phone charger to power the Pi
- Short USB micro power cable
- 4 AA rechargeable batteries to put in the motor power pack
- some Contact Adhesive to glue the wheel bearing socket to a flat Lego piece
- hand-picked contents of your Lego box :)
We loaded Raspbian Lite onto our 8GB microSD card (see Distros)
Once we turned on the Pi, we temporarily used a screen and keyboard to configure the following:
- sudo raspi-config
- set Hostname - to avoid confusion with other Pi devices on our network
- Expand Filesystem to fill SD card
- enable remote commands (SSH)
- Wifi connection details in WPA Supplicant
- reboot
Now we could connect remotely to the Pi using PuTTY [https://github.com/artmg/MuGammaPi/wiki/Remote-Desktop]
We chose Raspbian (Jesse) Lite for a smaller download, but it comes without some of the dependencies (programs required) to follow instructions in the CamJam worksheets.
# check that package sources are up to date
sudo apt-get update
# update all software currently installed, including kernel
sudo apt-get upgrade
# now install the CamJam dependencies
sudo apt-get install python3 python3-rpi.gpio
# install other libraries we use below
You cannot reliably copy the code from the CamJam worksheets, so they ask you to manually transcribe it. As much as this might be therapeutic for some, and educational for others, it can be a bind to have to re-type the lot.
If you want to simply copy the code to paste it into your own local editor, see
[https://github.com/CamJam-EduKit/EduKit3/tree/master/Code]
With modern phones and remote control apps we are spoilt for choice, However the Playstation controllers just feel right for commanding a small vehicle.
NB: Two important steps with pairing your controller over Bluetooth
- Remove all power to your PS3 console
- or do this far enough away
- so it can't interfere with the pairing and connection process
- Connect the PS3 controller in using a USB cable
- it needs to be directly connected to recognise and authenticate the specific controller
Most instructions were written for using USB bluetooth adaptors in the Raspberry Pi 2, so tell you to power off your Pi after installing software. If you are using a Pi 3 with Bluetooth onboard you can skip that step, as the adaptor will already be active.
see also:
- [https://github.com/artmg/MuGammaPi/wiki/Ready-made-input-devices]
- more about using Game Controllers like a Wiimote or PS3 controller
- [https://github.com/retropie/retropie-setup/wiki/Setting-up-a-PS3-controller]
- [https://github.com/recantha/EduKit3-Bluetooth]
This is rather a heavyweight solution, with loads of libraries being installed.
# credit [https://www.piborg.org/rpi-ps3-help]
sudo apt-get -y install libusb-dev joystick python3-pygame
cd ~
wget http://www.pabr.org/sixlinux/sixpair.c
gcc -o sixpair sixpair.c -lusb
Once installed, the article [https://www.piborg.org/rpi-ps3-help] guides you through:
- Connecting the Controller over USB to the Pi
- using
sixpair
to make our Pi bluetooth the master of this controller - using
bluetoothctl
to:- set the Bluetooth discoverable
- identify the MAC address of the controller
- try to connect
- trust (pair with) the controller
- test the inputs to see which controls you're pressing
Use the code at
[https://github.com/artmg/MuGammaPi/blob/master/EduKitRobotics/ps3ControlCamJamCar.py]
NB: due to limitations with pygame expecting a display, you must run this as sudo
For possible workarounds see:
- [http://unix.stackexchange.com/questions/58961/how-do-i-let-an-sdl-app-not-running-as-root-use-the-console]
- [https://www.raspberrypi.org/forums/viewtopic.php?t=46096&p=388598]
If you want this to automatically start up when the Pi boots then:
- copy the contents of the script at the link below
- open a command window via SSH
- paste in the scipt commands
[https://github.com/artmg/MuGammaPi/blob/master/EduKitRobotics/ps3ControlCamJamCar.InstallService.sh]
This should install the service and reboot to test it's running
- see also Raspbian autostart
Please note that this service starts up pretty soon after you power on your Pi, but it will not start properly unless it finds a controller connected. Therefore you should:
- Power on your controller
- See the four controller number LEDs flashing
- THEN power on your Pi
- After a few seconds, one of the controller number LEDs goes steady
- now you should be able to control your robot
This is a much lighter-weight setup, but might be more work to hack.
see [https://pythonhosted.org/triangula/sixaxis.html] or [https://www.raspberrypi.org/forums/viewtopic.php?t=130201&p=869560] and [https://github.com/RPi-Distro/python-sense-hat/issues/9]
Note that evdev is "a generic input event interface in the Linux kernel" and is not related to ev3dev below.
Pulse Width Modulation (PWM) is a technique sometimes used in telecommunications, for encoding one signal within another. However, by turning power on and off very quickly, you can regulate the overall percentage of time that power is actually turned on. Because you control the amount of power delivered to a load, without dissipating any wasted power, it is an energy efficient means to control the speed of DC motor.
CamJam Edukit 3 Worksheet 7 covers the programming basics.
The worksheet states that the motor circuit is an h-bridge
, but what IC does it use (so we can look up its characteristics)
[http://www.robotroom.com/PWM5.html] explains some of the pros and cons of choices you might make for "power control" to make DC motors and LEDs weaker or stronger.
Beware:
-
audible hum - slightly annoying for people in the room
-
radio frequency (RF) interference - annoying for people and devices relying on radio signals for service and entertainment
-
one person's advice for motor frequencies [https://www.raspberrypi.org/forums/viewtopic.php?f=37&t=133009]
-
Adafruit tutorial suggests 500Hz [https://cdn-learn.adafruit.com/downloads/pdf/adafruit-raspberry-pi-lesson-9-controlling-a-dc-motor.pdf]
- Intro to soft PWM [http://raspi.tv/2013/rpi-gpio-0-5-2a-now-has-software-pwm-how-to-use-it]
- Comparing the types of PWM available [http://raspberrypi.stackexchange.com/questions/298/can-i-use-the-gpio-for-pulse-width-modulation-pwm]
- Using the clock to choose hardware frequencies [http://raspberrypi.stackexchange.com/questions/53854/driving-pwm-output-frequency]
- coding using hardware PWM [http://stackoverflow.com/questions/20081286/controlling-a-servo-with-raspberry-pi-using-the-hardware-pwm-with-wiringpi]
see also:
- [https://docs.google.com/document/d/1z6bJ98HL0Mkx5gJ0zj70wZER22MLfqQsBr68-bxLPUg/edit]
- [http://www.mikronauts.com/robot-zoo/hobbit/]
- [http://mattandshirl.blogspot.co.uk/2013/06/lego-car-controlled-by-raspberry-pi-and.html?m=1]
- [http://www.mikronauts.com/2016/05/29/serving-raspberry-pi-6-virtual-bumpers-robot-hotspot-wireless-joystick-remote/]