Source Code
MyCobot 280 Pi#
Note
Optionally, complete the following network setup steps, applicable to devices such as Raspberry Pis running RPi OS Lite.
Consider setting up Tailscale for secure remote access and management. Please refer to the Tailscale Setup Guide for detailed instructions on installation and configuration.
If you need to connect to a WPA2-Enterprise WiFi network (common in institutional environments), please refer to the Raspberry Pi WPA2-Enterprise WiFi Setup Guide first.
The general structure of the program is as follows;
The cobot runs a python server which listens for commands from HiveMQ, and runs the appropriate Python API functions from pymycobot.
HuggingFace Spaces and the HuggingFace Python API (used in the Colab demo above) connect to HiveMQ and send commands to the appropriate topics, which the server is listening on.
If you own a Cobot, you can follow the instructions below to set it up. Once completed, you also have the option of using the
CobotControllerclass as defined inclient.py.
Setup guide (if you own a cobot)#
Power on the Cobot280 Pi and connect the micro HDMI cable to a monitor.
Connect the Cobot280 Pi to Wifi by clicking on the Wifi icon in the top right corner of the screen.
Open a terminal and type to the following command to upgrade system packages
sudo apt-get update && sudo apt-get upgrade -y
Install the required system dependencies with the following command
sudo apt-get install git
Clone the repository containing the code for the server run by the Cobot.
git clone https://github.com/AccelerationConsortium/ac-training-lab.git
Since we only need the files in the
ac-training-lab/src/ac_training_lab/cobot280pi/directory, we move them out and delete the rest of the repository.
mv ac-training-lab/src/ac_training_lab/cobot280pi ./
rm -rf ./ac-training-lab
cd ./cobot280pi
Install the required python packages for running the server.
pip install -r requirements.txt
Create an account on HiveMQ. Once you do, create a free serverless cluster. In the Overview > Connection details section, take note of the URL and Port parameters.
Then, in the Access Management section, create new credentials. Choose a Username and Password and take note of these parameters too. For the Permission dropdown, select Publish and Subscribe, and then Save your new credentials.
Create a file in the
ac-training-lab/src/ac_training_lab/cobot280pi/directory namedmy_secrets.py. Paste the following contents into the file. Replace the <…> attributes with your own values as noted above. Make sure to keep these credentials secret!
HIVEMQ_USERNAME = "<HiveMQ credential username>"
HIVEMQ_PASSWORD = "<HiveMQ credential password>"
HIVEMQ_HOST = "<host URL from HiveMQ>"
DEVICE_PORT = <port from HiveMQ>
DEVICE_ENDPOINT = "cobot280pi/cobot1"
Run the server with the following command.
python device.py
Your server is now running! You can use the
CobotControllerclass from theclient.pyfile to control your cobot. Initialize it with the same parameters as in yourmy_secrets.pyfile.