Working with the Physical MiRos¶
Introduction¶
In Week 1 you've overviewed the basics of the MDK and hopefully refreshed in your memory some of the ROS concepts, using the simulated MiRo and the WSL-ROS environment. On this page you will learn how to work with the physical MiRos using our dedicated Robot Laptops, specifically prepared for this task.
Handling the Robots¶
You'll no doubt be very familiar with MiRos by now, but it's still worth reiterating some general guidelines regarding handling the physical robot.
Abstract
Please adhere to the following husbandry practices
- Use common sense when handling the robot. It is not especially fragile, but neither is it intended to be treated roughly.
- Lift the robot only by the body shell, supporting its weight from underneath—do not pick up the robot by the head, this may damage the robot.
- Do not drop the robot from any height—it is not designed to absorb the shock of falling.
- Do not force any of the robot’s joints to move when they are under power or the robot may be damaged. If the joints are unpowered (for example, when the robot is powered off) you can gently move the joints as required.
- Do not otherwise apply force to or pull on any of the robot’s appendages (head, nose, ears, tail, eyelids, etc.) at any time.
- Do not push the robot along on a surface (or manually turn the drive wheels) at any time. Rather, if you need to move the robot, lift it as described above.
- Do not allow any liquids into contact with the robot.
- Do not take the robots with you outside of the lab environment.
Turning the Robots On and Off¶
Use the switch underneath your MiRo to turn it on and off. When turning On:
- Both red and blue lights on the left side of the body shell flicker together for two seconds.
- The red light stops flashing and remains lit and the blue light flashes slowly, indicating that the on-board computer is booting.
- When booting is complete, the blue light will stop flashing and remain lit.
When turning Off:
- The red light under the left flank will go out immediately.
- The blue light will flicker briefly three times, as the computer waits to see if the switch will be turned back on.
- If the switch remains off, the blue light will continue flickering for two seconds and then return to flashing slowly, indicating that the computer is shutting down.
- When shut down completes, the blue light will flicker again for five seconds and then go out, indicating that power has now been turned off.
On-board and Off-board Deployment¶
You might remember there are different profiles when developing code for the robot that were covered on the Getting Started page. When working with the real robots there are two possible profiles, on-board (local) and off-board (remote):
- "On-board" Deployment: The robot is powered by Raspberry Pi 3B+, which runs Raspbian Linux and ROS. We can therefore create ROS packages and nodes directly on the robot's filesystem and execute them on the robot itself.
- "Off-board" Deployment: ROS is network-based and can work over a Wi-Fi connection, so we can very easily add additional external ("remote") devices into our ROS network (e.g. a laptop computer), create ROS packages and nodes, and execute these on the remote device to invoke changes to a robot connected to the same ROS network.
For the most part, these pages assume that you will be deploying your ROS nodes off-board, and we have a fleet of pre-configured Robot Laptops in the lab that are set up to allow you to do this. In some cases, you might opt to deploy nodes locally instead, and this explains on a separate page.
Important
In all cases, it is important to remember that the ROS Master runs on the robot!
Working with the Robot Laptops¶
The WSL-ROS environment that you used in Week 1 ran Ubuntu 20.04 and ROS Noetic, and the laptops that we have in the robotics lab run exactly the same OS/Software.
The laptops come with a "student" user account that you should use when working in the lab. The laptop should log you into this user account automatically on start-up, but we will provide you with the account password as well, during the lab sessions, should you need it.
When working with the robot for the first time, there are three important steps you need to do...
Step 1: Enabling 'MiRo Mode'¶
You might remember using the laptops as part of the COM2009 labs to connect with the Turtlebot 3 robots, and indeed our robot laptops are also setup to work with them. For interoperability, we've implemented a quick switch between the two different modes that the laptops can operate in: 'MiRo Mode' and 'Waffle Mode'.
Clearly, we will want to use the former, so make sure the laptop is indeed in MiRo Mode by opening up an Ubuntu Terminal Window on the laptop (using the Ctrl+Alt+T
keyboard shortcut) and running the following command:
The following message indicates that the laptop has successfully been switched into MiRo Mode (if it wasn't already):
Step 2: Enabling 'Real Robot Mode'¶
The robot laptops can also be used to work in simulation, too (and, indeed, you can use the laptops over the workstations if you find WSL-ROS too slow for your purposes). To work with the physical robots, make sure that you are in 'Real Robot Mode' by running the following command:
... which should present you with the following message:
Step 3: Pairing the Laptop with a Robot¶
At this point you can turn on your MiRo robot, if you haven't done so already.
When the ROS on the robot completes its boot process, it will launch the ROS Master on the robot itself.
In order to connect your laptop to the robot, the ROS on the laptop needs to where the ROS Master is, which is handled by an environment variable which is called $ROS_MASTER_URI
, which needs to be on the same ROS Network.
Identify the number of the robot that you are working with by looking at the yellow label printed on its head, which will be of the form of a number between 1 and 40.
This is the 'Robot Number', and to tell the laptop that this is the robot that you will be working with, run the following command:
... replacing X
with the actual number of the robot, as determined above.
You should then see the following message:
Pairing with robot: dia-miroX...
Done. Re-source the .bashrc (by typing 'src') for the changes to take effect.
Do as instructed and re-source your environment now:
Once you've done all three of these things, it's a good idea to close down the terminal window. Don’t worry if you see a pop-up message saying that "there is a process still running," just click the "Close Terminal" button to proceed. Every new terminal window you open from now on should have the correct settings applied, so you're good to go!
Wi-Fi¶
The Robots and Laptops will communicate with one another (via a ROS Network) on a special wireless network running in the Diamond called 'DIA-LAB'.
Note
Laptops must be connected to the DIA-LAB network in order for you to communicate with the robots, so make sure that this is the case.
DIA-LAB is an internal network, so you will not be able to access the internet and you should use the Computer Room 3 workstations to access any external resources (such as these pages) instead.
Credentials for DIA-LAB should have already been set on the laptops, allowing you to connect straight away, but speak to a member of the teaching team if you are having any issues.
If you do want to connect the laptop to the internet temporarily, then you can also connect it to 'eduroam', but be aware that this will break any ROS network that may be running between the laptop and a robot. Credentials for eduroam have already been set up too, so you should be able to connect the laptop to it straight away, but - once again - speak to the teaching team if you are having any issues.
Note
Please be aware that due to network restriction only the Diamond devices can connect to the DIA-LAB!
Available IDE¶
Visual Studio Code is installed on the laptops for you to use when writing/editing your Python ROS nodes.
Launch VS Code from any terminal by simply typing code
, or you could also launch it by clicking the icon in the favourites bar on the left-hand-side of the screen.
ROS on the Robot¶
If you haven't already, now would be a good time to turn on your MiRo robot (please speak to a GTA if you haven't received one). As you might remember from COM1005 labs, MiRos take some time to load. A good indication of a successful boot process is when MiRo starts to speak its IP address.
Bug
Sometimes the robot fails to load the ROS bridge or connect to the DIA-LAB. If you haven't heard anything from the robot in about one minute, it might be a good idea to reboot it using the ON-OFF switch.
Note the last digits of the IP address, this is the number that you will use for the pair_with_miro
command.
Once everything is set up and ready, open a new terminal and run the rostopic list
command.
This is a quick way to check if a ROS network connection has been successfully established, as you should be able to see a list of ROS topics that are currently run on the robot.
Example
Try running miro_gui
and compare that to the output from the simulator!
Example: K-bandit¶
Now let's try running a program to showcase the functionality of the real robot. You can use the famous example of reinforcement learning, the so-called K-bandit problem, which is provided in the COM3528 code repo.
- Go to the MDK catkin workspace
- Clone the COM3528 code repo
- Build the workspace
Re-open the terminal window and run the script using the rosrun
command:
This program illustrates a simple action selection mechanism inspired by the K-bandit problem. Initially, MiRo performs one of the following actions on random, namely: wiggle ears, wag tail, rotate, turn on LEDs and simulate a Braitenberg 2a Vehicle based on the overall light level. While an action is being executed, stroking MiRo's head will reinforce that action, while stroking MiRo's body will inhibit it, by increasing or reducing the probability of this action being picked in the future.
You can open the source code for k_bandit.py
in VS Code and have a look at the comments to get a better idea of how it works.
Exercise: Try to add more actions to the existing repertoire or modify existing ones
=====
This completes the tutorial for the Week 2 lab session.