Investigating Node.js for Raspberry Pi Robotic Vehicle

I’ve been looking at alternatives to WebIOPi since it is no longer maintained. I have successfully built a few, small vehicles running WebIOPi but it seems that the project is no longer supported. I was also never satisfied with the latency when moving the vehicle or servos attached to it.

I’ve worked with Node.js before but was not aware that you could use it to create the PWM signals that I normally use to control the motors on my vehicles. I have developed larger vehicles now, with tank tracks, that use 12 volt drill motors. I use Radio Controlled ESC’s (Electronic Speed Controllers) to handle the increased voltage and amperage. This is a small tracked vehicle I built controlled by Node.js, Johnny-five and Raspi-io. I deploy an ad-hoc network on the bot for a connection.

Just a side note. I built this vehicle from spare parts and junk I had in the garage. The frame is made from crutches. The track wheels are from an old set of roller blades. The tracks themselves were made from rubber tarp straps. I cut the metal ends off and spliced them together. I then screwed metal stitching plates used in construction between the two straps. Topped them off with strips of rubber that I cut up from a spare BMX tire. Motors are cheap drill 12V. I bought two 30amp RC ESC’s on Ebay for the connection between the Raspberry Pi and the motors. I used PWM signals to make them go forward, backward and define the speed.  I built my own dashboard to control it. Using the extensions of Node called Express & Socket.io to do this through a browser.

These are my notes so far while installing Node.js and other components.

  1. Intall Node using the ARM package
  2. Install the Pi-blaster daemon
  3. [sudo git clone https://github.com/sarfata/pi-blaster]
  4. [sudo apt-get install autoconf]
  5. [cd pi-blaster]
  6. [sudo ./autogen.sh]
  7. [sudo ./configure]
  8. [sudo make]
  9. [sudo make install]
  10. [cd ..]

Create a folder for your project.

Install the node modules that you need. Express, socket etc..

 

 

 

 

 

quick2wire-gpio-admin

If you are using quick2wire-gpio-admin, you’ll need to make a few changes to make it work.

https://github.com/quick2wire/quick2wire-gpio-admin/pull/6

In src/gpio-admin.c

Change this line 30  int size = snprintf(path, PATH_MAX, "/sys/devices/virtual/gpio/gpio%u/%s", pin, filename);
To this --          int size = snprintf(path, PATH_MAX, "/sys/class/gpio/gpio%u/%s", pin, filename);

Did a “sudo make uninstall” from within the quick2wire-gpio-admin folder, then “sudo make install” and added the user “sudo adduser $USER gpio” (where $USER is your user..). Logout and login,

 

Read More

Setting Up ServoBlaster On Raspberry Pi

Project Notes for using servoblaster and webiopi on my Raspberry Pi Robot :

gpio-descriptions

Start ServoBlaster at boot and have the ability to restart using init.d

Note: I’ve set this up to start and only use pins 11 and 12 by adding  –p1pins=”11,12″ after servod.
If you leave this off it will default to use all of the pins. I did it this way because the other pins were interfering with my Webiopi operation of two motors.
1. Create a file in /etc/init.d/ called servoblaster.
2. paste the code below


#!/bin/bash
# /etc/init.d/servoblaster

### BEGIN INIT INFO
# Provides: servoblaster
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This service is used to manage a servo
### END INIT INFO

case "$1" in
start)
echo "Starting servoblaster"
/home/pi/WebIOPi-0.7.0/examples/magpi-cambot/servod --p1pins="7,11,12"
;;
stop)
echo "Stopping servoblaster"
killall servod
;;
*)
echo "Usage: /etc/init.d/servoblaster start|stop"
exit 1
;;
esac

exit 0


4. Make it executable

sudo chmod +x /etc/init.d/servoblaster

5. I could start it with the following:

sudo /etc/init.d/servoblaster start

…and stop it again with this one:

sudo /etc/init.d/servoblaster stop
6. Have it start every time the PI boots
sudo update-rc.d servoblaster defaults

 

These notes were compiled using the tutorial at the link below. Thanks Raspberrypiwebserver for posting this info:
Please note that the tutorial originally references a /etc/init.d/servoblaster file but then moves to /etc/init.d/servod later on. I have changed that in my notes above to reflect only a /servoblaster file name in /etc/init.d

http://raspberrywebserver.com/serveradmin/run-a-script-on-start-up.html

 


I am using Webiopi for my web control of the robot, motors and servos. Webiopi is passing commands to ServoBlaster in my cambot.py file. Through testing I’ve found these are my settings for the Pan and Tilt servos which hold my Pi Camera.

Lights: Servo 0 – Pin 7 / GPIO 4
I use this pin to control an LED light on the front of my vehicle

Pan: Servo 1 – Pin 11 / GPIO 17
Negative value is pan right using incremental method – echo 0=-10 > /dev/servoblaster
Positive is pan left using incremental method-  echo 0=+10 > /dev/servoblaster
Neutral is 120-   echo 0=120 > /dev/servoblaster

Tilt: Servo 2 – Pin 12 / GPIO 18
Positive value is tilt up using incremental method – echo 1=+10 > /dev/servoblaster
Negative value is tilt down using incremental method – echo 1=-10 > /dev/servoblaster
Set value 100 is 3/4 up –  – echo 1=100 > /dev/servoblaster
Neutral is 60 –   echo 1=60 > /dev/servoblaster

 


 

Read More

Project Notes: Make: A Raspberry Pi Controlled Robot by Wolfram Donat

I’ve already been building various smaller robotic vehicles using the Raspberry Pi . However, I came across a review of the book by Wolfram Donat called MAKE: A RASPBERRY PI CONTROLLED ROBOT. Building a Rover with Python, Linus, Motors and Sensors. ( Book Link ) I’ve had some trouble using higher voltage motors (from a drill), a PI camera and various servos all on a working Rover. I knew I could learn something from this book so I bought if off Amazon.com and starting digging in a few days later. I am soooo glad i bought this book!!

I’m currently in Chapter 6 and I’ve really learned a lot already that is going to take my Rover to the next level.
I’ll chronicle my efforts on this blog along with my project notes. Stay tuned.

Changes to Pi:

1. Added static ip to /etc/network/interfaces so that I can use the same ip to SSH into every time.

2. Created a second /etc/network/interfaces file with an Ad Hoc network. This allows the PI to create a wireless network anywhere that you can log into with a computer or mobile device even if there is not a wireless network present. Great if you are testing outside, in the woods etc….

3. Added Tight VNC Server so that I can VNC into the pi if I ever want to use the GUI Desktop.
sudo apt-get install tightvncserver

Once VNC is installed you can start from the command line on the pi with :
vncserver :1 -geometry 1024×768 -depth 16

You’ll need to install VNC on your PC or Mac and then connect to the pi with this client.

4. Installed ServoBlaster for managing the Servos on my Pi Rover.

I’ll post instructions for the 4 steps soon. Drop a comment on here if you have any questions.

Read More