Raspberry and ROS

From Rsewiki
(Difference between revisions)
Jump to: navigation, search
(Autostart ROSCORE and bridge)
(Robobot from SVN)
Line 165: Line 165:
 
  ln -s svn/regbot/regbot_gui
 
  ln -s svn/regbot/regbot_gui
 
  ln -s svn/fejemis/ROS/catkin_ws
 
  ln -s svn/fejemis/ROS/catkin_ws
 +
 +
=== Teensy firmware compile ===
 +
 +
Download Arduino from https://www.arduino.cc/ ; find the software and download version 1.8.19 for Linux arm 32 bit.
 +
 +
Download also TeensyduinoInstall.linuxarm and 00-teensy.rules from https://www.pjrc.com/teensy/td_download.html - again the arm 32 bit version
 +
 +
Assuming these files end in the Downloads directory, then
 +
 +
cd
 +
cd Downloads
 +
tar -zf arduino-1.8.19-linuxarm.tar.xz
 +
 +
Arduino is now ready to run, but we need the Teensy addition, so:
 +
 +
sudo cp 00-teensy.rules /etc/udev/rules.d/
 +
chmod +x TeensyduinoInstall.linuxarm
 +
./TeensyduinoInstall.linuxarm
 +
 +
This should start the Teensyduino installer, guide the installation to the Arduino.1.8.19 just unpacked and install all packages.
 +
 +
We need some extra packages; we put them in a new 'git' directory:
 +
 +
cd
 +
mkdir git
 +
git clone https://github.com/adafruit/Adafruit_SSD1306.git
 +
git clone https://github.com/adafruit/Adafruit-GFX-Library.git
 +
git clone https://github.com/adafruit/Adafruit_BusIO.git
 +
 +
Next, these libraries need to be put where the Makefile looks for them, so link as follows:
 +
 +
cd
 +
cd Downloads/arduino-1.8.19/hardware/teensy/avr/libraries
 +
ln -s ~/git/Adafruit-GFX-Library
 +
ln -s ~/git/Adafruit_SSD1306
 +
ln -s ~/git/Adafruit_BusIO
 +
 +
To tell the Regbot code where the libraries and tools are found make even more links:
 +
 +
cd
 +
cd svn/regbot/regbot
 +
ln -s /home/local/Downloads/arduino-1.8.19/hardware/teensy/avr/libraries
 +
ln -s /home/local/Downloads/arduino-1.8.19/hardware/teensy/avr/cores/teensy3
 +
ln -s /home/local/Downloads/arduino-1.8.19/hardware/teensy/avr/cores/teensy4
 +
ln -s /home/local/Downloads/arduino-1.8.19/hardware/tools
 +
ln -s tools/teensy
 +
 +
Now it should be possible to compile the Teensy firmware.
 +
It is a Teensy 4.1, so:
 +
 +
cd 4.1
 +
make -j3
 +
 +
The option '-j3' tells the raspberry to use 3 CPU cores, it is faster, but eats memory and heats up the CPU. If that seems to be a problem, then use a lower number.
 +
 +
To install the newly compiled regbot.hex:
 +
 +
'''Press the (red) power button on the Regboard board (to maintain power while the processor is reprogrammed)'''
 +
make upload
  
 
=== Initialize the ROS environment ===
 
=== Initialize the ROS environment ===

Revision as of 15:12, 20 January 2023

Back to Robobot

Contents

Installation from blank SD-flash

Install Raspberry

Use Raspberry pi imager (download from https://www.raspberrypi.com/software/)

rpi-imager

First configure settings: click the gear icon, and set:

  • enable ssh, hostname, English language, Danish keyboard, possibly SSID, time zone, username (local) and password (remember to spell the password correctly).

then

Select operating system 'Raspberry Pi OS lite' and storage, an empty SD-flash of at least 16GB, then write.

When finished, mount the SD into the Raspberry

Start Raspberry

If everything is configured as above, then you just need to figure out the IP.

else

You need a screen and keyboard. Connect to the network to get an IP and for updating and date/time.

Find your IP address using:

sudo apt install net-tools nmap
ifconfig

Or from another computer on the same local net (if your local net is 192.168.2.XX)

nmap -sP 192.168.2.0/24

Wifi connect

The Raspberry uses the configuration in

cd /etc/wpa_supplicant
sudo nano wpa_supplicant.conf

@todo how to setup - copy from old installguide?

SSH from another computer

If the Raspberry has an IP of 192.168.2.39, then:

ssh local@192.168.2.39

or

ssh -X local@192.168.2.39

If your computer support X-graphics, e.g. has X-ming installed

Putty or other tools could be used too.

Install tools

Install subversion and other tools

Note: if you are on DTU network, then the date on the Raspberry will most likely not be set correct, and that may give problems for updating the operating system. If so you may need to install NTP and NTPDATE first and then configure /etc/ntpconf as described below.

ntp               # time setup
ntpdate           # time setup from DTU net
libreadline-dev   # command line memory
libopencv-dev     # openCV
python3-pyqtgraph # fancy graphs in Python
python3-scipy     # scientific functions 
pyqt5-dev         # QT designed GUI
pyqt5-dev-tools   # design QT GUI
festival          # text to sound
sox               # sound format read/write
libsox-fmt-all    # formats for SOX
v4l-utils         # video utilities
apt-file          # for finding missing system files (optional)
qv4l2             # for testing camera (optional)
kate              # graphical editor (optional - nano is faster)
xinit             # to run server (graphical user interface)
cmake             # to build apps
pip               # Python package install
sudo apt update
sudo apt dist-upgrade
sudo apt install ntp ntpdate libreadline-dev subversion libopencv-dev python3-pyqtgraph python3-scipy pyqt5-dev pyqt5-dev-tools festival sox libsox-fmt-all apt-file kate qv4l2 v4l-utils xinit cmake pip

NTP when on DTU net

Network time protocol (NTP), to keep clocks in sync. At DTU most clock sources are blocked, the clock source needs to be configured.

At DTU, edit /etc/ntp.conf, add ntp.ait.du.dk to the NTP server pool, like:

...
# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
pool ntp.ait.dtu.dk
pool 0.ubuntu.pool.ntp.org iburst
...

This should ensure a proper date on a DTU net and when the internet is available elsewhere.

Sync time (if on DTU net)

sudo ntpdate -u ntp.ait.dtu.dk
date

Install ROS base

I will use Noetic (if it is ethical to do so).

Follow the instructions at http://wiki.ros.org/noetic/Installation/Ubuntu like this:

Setup your computer to accept software from packages.ros.org.

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

Set up your keys

curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -

Update package list with the new source

sudo apt update

but it may fail with "The repository 'http://packages.ros.org/ros/ubuntu jammy Release' does not have a Release file."

The repository adds a file /etc/apt/sources.list.d/ros-latest.list. Modify the line in that file to include [trusted=yes], like:

sudo nano /etc/apt/sources.list.d/ros-latest.list
deb [trusted=yes] http://packages.ros.org/ros/ubuntu bullseye main

Then redo the (a few failed to fetch is OK)

sudo apt update

Install ros-desktop-full-dev or ros-desktop-full and a bit more to use a Catkin workspace:

sudo apt install ros-desktop-full python3-rosinstall libmap-msgs-dev

Robobot from SVN

Install the needed Regbot and Fejemis packages. Fejemis is for the bridge, which also is a ROS bridge. Regbot is for the firmware, and the user interface used for the sensor calibration.

We will install these packages in an 'svn' directory, and make an easy link to the relevant parts.

mkdir cvn
cd svn
svn checkout svn://repos.gbar.dtu.dk/jcan/fejemis
svn checkout svn://repos.gbar.dtu.dk/jcan/regbot
svn checkout svn://repos.gbar.dtu.dk/jcan/robobot

and then the links

cd
ln -s svn/regbot/regbot_gui
ln -s svn/fejemis/ROS/catkin_ws

Teensy firmware compile

Download Arduino from https://www.arduino.cc/ ; find the software and download version 1.8.19 for Linux arm 32 bit.

Download also TeensyduinoInstall.linuxarm and 00-teensy.rules from https://www.pjrc.com/teensy/td_download.html - again the arm 32 bit version

Assuming these files end in the Downloads directory, then

cd
cd Downloads
tar -zf arduino-1.8.19-linuxarm.tar.xz

Arduino is now ready to run, but we need the Teensy addition, so:

sudo cp 00-teensy.rules /etc/udev/rules.d/
chmod +x TeensyduinoInstall.linuxarm
./TeensyduinoInstall.linuxarm

This should start the Teensyduino installer, guide the installation to the Arduino.1.8.19 just unpacked and install all packages.

We need some extra packages; we put them in a new 'git' directory:

cd
mkdir git
git clone https://github.com/adafruit/Adafruit_SSD1306.git
git clone https://github.com/adafruit/Adafruit-GFX-Library.git
git clone https://github.com/adafruit/Adafruit_BusIO.git

Next, these libraries need to be put where the Makefile looks for them, so link as follows:

cd
cd Downloads/arduino-1.8.19/hardware/teensy/avr/libraries
ln -s ~/git/Adafruit-GFX-Library
ln -s ~/git/Adafruit_SSD1306
ln -s ~/git/Adafruit_BusIO

To tell the Regbot code where the libraries and tools are found make even more links:

cd
cd svn/regbot/regbot
ln -s /home/local/Downloads/arduino-1.8.19/hardware/teensy/avr/libraries
ln -s /home/local/Downloads/arduino-1.8.19/hardware/teensy/avr/cores/teensy3
ln -s /home/local/Downloads/arduino-1.8.19/hardware/teensy/avr/cores/teensy4
ln -s /home/local/Downloads/arduino-1.8.19/hardware/tools
ln -s tools/teensy

Now it should be possible to compile the Teensy firmware. It is a Teensy 4.1, so:

cd 4.1
make -j3

The option '-j3' tells the raspberry to use 3 CPU cores, it is faster, but eats memory and heats up the CPU. If that seems to be a problem, then use a lower number.

To install the newly compiled regbot.hex:

Press the (red) power button on the Regboard board (to maintain power while the processor is reprogrammed)

make upload

Initialize the ROS environment

Initialize sets up the needed environment variables and makes a script for remaining settings for this project.

cd ~/catkin_ws
rosws init . /usr/share

This outputs a message about the location of the ROS setup script:

rosinstall update complete.
Type 'source /home/local/svn/fejemis/ROS/catkin_ws/setup.bash' to change into this environment. 
Add that source command to the bottom of your ~/.bashrc to set it up every time you log in.

Put this script into ~/.bashrc, e.g. by

echo "source /home/local/svn/fejemis/ROS/catkin_ws/setup.bash" >> ~/.bashrc

Run catkin_make in the catkin_ws directory

cd ~/catkin_ws
catkin_make

Autostart ROSCORE and bridge

Link the startup script to the home directory of user 'local' as well as a link to the bridge executable and the initialization-file used by the bridge.

cd
ln -s svn/robobot/setup/start_bridge.sh
ln -s catkin_ws/devel/lib/bridge/bridge
ln -s svn/robobot/setup/bridge.ini

This script starts roscore and the bridge in this order.

Add the script to autostart at boot:

crontab -e

Select an editor; if asked, I have selected 'nano' (an ok simple editor) In the editor, add this line:

@reboot /home/local/start_bridge.sh

End with ctrl-s to save and ctrl-x to exit (if nano is the editor)

For info: the start script is executed as user 'local' and has the following content:

#!/bin/bash
# start roscore and bridge
# this script is added as a root cronjob
# to see and edit the job
# $ crontab -e
#
cd /home/local/
date >> rebootinfo.txt
/usr/bin/roscore &
# wait for ROSCORE to start
sleep 8    
#start the bridge (as a daemon)
./bridge -d  &
echo "Bridge started with PID:" >> rebootinfo.txt
sleep 1
pgrep -l bridge >> rebootinfo.txt
exit 0

Reboot

sudo reboot now

Reenter

ssh -X local@<IP>

If all goes well, then the 'rebootinfo.txt' should end with something like this:

Sun 27 Nov 13:03:52 CET 2022
Bridge started with PID:
426 start_bridge.sh
617 bridge

If not you may see what cronjob is executed by:

grep CRON /var/log/syslog

Clone the just installed image

Use SD card clone/copier (on Raspberry??)

- rpi-clone script should work (not tested).

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox