Documentation for Cablebot v2Link
Cablebot HardwareLink
The cablebot uses two Raspberry Pis, one for the base station and one for the camera.
The PI's should be running the the 64-bit version of Raspberry Pi OS Lite.
The user "romi" should be configured on both devices. All the software will be installed in the home directory of the romi user, /home/romi.
Cablebot SoftwareLink
The software is part of the romi-rover-build-and-test repository. It consists of four separate applications that communicate with each other over websockets:
- rcom-registry: A directory service that keeps track of the addresses of the applications
- romi-config: A shared configuration service for the ROMI services
- romi-camera: The interface to the camera
- romi-cnc: The interface to any CNC device for the motion
- romi-cablebot: To program the execution of scans at defined times
Base stationLink
The following steps have to be taken on the Raspberry Pi that runs the base station:
- Install the required libraries
- Get the source code
- Compile the apps
- Compile the apps
- Install the Python library
- Copy the config file
- Start the apps
- Run the tests
Install the required librariesLink
$ sudo apt update
$ sudo apt install libi2c-dev libjpeg-dev
For libjpeg, one of the alternatives, such as libjpeg-turbo, should work also.
Get the source codeLink
To clone the romi-rover-build-and-test repo, do:
$ cd /home/romi
$ git clone --branch ci_dev --recurse-submodules https://github.com/romi/romi-rover-build-and-test.git
Compile the appsLink
To compile the apps: rcom-registry, romi-cnc, and romi-config:
$ cd romi-rover-build-and-test
$ mkdir build
$ cd build
$ cmake ..
$ make rcom-registry romi-config romi-cnc romi-cablebot
Install the Python libraryLink
$ cd /home/romi/romi-rover-build-and-test/librcom/python
$ pip install --editable .
$ cd /home/romi/romi-rover-build-and-test/python
$ pip install --editable .
Copy the config fileLink
$ cp /home/romi/romi-rover-build-and-test/config/cablebot-v2.json /home/romi/config.json
Start the appsLink
Open a terminal and start the RCOM directory service:
$ /home/romi/romi-rover-build-and-test/build/bin/rcom-registry
You should see something like:
Registry server running at 172.20.10.3:10101
Open a second terminal and start the config server:
$ /home/romi/romi-rover-build-and-test/build/bin/romi-config --config /home/romi/config.json
Open a third terminal and start the CNC:
$ /home/romi/romi-rover-build-and-test/build/bin/romi-cnc
You should see a bunch of messages, and also the path of the log file:
...
Changing log to '/tmp/romi/log.txt'
...
Finally, in a fourth terminal and start the Cablebot app:
$ /home/romi/romi-rover-build-and-test/build/bin/romi-cablebot
The Cablebot app is optional, actually. You'll find more info below.
Run the testsLink
In the Python directory, you'll find example code that you can use to test the services.
You can test the config interface, run:
$ cd /home/romi/romi-rover-build-and-test/python
$ python3 config.py
You can test the CNC interface as follows:
$ cd /home/romi/romi-rover-build-and-test/python
$ python3 cnc.py
Camera moduleLink
For the camera module, many of the steps are similar as above. In this case, we'll only compile the romi-camera app.
- Get the source code
- Compile the app
- Start the app
- Run the tests
Get the source codeLink
To clone the repo, do:
$ cd /home/romi
$ git clone --branch ci_dev --recurse-submodules https://github.com/romi/romi-rover-build-and-test.git
Compile romi-cameraLink
To compile romi-camera:
$ cd romi-rover-build-and-test
$ mkdir build
$ cd build
$ cmake ..
$ make romi-camera
Start the appLink
Open a terminal and run:
$ /home/romi/romi-rover-build-and-test/build/bin/romi-camera --config /home/romi/config.json --directory /home/romi
You should see a bunch of messages, and also the path of the log file:
...
Changing log to '/tmp/romi/log.txt'
...
You can always check that log file for more info.
In the terminal that runs rcom-registry, you should see (IP and port numbers will differ):
INFO: RegistryServer: Received message: {"request": "register", "topic": "camera", "address": "172.20.10.3:55229"}
INFO: RegistryServer: Register topic 'camera' at 172.20.10.3:55229
Run the testsLink
On the base station, you can test the camera interface through the Python API:
$ cd /home/romi/romi-rover-build-and-test/python
$ python3 camera.py
It should store 10 images on the disk, named camera-xxxx.jpg.
Installation on an Intel Linux PCLink
The software can also be compiled and tested on a regular PC running Linux.
First, install the dependencies:
$ sudo apt update
$ sudo apt install libi2c-dev libjpeg-dev vgrabbj
We'll suppose that the repository will be cloned in the directory HOME_ROMI. Then do the following.
$ cd $HOME_ROMI
$ cd romi-rover-build-and-test
$ mkdir build
$ cd build
$ cmake ..
$ make rcom-registry romi-config romi-cnc romi-camera
Install the Python library:
$ cd /home/romi/romi-rover-build-and-test/librcom/python
$ pip install --editable .
$ cd /home/romi/romi-rover-build-and-test/python
$ pip install --editable .
Edit the config file:
If you don't have an USB camera connected to the PC, you can configure a "fake" camera. In the config file, change the camera type to "fake-camera". Don't change anything else:
{
"camera": {
"type": "fake-camera"
}
}
The camera will serve an image with random noise.
If you don't have a CNC connected to the PC, you can configure a fake CNC in the config file. Change the "controller-classname" parameter to "fake-cnc-controller". Keep everything else unchanged.
{
"cnc": {
"controller-classname": "fake-cnc-controller"
}
}
Start the applications:
$ $HOME_ROMI/romi-rover-build-and-test/build/bin/rcom-registry &
$ $HOME_ROMI/romi-rover-build-and-test/build/bin/romi-config --config $HOME_ROMI/romi-rover-build-and-test/config/cablebot-v2-dev.json &
$ $HOME_ROMI/romi-rover-build-and-test/build/bin/romi-cnc &
$ $HOME_ROMI/romi-rover-build-and-test/build/bin/romi-camera &
$ $HOME_ROMI/romi-rover-build-and-test/build/bin/romi-cablebot &
Python script versus Cablebot appLink
There are two ways to work with the cablebot:
- Write you're own Python script
- Use the Cablebot app
Python scriptLink
You can use the Python API for the camera and the cnc to write your own scanning script. Below is an example that may be helpful.
import argparse
import time
from romi.cnc import CNC
from romi.camera import Camera
def startup_cnc(cnc):
# Turn off the battery charger
cnc.set_relay(0, True)
# Power-up the motor
cnc.power_up()
def scan(cnc, camera, x0, dx, count):
for i in range(count + 1):
x = x0 + i * dx
cnc.moveto(x, 0, 0, 0.75)
time.sleep(1)
image = camera.grab()
if image != None:
filename = f"cablebot-{i:05d}-{int(1000*x):05d}.jpg"
print(f"Saving {filename}")
image.save(filename)
def shutdown_cnc(cnc, no_homing):
if no_homing:
cnc.moveto(0.0, 0, 0, 0.75)
else:
# Return to 4 cm before the homing
cnc.moveto(0.04, 0, 0, 0.75)
cnc.homing()
cnc.power_down()
# Recharge the battery
cnc.set_relay(0, False)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--start', type=float, nargs='?', default=0.0,
help='The start position')
parser.add_argument('--interval', type=float, nargs='?', default=0.5,
help='The distance between camera positions')
parser.add_argument('--count', type=int, nargs='?', default="1",
help='The number of images')
parser.add_argument('--no-homing', action=argparse.BooleanOptionalAction,
help='Go back to zero without the homing procedure')
args = parser.parse_args()
cnc = CNC("cnc", "cnc")
camera = Camera("camera", "camera")
startup_cnc(cnc)
scan(cnc, camera, args.start, args.interval, args.count)
shutdown_cnc(cnc, args.no_homing)