Programming XRP Robot Using Thonny
In Part 1 of the SLAM blog series, we discussed what SLAM (Simultaneous Localization and Mapping) is and how robots can use it for navigation. Part 2 went into the three primary techniques used in SLAM algorithms to create maps of unknown areas for robot navigation. In this blog, we will discuss a beginner-friendly robot, Experimental Robotic Platform (XRP), and how we can program it using an alternative method, Thonny.
What is XRP (Experimental Robotic Platform)?
XRP is an open-source robotic platform that helps in learning programming and the fundamentals of robotics. It is an entry-level robotics platform that is well-documented with good community support. XRP is a Raspberry Pi Pico based robot (Figure 1).
Figure 1: XRP robot. (Image source: SparkFun)
Why use Thonny?
Thonny is an open-source Python IDE (Integrated Development Environment) that is used for python programming and basic game development. Traditionally, we program XRP using a web interface known as XRP code. XRP code works with both Google Chrome and Microsoft Edge browsers. We are trying to find an alternative for XRP code using Thonny as there are some benefits to using Thonny. Thonny makes the installation of Micro Python libraries on XRP easier, and it improves the experience of programming XRP, especially in the Ubuntu OS. Given the glitches with the browser-based XRP code on Ubuntu OS, Thonny serves as a good alternative.
There are three steps involved in setting up Thonny for XRP programming.
Step 1: Installing XRP firmware (Optional)
If you haven’t already flashed the XRP firmware on your robot, follow these steps to download and install the firmware. Otherwise, if you have already done that, please skip this step and move on to Step 3.
1. Download the latest XRP firmware from the following URL:
URL: Releases · wpilibsuite/xrp-wpilib-firmware (github.com)
- You should be able to download a ‘.uf2’ file or download and extract the firmware ZIP file which contains a ‘.uf2’ file
2. Plug XRP into the USB port of your laptop
3. While pressing and holding the BOOTSEL button, press and release the RESET button (Figure 2)
Figure 2: XRP controller board. (Image source: SparkFun)
4. XRP will now temporarily disconnect from your computer to reconnect as a USB storage device ‘RPI-RP2’
5. Now copy the downloaded ‘.uf2’ file into the RPI-RP2 drive
6. Once the copying is finished, the drive will be automatically disconnected, and you can unplug the XRP from the PC
Step 2: Verify firmware installation using XRP code editor
Before moving ahead with using Thonny, let us first verify the installed firmware using the XRP code editor.
- Open the XRP code editor by accessing the following URL using Google Chrome or Microsoft Edge: XRP Code URL
- Plug the XRP into your PC using a USB cable
- To connect the XRP robot to the XRP code, press the ‘CONNECT XRP’ button
Step 3: Programming XRP using Thonny
- Download and install Thonny:
- Connect XRP to Thonny IDE
- After installation, open the application and connect XRP to your PC using a USB cable
- Configure Thonny IDE
- Go to Tools> Options> Interpreter (Figure 3)
URL: Thonny Website
Figure 3: Thonny IDE configuration. (Image source: Thonny.org)
- Then select ‘Micro Python (Raspberry Pi Pico)’ from the dropdown list (Figure 4)
- In the port dropdown list, select Try to detect port automatically for automatically detecting the com port for the connection (Figure 4)
Figure 4: Thonny IDE configuration. (Image source: Thonny.org)
Testing
To verify that everything went well, let us try to access the default programs on the XRP hardware.
- Go to File> Open..> and from the popup window select Raspberry Pi Pico (Figure 5)
Figure 5: Thonny IDE, accessing XRP files. (Image source: Thonny.org)
- Now you should be able to see all the default files or any files you have saved on XRP (Figure 6)
Figure 6: Thonny IDE showing XRP code files. (Image source: Thonny.org)
- Open ‘XRPExamples’ and run the any code of your choice
- You should be seeing the output as shown in Figure 7
Figure 7: Thonny IDE output window of running code. (Image source: Thonny.org)
Congratulations, now you have successfully programmed XRP using Thonny IDE.
Summary
There are benefits to using Thonny as an alternative for XRP code. The main advantages are that Thonny makes the installation of Micro Python libraries on XRP easier and it improves the experience of programming XRP, especially in the Ubuntu OS. Just follow the steps outlined in this blog to get your XRP programmed and running.
Have questions or comments? Continue the conversation on TechForum, Digi-Key's online community and technical resource.
Visit TechForum