OpenROV Cape Test Program (No Beaglebone required)

November 30, 2013

I decided to modify the OpenROV 2.4 Arduino source code to create an automatic test program that stimulates each of the cape outputs periodically to see if the Arduino ATmega328 chip and connecting circuitry are operating correctly.  Software has been tested with the cape operating  stand alone.  Hopefully it will run in a OpenROV cape with a Beaglebone attached provided the cape.(TBD)

Hardware Requirements:

OpenROV cape

Servo

LED lights

Battery Pack (12v)

ATmega328 programmer (Arduino Uno will do)

Proceedure:

1) Remove the ATmeta328 chip from the Cape and use an Arduino board to load the Openrov_cape_test.ino with includes.

2)Place the ATmega328 chip back into the Cape and hook up the externals (motors, servo and lights) .

3) Connect the battery power to the Cape. (Typically 12v)

4) Watch motors , servo and light cycle periodically in sequence. Each command level lasts for 2 seconds.

20131130-171808.jpg

Software Files: Download OpenROV_cape_test  folder from my dropbox. In it you will find the following OpenRov_cape_test.ino file.   Just use it instead of OpenRov.ino file.

/* OpenROV_cape_test  Written by Chris Siegert, 11.30.13 , vamfun@yahoo.com, https://vamfun.wordpress.com This program is designed to test the OpenROV Cape.  Program generates commands that cycles motors, tilt servo and lights sequentially.  No Beaglebone is required for the test. Power the cape using the battery input terminals and connect the output devices. All motors are cycled simultaneously with 2 second steps at magnitudes {135,90,45,90}. Motors are left in reset mode. Next the servo is commanded to {170,10,90}Basically full tilt up to full tilt down and back to neutral. The light goes to full brihtness then to half brightness and then off. The device sequencing is then repeated continuously. If running without the Beaglebone, load the sketch and its includes into the ATmega chip using an Arduino project board or programmer.  Then reinsert the chip back into the cape.   If running with the Beaglebone, one might be able to just upload the program using the OPENROV cockpit utility. */

#include <Servo.h>

#include <Arduino.h>

#include “Motors.h”

#include “Command.h”

#include “Device.h”

#include “Timer.h”

Motors motors(9, 10, 11);

Command cmd;

Device vout(“vout”, 0, vout.analog, vout.in);

Device light(“light”, 5, light.analog, light.out);

Timer time;

Servo tilt;   int array[MAX_ARGS];

int case_no=1;   void setup(){

Serial.begin(9600);

pinMode(13, OUTPUT);

tilt.attach(3);

motors.reset();

light.write(0);

time.reset();

delay(3000);//wait for ESC to calibrate }

void loop(){

switch ( case_no)   {

case 1:

Serial.print(“motor”);

Serial.print(”  mag = “);

Serial.println(135);

motors.go(135,135,135);

delay(2000); //cds  set step delay

Serial.print(“motor”);

Serial.print(”  mag = “);

Serial.println(“90”);

motors.go(90,90,90);

delay(2000);

Serial.print(“motor”);

Serial.print(”  mag = “);

Serial.println(“45”);

motors.go(45,45,45);

delay(2000);

Serial.print(“motor”);

Serial.print(”  mag = “);

Serial.println(“90”);

Serial.println();    //motors.reset();

motors.go(90,90,90);

case_no++;

break;

case 2:

Serial.print(“servo” );

Serial.print(”  mag = “);

Serial.println(“170”);

tilt.write(170);

delay(2000);

tilt.write(90);

Serial.print(“servo” );

Serial.print(”  mag = “);

Serial.println(“90”);

delay(2000);

Serial.print(“servo” );

Serial.print(”  mag = “);

Serial.println(“10”);

tilt.write(10);

delay(2000);

Serial.print(“servo” );

Serial.print(”  mag = “);

Serial.println(“90”);

Serial.println();

tilt.write(90);

case_no++;

break;

case 3:

Serial.print(“light” );

Serial.print(”  mag = “);

Serial.println(255);

light.write(255);

delay(2000);

Serial.print(“light” );

Serial.print(”  mag = “);

Serial.println(128);

light.write(128);

delay(2000);

Serial.print(“light” );

Serial.print(”  mag = “);

Serial.println(0);

Serial.println();

light.write(0);

case_no++;

break;

default:

case_no = 1;  //repeat sequence

} //end switch

}


Note 6 BBB: Creating OPENROV image with Virtualbox (problems still)

October 28, 2013

I followed the procedure   to use the Virtualbox /Vagrant approach to generate an OPENROV image.   I am really enthusiastic about the fact that I can run Linux easily on my Toshiba Win 7 machine.

Fixing the number of processors

The first problem I ran into was the Vagrantfile in the openrov-image-master GIT repository has a default of 2 cpu’s for the Virtualbox.    My Toshiba Satellite L655 intel processor doesn’t have hardware virtualization (VT-x) capability available in the bios.   The default value of 2 processors  requires VT-x.   I fixed this by editing the Vagrantfile to use 1 cpu and at least got ubuntu installed.  Here is the new Vagrantfile:

code:

# -*- mode: ruby -*- # vi: set ft=ruby :

Vagrant.configure(“2”) do |config|  

# All Vagrant configuration is done here. The most common configuration  

# options are documented and commented below. For a complete reference,  

# please see the online documentation at vagrantup.com.   config.vm.box = “ubuntu-12.04-32bit”   config.vm.box_url = “http://files.vagrantup.com/precise32.box”   config.vm.provision :shell, :path => “build.sh”

config.vm.provider :virtualbox do |vb|          

vb.customize [“modifyvm”, :id, “–ioapic”, “on”]     

vb.customize [“modifyvm”, :id, “–memory”, “2048”]     

# you cannot use more than one cpu unless you have hardware virtualization. So for my Toshiba laptop I have no VT-x in BIOS   

vb.customize [“modifyvm”, :id, “–hwvirtex”, “off”]     

#vb.customize [“modifyvm”, :id, “–cpus”, “2”]

end

end

end code:

Use Chrome over IE

Problem with IE downloading ubuntu-saucy-console-armhf-2013-09-26.tar.xz  .   Apparently IE creates a tar out of this that must be unzipped.   PEA zip gave an index out off range error and I could not unzip the file.   Used google Chrome and worked ok.     I added the file to the Vagrantfile.

Logging in

I used putty to SSH into the Virtualbox.

User: vagrant

Password: vagrant    (It took me a while to discover this!!)

When ubuntu boots it goes to the home directory.

First thing is to change the directory to  /vagrant and list the directory since this has the build script.

Welcome to your Vagrant-built virtual machine.
Last login: Fri Sep 14 06:22:31 2012 from 10.0.2.2
vagrant@precise32:~$ cd /vagrant
vagrant@precise32:/vagrant$ ls
]             lib
build.sh      putty info 10.24.txt
CHANGELOG.md  README.md
cleanup.sh    ubuntu-saucy-console-armhf-2013-09-26.tar.xz
contrib       Vagrantfile
FETCH_HEAD

I list the directory using “ls” command and then copy the long name of the .tar.xz file and use it in the build command
vagrant@precise32:/vagrant$ sudo ./build.sh ubuntu-saucy-console-armhf-2013-09-26.tar.xz –black

When running build.sh be sure to add the processor type  as a second argument.  For me this is “–black”.

Updating Ubuntu

The next error was the need to install some missing tool packages.  I  wrote a shell script that is called in the Vagrantfile to load boot tools, git, nodejs,npm qemu-user-static,cross compiler etc.  Here is the script update.sh:

#!/bin/bash

echo “updating ubuntu with nodejs,crosscompilers ,git,qemu-static etc”

sudo apt-get update

sudo apt-get install -y dosfstools git-core kpartx u-boot-tools wget

sudo apt-get install -y nodejs nodejs-dev npm

sudo apt-get install -y debootstrap qemu-user-static qemu-system git

sudo apt-get install -y g++-4.6-arm-linux-gnueabihf

#end script

 update.sh is called in the Vagrantfile by adding a provisioner statement

config.vm.provision :shell, :path => “update.sh” 

Build Errors

Currently I still am getting some build errors related to unsuccessful mounts and failure to make some directories:

mount: wrong fs type, bad option, bad superblock on /dev/mapper/loop0p1,

and

mount: mount point /vagrant/root/dev/ does not exist

mount: mount point /vagrant/root/proc/ does not exist

mount: mount point /vagrant/root/sys/ does not exist

mount: mount point /vagrant/root/run/ does not exist

mount: mount point /vagrant/root/etc/resolv.conf does not exist

cp: cannot create regular file `/vagrant/root/usr/bin/’: No such file or directory

mkdir: cannot create directory `/vagrant/root/tmp/work/’: No such file or directory

Here are more complete debug files

installation debug printout

dmesg and partd printouts

Anyone have some ideas??


note 1 Beaglebone Black: Boot attempt using OPENROV image

August 9, 2013

As mentioned in my last Arduino post, the 599 Algilita ROV team selected the OPENROV processing architecture for their ROV.   It was hoped that this would save us a lot of time setting up the cockpit display software which is already working on OPENROV.   Ha…think again.   Unfortunately, the OPENROV flash image which works so nice in the Beaglebone doesn’t seem to boot with the Beaglebone Black (BBB), at least for me.

Flashing the OPENROV image to BBB (unsuccessful)

The BBB uses a built-in eMMC to boot from normally.   To flash a new image you insert a micro SD MMC and while holding down the User (boot) button on the BBB you power up the board either by USB or 5v power supply.  Continue to hold the button until the user LED’s begin to blink (See flashing procedure),  The BBB board is then boots up and transfers the image from the micro SD to the built-in eMMC.

I made a bootable 8GB micro SD card using the Windows solution outlined in the Getting Started link  github.com/OpenROV/openrov-image.   I held the boot button down, powered up and waited for over 5 minutes for the user LED’s to light, but only the power LED lit.

I searched the forums and only found one comment re the BBB not being able to flash the OPENROV-image.  Apparently some modifications need to be made to the uSD 64K partition that contains a file called

I did check that I could flash something by starting with a fresh Angstrom image and booted that ok.


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 
}