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,

 

Raspberry Pi – Edimax EW-7811Un Wifi dongle powers down / goes to sleep fix.

Edimax EW-7811Un Power Management

I have several of the tiny Edimax Wifi dongles that I use on my Raspberry Pi’s. If you leave the Pi unattended for awhile, the Edimax will go to sleep and you’ll lose your SSH connection. Here is a fix that worked for me. This is entered on the command line / terminal.

sudo nano /etc/modprobe.d/8192cu.conf

Add the following lines to this file you created. It disables the power down on the Edimax.

options 8192cu rtw_power_mgnt=0 rtw_enusbss=0

Then, do your normal Ctrl-X, Yes and save this file. Reboot. 


Simple Wifi Configuration for Raspberry Pi /etc/network/interfaces

Sometimes, when I’m troubleshooting or initially setting up a Raspberry Pi,  I like to create a dead simple configuration to connect to my home wifi network. This skips using the wpa_supplicant and has all the information in the intitial networking file for simplicity.

From the command line on your Pi I do the following:

  1. cd /etc/network
  2. sudo cp interfaces interfaces-wifi

    This makes a copy of our existing interfaces file for a backup.

  3. sudo nano /etc/network/interfaces

    We open the file in a text editor to make our changes.

Update the code in this file so that it contains the code following this paragraph:
Be sure to insert the name of your network in place of ssid inside the quotes as the value for wpa-ssid and password in the appropriate place as the value for wpa-psk, within the code. You may already some of these lines in there for your ethernet (eth0) so you can keep it or replace it.

auto lo
iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp
wpa-ssid "ssid"
wpa-psk "password"

After your file looks like this, hit Ctrl-X, then y for yes and enter.
I usually reboot at this point with a command of:

sudo reboot

Note: If something happens and you can’t log onto your wifi network, don’t despair. Just hook up your monitor and keyboard and go back to this file, change it back or rename your backup file to interfaces and you are back where you started. To change back to your original interfaces file that we renamed in step #2, just type this on the command line.

sudo cp /etc/network/intefaces-wifi /etc/network/interfaces

When finished doing this, reboot again.

sudo reboot

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

 


 

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.