Monday, October 18, 2021

Use Virtual Machine Manager to create a Raspberry Pi virtual machine on Ubuntu

I tried to use the Virtual Machine Manager (virt-manager)'s graphical user interface on Ubuntu to create a Raspberry Pi virtual machine. I found it to be a little tricky having to know the right parameters and configuration. This post describes the steps I went through to successfully create and run the Raspberry Pi virtual machine.

Install software prerequisites

If virt-manager and/or QEMU are not installed on the Ubuntu host, then run the following commands to install them.

$ sudo apt-get install qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils virtinst libvirt-daemon virt-manager

Download a Raspberry Pi OS image

  1. Open up a browser to https://www.raspberrypi.com/software/operating-systems/.

  2. Click on a Raspberry Pi OS image of your choice to download. For example, Raspberry Pi OS Lite.

  3. Unzip the download file and place the extracted image file e.g. 2021-05-raspios-buster-armhf-lite.img to a folder, e.g. /path/to/folder/.

Download a QEMU kernel and the device tree blob (.dtb) for Raspberry Pi

  1. Open up a browser and browse to the repository https://github.com/dhruvvyas90/qemu-rpi-kernel.

  2. Click on kernel-qemu-4.19.50-buster and download the kernel to a folder, e.g. /path/to/folder/.


  3. Next, click on versatile-pb-buster.dtb and download the file to a folder, e.g. /path/to/folder/.

Create a new VM

  1. On the Ubuntu host, run virt-manager.

    The Virtual Machine Manager graphical application appears.
     
  2. Click the Create a new virtual machine button.

    The New VM dialog box wizard appears.


  3. In the Architecture options drop down, choose armv6l in the Architecture combo box. Then select versatilepb in the Machine Type combo box. Press Forward.

    Step 2 page appears.
     
  4. In the Provide the existing storage path field, click Browse.

    The Choose Storage Volume dialog appears.


  5. Click Browse Local and choose to open the previously downloaded Raspberry Pi OS image, e.g. /path/to/folder/2021-05-raspios-buster-armhf-lite.img.



  6. In the Kernel path field, click the Browse button.

    The Choose Storage Volume appears again.


  7. Click Browse Local and choose to open the previously downloaded kernel file, e.g. /path/to/folder/kernel-qemu-4.19.50-buster.

  8. In the DTB path field, click the Browse button.

    The Choose Storage Volume appears.

  9. Click Browse Local and choose to open the previously downloaded dtb file, e.g. /path/to/folder/versatile-pb-buster.dtb.

  10. In the Kernel args field, type in the following:

    root=/dev/vda2 panic=1

  11. Finally, in the Choose the operating system you are installing field, type and choose the following:

    Generic default (generic)

    The Step 2 of the New VM dialog should look like the screen below.


  12. Click Forward.

    Page Step 3 appears.

  13. In the Memory field, change the value to 256.



  14. Click Forward.

    Page 4 appears.


  15. Optional. Change the Name from vm-armv6l if necessary.

     
  16. Toggle on Customize configuration before install. In the Network selection drop down, select Specify shared device name. Then type in virbr0 in the Bridge name.

  17. Click Finish.

    The vm-armv6l on QEMU/KVM dialog box appears.



Customize configuration

  1. Click CPUs. Then in the Model combo box, choose arm1176. Then click Apply to save the change.



  2. Click Boot Options. Toggle on Enable boot menu. Then Toggle on IDE Disk 1. Click Apply.




  3. Click on IDE Disk 1. Then click the Advanced options drop down. In the Disk bus field, change from IDE to VirtIO. Click Apply.



  4. Click the NIC icon. Then change the Device model to virtio. Click Apply.



  5. Optional. Click Add Hardware to add additional peripherals such as Serial mouse, Video card etc. if necessary.

  6. Click Begin Installation.

    The processing messages appear and the Raspberry Pi VM is created.


Monday, October 11, 2021

Using rostopic to simulate publishing odometry topic messages

While developing (Robotic OS) ROS1 node callbacks, and you don't have any inertial motion devices on hand, you can use the rostopic utility command with pub option to simulate the publishing of odometry messages. Basically, before being able to use the command, you have to find out how the odometry message is structured. Once you have the fields - names and format, simply create a shell script and type in the rostopic command with the correct argument structure. More information about the rostopic command is available on http://wiki.ros.org/rostopic.

Identify the Odometry message fields

This can be done using the rosmsg command. In a Terminal, type in the following command:

$ rosmsg info nav_msgs/Odometry

The odometry fields are displayed.

Create a shell script

Using your favorite text editor, create a shell script e.g. test_rostopic.sh to publish odom topic messages of type nav_msgs/Odometry. Type in the following with the fields and corresponding values in yaml format. Make sure no tabs are used and be careful of the spaces.

rostopic pub /odom nav_msgs/Odometry '
{
header: {seq: 1, stamp: now},
pose: 
  { 
  pose: { 
    position: { x: 10, y: 20, z: 30}, 
    orientation: { x: 0.2, y: 0.1, z: 0}
  }, 
  covariance: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},
}'
-r 0.1

Note: the last line "-r 0.1" simply says to repeat the rostopic pub command at 0.1 hz.

Run the shell script

 In a Terminal, type in the following to run the rostopic pub command.

$ bash /path/to/test_rostopic.sh

Optional. To see whether the odometry messages published by the script, open up another Terminal and run the following command:

$ rostopic echo odom

The odom topic is displayed.