AWS Robomaker on RB3

Skill LevelArea of FocusOperating SystemPlatform/Hardware
IntermediateRobotics, Computer VisionLinuxRB3 Robotics Dev Kit

This project is designed to help you get started with Amazon AWS Robomaker and Qualcomm® Robotics RB3 Development Kit. The robotics platform is based on the Qualcomm ® Snapdragon™ 845 mobile platform from Qualcomm Technologies, so you may see the kit referenced as Qualcomm® SDA845 in some sections. The project will walk you through the following steps:

  1. Build and simulate a robot application in AWS cloud
  2. Deploy the robot application to the Qualcomm Robotics RB3 development kit through Greengrass
  3. Run the deployed robot application on the Qualcomm Robotics RB3 development kit

Build/Assembly Instructions

Here are a few things to keep in mind and test before you start. Please make sure that the Wi-Fi on target (Qualcomm Robotics RB3 Development Kit) can access the AWS website. After deployment, the ROS master and robot application are run inside the Docker. The sensor node/movebase packages/Kobuki packages are run outside the Docker (run on the target). Please launch the movebase/Kobuki packages only after the ROS master is running successfully inside the Docker.

Build and simulate a robot application in AWS cloud

  1. Hello World

    The “HelloWorld” example is designed to help you understand some basic concepts on ROS and AWS cloud such as S3 bucket and deployment process. You don’t need to change any code in this stage. You only need to repeat steps 1 and 2 below to “Restart the Hello World Simulation Application

    1. Create an AWS account.
    2. Run example Hello world simulation job.
    3. Create a development environment and a cloud 9 workspace. This will create a virtual PC (VPC) and a workspace on that VPC.
    4. Run HelloWorld app in your workspace.
    5. Deploy the robot APP to target.
       More details for this step can be found in section 2 of the instructions.
  2. Other Examples

    After the HelloWorld example, we recommend that you try other examples on Robomaker for better understanding and improving your skills.

    Please keep in mind that each example has a corresponding simulation job. Run a new simulation job, and choose from one of the examples as seen below. We recommend “Robot Monitoring” at this stage as it is based on movebase (navigation stack).

    1. Download the source code of example you choose. 
    2. Start from the section to “Modify and Build Applications” because you have already created an environment while running the HelloWorld example.
    3. Download the source code that corresponds to the simulation job you choose.
    4. Run this new simulation.
  3. Create your own

    Once you are familiar with the AWS Robomaker examples, it’s time to create your own application workspace, simulation job and deploy your own robot application.

    1. Create your workspace.

      1. You can utilize some code samples from existing examples, for example the movebase demo.
    2. Build and bundle your application.

    3. Create a simulation job.

      Useful Tips:

      1. The last section Create a Simulation Job can be done from the Robomaker console.

      2. For the rest of the steps, please follow the guild in your cloud 9 command prompt.

      3. After the simulation job is created successfully, you will see it’s in running state. In case of failure, you can check the log to troubleshoot.

    4. You can create a reference workspace based on movebase by the following steps.

      1. On the AWS simulation environment, a workspace includes a robot application and a simulation application. For the simulation application, you can utilize the Robot Monitoring example. Copy the whole folder of this simulation application to your new simulation app and remove the package aws_robomaker_simulation_common.

      2. Saving the below python script as a reference robot application to send the navigation goal to movebase. the folder tree please refer an exist AWS example.

      3. After deployment, the robot application runs on the SDA845 target inside the docker. the movebase runs outside the docker on SDA845. please refer to last section of guide to launch movebase and Kobuki(the real robot).

      The below python script is a reference for your robot application.

    5.   #!/usr/bin/env python

      import rospy
      import actionlib
      from actionlib_msgs.msg import *
      from geometry_msgs.msg import Pose, Point, Quaternion, Twist
      from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal

      class MoveBaseTest():
      def __init__(self):
      rospy.init_node('nav_test', anonymous=False)
      rospy.on_shutdown(self.shutdown)

      #p1 = Point(-1.04219532013, 5.23599052429, 0.0)
      p1 = Point(-1.04219532013, 2.23599052429, 0.0)
      q1 = Quaternion(0.0, 0.0, -0.573064998815, 0.819509918874)

      p2 = Point(1.64250051975, 1.58413732052, 0.0)
      q2 = Quaternion(0.0, 0.0, -0.0192202632229, 0.999815273679)

      p3 = Point(5.10259008408, 0.883781552315, 0.0)
      q3 = Quaternion(0.0, 0.0, -0.455630867938, 0.890168811059)

      p4 = Point(6.15312242508, -6.41992664337, 0.0)
      q4 = Quaternion(0.0, 0.0, 0.999290790059, -0.037655237394)

      p5 = Point(1.73421287537, -5.13594055176, 0.0)
      q5 = Quaternion(0.0, 0.0, 0.718415199022, 0.695614549743)

      p6 = Point(-3.83528089523, -5.31936645508, 0.0)
      q6 = Quaternion(0.0, 0.0, 0.701646950739, 0.712524776073)

      quaternions = list()
      quaternions.append(q1)
      quaternions.append(q2)
      quaternions.append(q3)
      #quaternions.append(q4)
      #quaternions.append(q5)
      #quaternions.append(q6)

      points = list()
      points.append(p1)
      points.append(p2)
      points.append(p3)
      #points.append(p4)
      #points.append(p5)
      #points.append(p6)

      goals = list()
      goals.append(Pose(points[0], quaternions[0]))
      goals.append(Pose(points[1], quaternions[1]))
      goals.append(Pose(points[2], quaternions[2]))
      #goals.append(Pose(points[3], quaternions[3]))
      #goals.append(Pose(points[4], quaternions[4]))
      #goals.append(Pose(points[5], quaternions[5]))

      rospy.loginfo("*** started navi test")

      # Publisher to manually control the robot (e.g. to stop it, queue_size=5)
      self.cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=5)

      # Subscribe to the move_base action server
      self.move_base = actionlib.SimpleActionClient("move_base", MoveBaseAction)
      self.move_base.wait_for_server()

      rospy.loginfo("Connected to move base server")
      rospy.loginfo("Starting navigation test")

      # Initialize a counter to track goals
      i = 0
      while not rospy.is_shutdown():
      # Intialize the waypoint goal
      goal = MoveBaseGoal()
      goal.target_pose.header.frame_id = 'map'
      goal.target_pose.header.stamp = rospy.Time.now()
      goal.target_pose.pose = goals[i%3]

      #move toward the goal
      self.move(goal)
      i += 1

      def move(self, goal):
      # Send the goal pose to the MoveBaseAction server
      self.move_base.send_goal(goal)

      # Allow 1 minute to get there
      finished_within_time = self.move_base.wait_for_result(rospy.Duration(60))

      # If we don't get there in time, abort the goal
      if not finished_within_time:
      self.move_base.cancel_goal()
      rospy.loginfo("Timed out achieving goal")
      else:
      if self.move_base.get_result():
      rospy.loginfo("Goal done: %s", goal)

      def shutdown(self):
      rospy.loginfo("Stopping the robot...")
      # Cancel any active goals
      self.move_base.cancel_goal()
      rospy.sleep(2)
      # Stop the robot
      self.cmd_vel_pub.publish(Twist())
      rospy.sleep(1)

      if __name__ == '__main__':
      try:
      MoveBaseTest()
      except rospy.ROSInterruptException:
      rospy.loginfo("Navigation test finished.")
    6. Deploy your own application.

      Details for deploying your application are described below.

Deploy the robot application to RB3 development kit through AWS IOT Greengrass

Refer to the AWS Greengrass official guide for the latest getting started instructions.

  1. Create IAM policy

    1. Open IAM page above and select “Policies” ---> “Create policy”

    2. Choose “Greengrass”

    3. Type the policy info in “JSON” tab, copy the JSON code below and modify s3 BUCKET info

                {
                    "Version": "2012-10-17",
                    "Statement": [
                        {
                            "Effect": "Allow",
                            "Action": [
                                "robomaker:UpdateRobotDeployment"
                            ],
                            "Resource": "*"
                        },
                        {
                            "Effect": "Allow",
                            "Action": [
                                "s3:List*",
                                "s3:Get*"
                            ],
                            "Resource": ["arn:aws:s3:::my-robot-application-source-bucket/*"]
                        }
                    ]
                }
              
    4. Input your own policy name and then “Create policy”

  2. Create IAM role

    1. Open IAM page below and select “Role” ---> “Create role”

    2. Choose “Greengrass”

    3. Select the policies below and then select “Next”

      1. AWSGreengrassResourceAccessRolePolicy

      2. SZ_IOE_POLICY

    4. “Add tags” page is optional, skip it by selecting “Next”

    5. Enter your IAM role name and create role.

    6. Edit trust relationship, and copy the JSON settings seen below:

                {
                  "Version": "2012-10-17",
                  "Statement": [
                    {
                      "Effect": "Allow",
                      "Principal": {
                        "Service": [
                          "greengrass.amazonaws.com",
                          "lambda.amazonaws.com"
                        ]
                      },
                      "Action": "sts:AssumeRole"
                    }
                  ]
                }
              

  3. Create AWS IoT Greengrass Group

    1. Open page below, select “Create Group”

    2. Select “Use easy creation”

    3. Specify a Group name and then click “Next”

    4. Specify a Greengrass Group name and then click “Next”

    5. Select “Create Group and Core”

    6. Download your security resources as pic shown below, and select “Finish”

      *** This is your only chance to download the security resources.

      *** Downloaded security keys will be used in the next step.

    7. Attach the IAM role to the Greengrass Group

Congratulations! You have successfully created the IAM policy, role and created a Greengrass group for Robomaker. Next, let’s look at how you can run the Greengrass Core on RB3 development kit.

Run GG-Core in RB3 development kit Docker

  1. Prerequisites and launching the docker service

    1. Follow the steps below to connect the development kit to the internet.

      Use below steps to enable WLAN and dhcp.

                $ insmod usr/lib/modules/4.9.103/extra/wlan.ko
                $ ifconfig wlan0 up
                $ wpa_supplicant -iwlan0 -Dnl80211 -c /data/misc/wifi/wpa_supplicant.conf -O data/misc/wifi/sockets &
                $ /usr/sbin/dhcpcd wlan0 -t 0 -o domain_name_servers --noipv4ll -h -b &
                $ wpa_cli -iwlan0 -p /data/misc/wifi/sockets
                $ add_network
                $ set_network 0 ssid "Your SSID"     
                $ set_network 0 psk "SSID Password"
                $ enable_network 0
              

      Ping some website to make sure wlan network is up.

    2. Run chronyd, and make sure system time is correct.

    3. Resolve host name “sda845” to “127.0.0.1” by add content below to /etc/hosts

    4. create a work directory on target

                $ mkdir -p /greengrass/certs
                $ mkdir -p /greengrass/config
              
    5. Push files listed below to /greengrass directory

      1. arm32v7-ubuntu-18.04-aws-iot-greengrass.tar

      2. your-security-file.tar.gz

    6. Copy the content in page below and save it as /greengrass/certs/root.ca.pem

      https://www.amazontrust.com/repository/AmazonRootCA1.pem

    7. Decompress the secure file

                $ tar xzvf your-security-file.tar.gz -C /greengrass
              
    8. launch Docker service

                $ systemctl start docker
              

      Pro Tip: You can check docker with the command “ps -ef | grep docker”

    9. load docker image

                $ docker load -i arm32v7-ubuntu-18.04-aws-iot-greengrass.tar
              

      Pro Tip: You can run command “docker images” and you’ll see docker images already installed on your system

    10. Environment setup is now done, proceed to run Greengrass Group core on target

                $ docker run --rm -it --name aws-iot-greengrass --entrypoint /greengrass-entrypoint.sh -v /greengrass/certs:/greengrass/certs -v  /greengrass/config:/greengrass/config -v /greengrass/log:/greengrass/ggc/var/log -p 8883:8883 armv7l-ubuntu18.04/test-aws-iot-greengrass:1.8.0
              

      Pro Tip: Press “CTRL+P+Q” keys to detach docker, it’s running in the background now!

    11. Check docker status

                $ docker ps
              
    12. Check Greengrass Group core log

      A sample log seen below indicates that your Greengrass Group core successfully connected.

                $ tail -F /greengrass/log/system/runtime.log
                
                [2019-04-18T04:23:20.122Z][INFO]-Started Deployment Agent and listening for updates
                [2019-04-18T04:23:20.122Z][INFO]-Started Deployment Agent and listening for updates
                [2019-04-18T04:23:20.122Z][INFO]-MQTT connection connected. Start subscribing: clientId: SZ_IOE_GROUP_Core
                [2019-04-18T04:23:20.122Z][INFO]-Deployment agent connected to cloud
                [2019-04-18T04:23:20.123Z][INFO]-Start subscribing 2 topics, clientId: SZ_IOE_GROUP_Core
                [2019-04-18T04:23:20.123Z][INFO]-Trying to subscribe to topic $aws/things/SZ_IOE_GROUP_Core-gda/shadow/update/delta
                [2019-04-18T04:23:20.806Z][INFO]-Subscribed to : $aws/things/SZ_IOE_GROUP_Core-gda/shadow/update/delta
                [2019-04-18T04:23:20.806Z][INFO]-Trying to subscribe to topic $aws/things/SZ_IOE_GROUP_Core-gda/shadow/get/accepted
                [2019-04-18T04:23:21.307Z][INFO]-Subscribed to : $aws/things/SZ_IOE_GROUP_Core-gda/shadow/get/accepted
                [2019-04-18T04:23:21.789Z][INFO]-All topics subscribed, clientId: SZ_IOE_GROUP_Core
              
    13. kill container (stop greengrass-core)

                $ docker kill <ggc container-id>	  ## get container id by docker ps
              

      Pro Tip: If you do not kill the container now, you will encounter a Greengrass Group core crash issue in the next step.

  2. Create robot application

    Follow the steps above to create your own application. While creating the application, be sure to select the correct AWS region (us-east-1, us-west-2, etc.).

    1. Configure your robot app

      1. Inside “Development” – “Robot applications” page, select your application and click “Actions” button,

      2. Enter your robot-app S3 address to the “ARM64 source file”

        You can get this info from page https://s3.console.aws.amazon.com/s3/home?region=us-east-1

      3. Inside “Development” – “Robot applicants”, click your app name, and then select “create new version”

    2. “Fleet management” – “Robots” – “Create robot”

    3. “Fleet management” – “Fleets” – “Create fleet”

    4. Click your fleet name inside “Fleets” page, then click “Register new” button and register your robot.

    5. Inside “Fleet management” – “Deployment” – “Create deployment”. Configure your robot app info, and then click “create”

  3. Deploy lambda (robot app) to target

    Log into the Greengrass console and navigate to the Group hub.

    Here you can see:

    1. A lambda function is added to the robot application that was created.

    2. Group status is “In progress”

    3. Select “Action” -- “reset deployment” to reset the status because we need some other configuration

    4. In “setting” page, set “Lambda function containerization” to “no container” 
This is an important step before you can deploy the Lambda, or Greengrass Group core will crash

    5. Run Greengrass Group core on target

                $ docker run --rm -it --name aws-iot-greengrass --entrypoint /greengrass-entrypoint.sh -v /greengrass/certs:/greengrass/certs -v  /greengrass/config:/greengrass/config -v /greengrass/log:/greengrass/ggc/var/log --network host armv7l-ubuntu18.04/test-aws-iot-greengrass:1.8.0
              
    6. Deploy

Congratulations! You have successfully deployed the robot application to RB3 development kit through AWS IoT Greengrass.

Run the deployed robot application on RB3 development kit

The robot application ROS node would run along with ROS master inside the docker once the deployment is finished. You need to run the Kobuki ROS package or other ROS packages (for example movebase) after ROS master is running. Before you run these packages, you need to setup the devices. Here is a script to help you with easy setup.

  #! /bin/sh
  #hack the kobuki_node minimal.launch first: remap odom to wheel_odom
  #hack the /etc/ros_8009.bash: set the ROS_IP, ROS_HOSTNAME and 
  #ROS_MASTER_URI with IP address directly,  'localhost' doesnot work
  source /etc/ros_845.bash
  roslaunch /opt/ros/indigo/share/kobuki_node/launch/minimal.launch &
  sleep 5
  roslaunch /data/pathplan/launch/movebase_845.launch

Setup the ROS env:

  1. Copy the script to the RB3 kit.

          adb push launch_movebase.sh /home
          adb shell
        
  2. Edit the ROS environment to change the IP address

          vi /opt/ros/indigo/share/ros_env.bash
        
  3. Set IP address as seen below

          export ROS_MASTER_URI=http://192.168.1.102:11311
          export ROS_IP=192.168.1.102
          export ROS_HOSTNAME=192.168.1.102
        
  4. Switch to home directory

          cd /home
        
  5. Launch!

          $ ./launch_movebase.sh
        

Congratulations! You are now up and running with Robomaker on the RB3 Development kit. 
The “Hello World” example is designed to make the Kobuki base rotate in place. The reference application is designed to make the Kobuki base move. We cannot wait to see how you use these powerful platforms, you can share your projects with us here.

NameTitle/Company
Zixiang WangDirector, Engineering
Qualcomm
Weizhang LuoSenior Staff Engineer
Qualcomm.