Installation and Setup - shabaj-ahmed/SAR_for_habit_formation GitHub Wiki
Installation and set up
The following are instructions on how to replicate our study. If you would like to collaborate or need help setting up your own system please get in contact with me.
Hardware used
- Digital Dream Labs Vector 2.0,
- Raspberry Pi 5 8 GB,
- Micro SD card with Debian Bookworm installed,
- USB microphone,
- Mini External USB Stereo Speaker,
- Raspberry Pi touch display 2,
- 5V power supplies,
- TP-Link M7350 4G LTE Mobile Wi-Fi Router with pre-paid data only SIM
All devices were powered by the Raspberry Pi's USB ports
Prerequisites
Before running the project, ensure you have:
- 64-bit Debian Bookworm installed on your Raspberry Pi 5 (Vector SDK does not work on 32-bit RPi OS)
- Ensure that the Vector robot authentication certificate is located in the ~/.anki_vector directory and the sdk_config.ini is configured correctly.
- Create a .env file in the /configuration directory using the example.env as a template
- This project uses Google Cloud for Speech-to-Text (STT) recognition. We found its accuracy to be much better than that of local STT. To use this project as it is you will need to sign up for Google Cloud and create a project with speech-to-text. Retrieve the JSON API key and create the directory ~/.google-cloud to store it in. Add the file path to the Google API key to the .env file.
- Add the remaining hardware configuration properties to the .env file, such as network name amd location of brightness file.
Run Installation Script
The setup process is automated using a Bash script.
- Ensure Correct File Path set up the project in the following location:
~/Documents/hri_study
Or you will have to modify the bash script.
- clone the repository here using Open a terminal, navigate to the hri_study directory, and clone this repository.
cd ~/Documents/hri_study
git clone https://github.com/msahmed1/SAR_for_habit_formation.git
- Run the setup script Before running the bash.sh ensure that the prerequisites have are satisfied. Following this, navigate to the project root directory and make bash.sh executable before running it:
cd ~/Documents/hri_study/SAR_for_habit_formation
chmod +x bash.sh
./bash.sh
This script will:
- Pull the latest code from the repository (continuous deployment).
- Install and start the Mosquitto MQTT broker
- Create a Python virtual environment
- Install the required packages and dependencies
- Update the Vector SDK Library by updating the Protobuf files and parching broken code
- Launch all services
If successful, a chromium window should open in full-screen
Authenticate the vector robot
To connect a Vector robot using the Python SDK, you need to have the same authentication certificate as the Vecot to accept your request. If this program is being run on the same computer Wire Pod has been installed, then no other changes need to be made. Otherwise, you will need to copy the configuration file that was generated into the /home/.anki_vector/ file.
The following steps have been used to authenticate a vector robot on a Raspberry Pi 5 running Debian version: 12 (bookworm). Ensure you have a WiFi network with internet access that allows devices on the same network to communicate with each other. A university Eduroam network will not work for this. You will then need to install and set up Wire Pod, an open-source server for activating the vector robot. For ease of setup, here are the distilled instructions:
- Install and start WirePod Open the terminal on the Pi and run the following:
cd ~
git clone https://github.com/kercre123/wire-pod --depth=1
cd ~/wire-pod
sudo STT=vosk ./setup.sh
sudo ./chipper/start.sh
Once it has completed installing, in the terminal, you should see something similar to:
Initializing variables
SDK info path: /home/kerigan/.anki_vector/
API config JSON created
Initiating vosk voice processor with language
Loading plugins
Wire-pod is not setup. Use the webserver at port 8080 to set up wire-pod.
Starting webserver at port 8080 (http://localhost:8080)
Starting SDK app
Starting server at port 80 for connCheck
Configuration page: http://192.168.1.221:8080
Open a browser and head to the Configuration page. In the example above, this is http://192.168.1.221:8080.
- Update the Vector firmware and Activate it
Press and hold the Vecrots power button for 15 seconds until you see a white LED, and then release. Now open an incognito browser and head to https://wpsetup.keriganc.com/
Follow the instructions on the webpage to connect to the vector, you may have to attempt the connection a few times before it works.
Once the vector has updated you will be presented with an Activate button, ensure that WirePod is still running before clicking it.
Once the vector is activated, you can close WirePod.
- Update the .env file
Copy the serial number, located underneath the Vector Robot, into the .evn file.
Screen dimming
For this study, we used the Raspberry Pi Touch display and Raspberry Pi Touch display 2. To enable the dimming of the touch screen you will have to change the path to the brightness file to allow the screen to be dimmed. Type the following in the terminal
/sys/class/brightness/
Then press tab and update the env file by replacing rpi_backlight with directory displayed in your terminal.
The brightness value for:
- Raspberry Pi Touch display = 255
- Raspberry Pi Touch display 2 = 31
Auto start script
We tried a few different methods to start the program on the Raspberry Pi automatically. The most reliable was to use use systemd with a delay to ensure the desktop environment is ready before the script runs. This is to ensure that the browser launches on start-up, which will only happen after the desktop environment has finished loading.
- Create a systemd service file
sudo nano /etc/systemd/system/autostart_script.service
- Add the following configuration
[Unit]
Description=Run Custom Startup Script After Desktop Loads
After=multi-user.target network-online.target
Wants=network-online.target
[Service]
Type=simple
ExecStartPre=/bin/sleep 2
ExecStart=/bin/bash -l /home/pi/Documents/hri_study/SAR_for_habit_formation/bash.sh
User=pi
Group=pi
WorkingDirectory=/home/pi
Environment="DISPLAY=:0"
Environment="XDG_RUNTIME_DIR=/run/user/1000"
Restart=always
StandardOutput=append:/home/pi/logs/systemd_autostart.log
StandardError=append:/home/pi/logs/systemd_autostart.log
[Install]
WantedBy=multi-user.target
This will run the bash.sh with root level access after 2 seconds of the desktop environment loading.
- Create a log directory to store the output
mkdir -p /home/pi/logs/
- Apply changes and reboot
sudo systemctl daemon-reload
sudo systemctl enable autostart_script.service
sudo reboot
Updating Vector SDK library
The following are the steps taken to update the Vector SDK. These steps have been automated in the bash.sh files but if you want to run this in a seperate project the following may be useful to you.
Unfortunately, the installation of the vector SDK is not straightforward. The Vector library user is on proto buff version 3.19.0; however, many of the other libraries in this project use a newer version, 5.29.0, of proto buf. As a result, the andki_vector library needs to be updated with the proto files generated with the latest version of proto buff to allow it to work with other modern libraries.
This was done on a Mac by downloading protobuf using Brew and then downloading the vector SDK source files from Git Hub. Navigate to the anki_vector/messaging folder and then use the terminal command below to generate the new py2 files. Be aware that I had to download the Google API source code from GitHub, as the command below is needed to generate the .proto files.
`protoc --proto_path=/path/to/vector-python-sdk-master \
--proto_path=/path/to/googleapis \
--python_out=/path/to/vector-python-sdk-master/anki_vector/messaging/newproto_files \
/path/to/vector-python-sdk-master/anki_vector/messaging/alexa.proto \
/path/to/vector-python-sdk-master/anki_vector/messaging/behavior.proto \
/path/to/vector-python-sdk-master/anki_vector/messaging/cube.proto \
/path/to/vector-python-sdk-master/anki_vector/messaging/extensions.proto \
/path/to/vector-python-sdk-master/anki_vector/messaging/external_interface.proto \
/path/to/vector-python-sdk-master/anki_vector/messaging/messages.proto \
/path/to/vector-python-sdk-master/anki_vector/messaging/nav_map.proto \
/path/to/vector-python-sdk-master/anki_vector/messaging/response_status.proto \
/path/to/vector-python-sdk-master/anki_vector/messaging/settings.proto \
/path/to/vector-python-sdk-master/anki_vector/messaging/shared.proto`
I then copied all these files into the anki_vector/messages folder in the site-packages of the Python environment in which I am running the project.
If you get an error from the library that one of the imports is not installed, you most likely have a missing dependency. Create a Python project with the imports that are creating the error and run it. This should help identify the missing dependencies.
Patches
Additionally, I have had to make small patches in the anki_vector library to get it to work on Mac and then again to get it to work on Raspberry Pi.
For example, the loop argument is being passed to asyncio.Event() is in the anki_vector/events.py and anki_vector/connection.py files. You will need to remove the loop parameter from both files.
To run the flask app example in the vector SDK, I had to modify the anki_vector SDK code to use the newer textbox method instead of text size.