note 2 BeagleBone Black:building OpenROV software with Angstrom

August 9, 2013

I decided to try to get the OpenROV software working using the demo Angstrom distribution that comes installed in the BBB since it has a lot of the needed packages already installed and you don’t need an Ubuntu SD image.   There are 13 installation steps in the OpenROV/openrov-software/Readme.md file shown here.  I skipped step 1 since I am using Angstrom.  I postponed Step 2 for later if I get everything else working.

Step 3

upgrade software and install rerequisits (holy moly, there’re packages!):

sudo apt-get update
sudo apt-get install g++ curl pkg-config libv4l-dev libjpeg-dev build-essential libssl-dev vim cmake

I verified that most of the required packages were already installed and found only “build-essentials” missing from Angstrom.  Those that were installed were updated with opkg.

build-essentials was not found in searching Angstrom opkg.   However,  I did find packagegroup-core-buildessential-dev 1.0-r0.1 .  I installed this with opkg and seemed to work.

Installing SUDO:

Using opkg search I couldn’t find  a sudo package.  I did find an Angstrom dev package for sudo and installed that by downloading it to my computer from here and copying it to the BBB root.   I then used

root:/# opkg install ./sudo_1.8.4p4-r1_armv7a.ipk

The program unzipped the ipk package and successfully installed  sudo.

Step 4:

Install nvm (Node Version Manager):

git clone git://github.com/creationix/nvm.git ~/.nvm
echo ". ~/.nvm/nvm.sh" >> .bashrc
echo "export LD_LIBRARY_PATH=/usr/local/lib" >> .bashrc
echo "export PATH=$PATH:/opt/node/bin" >> .bashrc

And make those changes work now:

source ~/.bashrc

I followed these instructions and tried to install node v0.8.11 as per Steps 5 thru 7  but ran into a missing Python compiler.ast error so I opkg updated the Python compiler and then things worked.   Since Angstrom has v0.8.2 node installed already, I don’t think it is necessary to install v0.8.11 but I have yet to try this.

No /opt/ directory

It seems that my Angstrom dist doesn’t have an opt directory and I am not sure why since it is standard in the LInux directory tree.  Also many of the paths in OpenROV software assume it is populated.   My solution was to create the directory.   Later I would install OpenROV software into it.

Step 8

Install mjpg-streamer

Download mjpg-stream:

 wget http://downloads.sourceforge.net/project/mjpg-streamer/mjpg-streamer/Sourcecode/mjpg-streamer-r63.tar.gz

Prepare mjpg-streamer for make:

tar zxf mjpg-streamer-r63.tar.gz
cd mjpg-streamer-r63.tar.gz

Make and install OpenCV:

make && sudo make install

The r63.tar.gz package would not install because of  fatal error: videodev.h No such file or directory .   Apparently it uses videodev.h instead of videodev2.h which is in more recent library distributions of Linux..at least in my version of Angstrom.  I tried to fix it by just changing all the videodev.h to videodev2.h in all the source files that need it.  I got it to compile through most of the files but ran into some other problem which I don’t recall right now.   So I gave up and found a more recent version of mjpg-streamer on the github.com site that uses vidodev2.h.  You can download this from Dominik’s codewithpassion site as “mjpg-streamer or the sourceforge site that it is branched from.  You know you have the right version if mjpg_streamer.c has <linux/vidoedev2.h>.

I actually installed mjpeg-streamer-experimental in /root rather than /~ and tested it standalone and it seems to work fine with Chrome except there is about .5 second delay in the image.  I understand that the delay is roughly .2 to .3 seconds with Firefox browser but I didn’t try it.

Step 9 Download OpenROV ROVision:

cd ~
git clone git://github.com/OpenROV/openrov-software.git
cd openrov-software/

Change to development branch:

git checkout development

edit ~/.bashrc, add:

export LD_LIBRARY_PATH=/usr/local/lib

You’ll need to restart your shell:

source ~/.bashrc

Git OpenROV-software

Ok I did all this but I could not checkout development branch…it said that it didn’t exist.  I decided to use Dominiks codewithpassion/OPENROV code since it probably was more recent and also had a development branch which I checked out to 599ROV branch.

git clone git://github.com/codewithpassion/openrov-software/

git checkout remote/origin/development -b 599ROV

Step 10

Download modules:

npm install express socket.io serialport

Completed this step ok and had enough modules to start testing.  I did this from root directory.

Preliminary tests:

Restarted shell with

source  ~/.bashrc

node app

and got error that “forever-monitor’ module could not be found.   This is located in node.   I fixed this by reinstalling node in root rather than home.  The is is because the openrov software is now installed in /opt  I think.

Cockpit display now works and includes the Genius camera image!!

The next note will be on getting the Arduino firmware loaded to the OPENROV Cape.


 


Note 3 Beaglebone Black: Getting OpenROV software to load .hex file into Arduino

August 7, 2013

I tried to upload a new Arduino program to the OpenROV cape using the software routines and the procedure outlined here.   On the cockpit display you select setup and then select a program to upload.   This program is a tar or zip compression of the Arduino source files.   The tar file is automatically expanded and then an attempt is made to build the hex file required by the Cape Arduino processor for upload.   The program threw an error which I traced to Arduino “ino” command line toolkit  program not being installed on the BBB.   I attempted to load ino onto the BBB as described here but that failed since a setuptool file for Python was missing.   This was installed  using

cd /

opkg install python-setuptools

Next, I reran  /ino/make install and now it couldn’t find the file py.compile.  This file apparenty is used in later versions of Python.  Searching opkg angstrom packages I found  python-compile_2.7.2-r3.17_armv7a.ipk\ which was downloaded to my pc and ssh to BBB.  I then used opkg service to install  it:

cd /

opkg install python-compile_2.7.2-r3.17_armv7a.ipk

ino seemed to be installed without errors.  Now tried to upload an Arduino file and of course more problems arose.  Seems that the ino makefile puts some of ino Python libraries in the wrong folder and when the ino calls were made several library functions were not found.    A search showed up this post which discussed the libraries and one of the comments to the post said that installing ino with Python commands works.  So I reinstalled ino using

cd /ino

python setup.py install

At last success!!   I ran another upload and got a little further until more errors showed up.    Here is the log file output:

Received ‘arduinofirmware-startupload’ for file: OpenROV_arduino.zip file: undefined going to install the uploaded file: OpenROV_arduino.zip unpack: build dir is /tmp/tmp.klu0me4aEo

Archive:  /opt/openrov/src/temp/OpenROV_arduino.zip    creating: OpenROV/   inflating: OpenROV/Command.cpp   inflating: OpenROV/Command.h   inflating: OpenROV/Device.cpp   inflating: OpenROV/Device.h   inflating: OpenROV/Motors.cpp   inflating: OpenROV/Motors.h   inflating: OpenROV/OpenROV.ino   inflating: OpenROV/Timer.cpp   inflating: OpenROV/Timer.h

unziped /opt/openrov/src/temp/OpenROV_arduino.zip in /tmp/tmp.klu0me4aEo/src

Unpacked firmware file into Searching for Board description file (boards.txt) … FAILED Board description file (boards.txt) not found. Searched in following places:   – /usr/local/share/arduino/hardware/arduino   – /usr/share/arduino/hardware/arduino

Compiled firmware in directory Closing serial connection for firmware upload Setting up uploader

Searching for Board description file (boards.txt) … FAILED Board description file (boards.txt) not found. Searched in following places:   – /usr/local/share/arduino/hardware/arduino   – /usr/share/arduino/hardware/arduino

Initiating arduino reset

/opt/openrov/linux/reset.sh: line 18: /sys/kernel/debug/omap_mux/gpmc_ad0: No such file or directory

upload failed, trying again. Searching for Board description file (boards.txt) … FAILED Board description file (boards.txt) not found. Searched in following places: – /usr/local/share/arduino/hardware/arduino – /usr/sh are/arduino/hardware/arduino

Initiating arduino reset

So it can’t find the board description and it is missing sys/kernel/debug/omap_mux/gpmc_ad0.   Back later when I figure this out.

 Ok… I’m back.   The missing board .txt file indicates that I need to install the Arduino IDE.   Normally ino uses AVERDUDE to boot up files to the Arduino but this is not installed on BBB.  I I tried to opkg averdude but Angstrom doesn’t have that .  However, all these files are in the Arduino IDE.  So I downloaded the  linux Arduino .tgz from here and ssh it to my root. Then installed this way

cd /usr/share

tar -xzf /arduino-1.0.5-linux32.tgz

Cool, now I have board.txt and averdude.

 

I fixed the gpmc_ad0 error by updating rc.local to make use of the .dt0 file overlay files supplied with Angstrom for BBB which are located in /lib/firmware.   Basically, I commented any reference to omap_mux and add code to set up UART1.  I will write a more detailed post on how to do this.

Using .hex file instead of .tar file of source

Why not build the .tar file on the host PC and then ask the OpenROV software to just upload the .hex file to the Arduino?   First, it took me a while to find where the Arduino puts the IDE.  Some said that holding the shift key down while compiling will show the file.   This didn’t seem to work so I just searched for the project name in temp files and found my .hex program in this build directory.

C:\Users\vamfun\AppData\Local\Temp\build802015884711230598.tmp

Next I will work on how to make the OpenROV uploader use the file in .hex format rather than the expected .tar format.  You still need ino installed to do the hex file upload.  But it could save a few steps in the overall upload procedure.


Getting my feet wet with Arduino Uno

July 18, 2013

Arduino Uno

I have tried to stay away from Arduino mainly because I didn’t want to learn a whole new culture. However, my AlgalitaROV project uses the OPENROV electronic architecture which employs a Cape that uses the Arduino Uno processor which in turn attaches to a BeagleBone Black(rats…another processor culture to learn).
Downloaded and installed the Arduino SDK 1.0.5 from arduino.cc and read through the getting started and reviewed the types of commands it uses. I bought a Arduino Uno starter kit from amazon ($32) which has a breadboard and some jumper wires. plugged in the Arduino Uno and it installed automatically without updating the drivers as suggested in the instructions. First observations:

1) the general purpose I/O (GPIO) are 5 volt at the breakouts. This is great since it is compatible with Vex parts. Current is o limited to 40ma per pin.

2) it can be powered from the USB cable or an external supply that must range from 6v to 20v with a recommendation of 7v to 12v.

3) Software wise in the Arduino you write a void setup() function and a void loop() function. These functions are called automatically by the operating system. setup() runs once and the loop() runs continuously…meaning the hidden main() function contains a while(true){loop()} structure that runs after the setup() runs. By contrast the Vex RobotC template calls a function pre_autonomous() once and executes separate tasks autonomous() and usercontrol(). usercontrol contains an explicit while(true){} which the programmer can change. Not sure that Arduino gives us that capability.

3)There are plenty of software examples and the language is close to C. The only function that seemed misnamed was analogWrite(pin,duty). This doesn’t write an analog output to a d/a hardware as one might assume but puts a 5 volt PWM signal output on a PWM capable GPIO pins. On the Uno 6 of the 14 GPIO pins are PWM capable (3,5,6,9,10,11). Not sure why they didn’t just call it PWMWrite().

4)Servo library is available for use but be careful with servo.write(int val).

Here is the function code from the servo library.  Note that if val is >544 then the command is assumed to be in microseconds rather than servo degrees.  Also note if it is less than 544 that the degree values are truncated to valid servo range of [0,180].    So a val = 255 will produce a 180 degree command.

void Servo::write(int value)
{
  if(value < MIN_PULSE_WIDTH)
  {  // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
    if(value < 0) value = 0;
    if(value > 180) value = 180;
    value = map(value, 0, 180, SERVO_MIN(),  SERVO_MAX());
  }
  this->writeMicroseconds(value);
}

First Script.
We need an r/c brushless motor driver. The ESC needs a standard servo drive signal. So I hooked up a Vex pot to the board and read its value [0, 1023] and scaled it to [0,180] which is given to a canned servo program object which has a servo.write which generates the proper servo output to a specified pin.  A motor is a continuous rotation servo  so 0 value represents max reverse speed and 180 value gives max forward speed.   I also included a serial printout of the value to the laptop console.
Hardware Setup:
[click on picture to expand to full size]

Shows breadboard wiring , motor 7.2v battery and external board 5 volt power supply

Shows breadboard wiring , motor 7.2v battery and external board 5 volt power supply

It is important to note that the motor is powered by a separate battery since it draws more current than the board can supply.

Closeup of arduino wiring

Closeup of arduino wiring

Full test setup

Full test setup

Mymotorcontrol.ino

// Controlling a servo/motor position using a potentiometer (variable resistor) 
// by Chris Siegert:  vamfun@yahoo.com   https://vamfun.wordpress.com
// adapted from  Michal Rinott servo code  
// connect the center pin of a potentiometer (pot) to the potpin.  Connect the other two pins to the arduino 5v and ground pins.
// connect the white wire of the motor pwm cable to the servopin.  
// Important!! Connect the red and black wires to an external motor power source. 
// The arduino is not designed to deliver enough current to drive a servo/motor.
#include <Servo.h> 

Servo myservo;  // create servo object to control a servo or motor. 
int servopin = 9; //connects servo to pin 9 which is a pwm pin.
int potpin = 0;  // analog pin A0 used to connect the potentiometer
int val;    // variable to read the value from the analog pin 
int cmd = 0; // cmd to motor [0 to 180]
int cnt = 0; // program cycle counter 
int cnt_max = 33;   // this is the number of delay cycles between serial printouts. (15ms per cnt) 33 counts gives about 2 per second)  
void setup() 
{ 
  Serial.begin(9600);   //start up the serial data port at 9600 baud 
  myservo.attach(servopin);  // attaches the servo on servopin number to the servo object void loop() 
{ 
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
  cmd = map(val, 0, 1023, 0, 180);     // scale it in degrees of servo rotation(value between 0 and 180) 

  myservo.write(cmd);                  // sets the servo position according to the scaled value in deg 
  cnt++; 
  if(cnt > cnt_max)                  // this sets time between serial print outs to cnt_max cycles  or about (15 ms*cnt_max)
  {
    Serial.println(cmd);  
    cnt = 0;      // debug value
  }
  delay(15);                           // waits for the servo to get there 
}