Class Meeting 08: Forward & Inverse Kinematics


Today's Class Meeting



What You'll Need for Today's Class



Class Exercise #1: Computing Forward Kinematics for 3DOF Robot Manipulator in 3 Dimensions


For this exercise, work independently to compute \([x, y, z]\) of the robot's end effector in terms of the lengths of the robot's two linkages \((l_1, l_2)\) and the angles of rotation of the two revolute joints \( (q_1, q_2) \). If it's useful to you, feel free to reference the slides we just went over in class.

forward kinematics 3D 2DOF manipulator

Once you've finished computing \([x, y, z]\), please wait for others to finish. We'll go over the solution in the main Zoom room together.


Class Exercise #2: Basics of Robot Arm Control


Please head into breakout rooms for this class exercise.

In this class exercise, you will 1) learn the basics of turtlebot's arms though GUIs, 2) learn how to manipulate the arm through code.



Arm Control Through GUI


Let's go over the Turtlebot3 tools that allows you to control the robot arm with a GUI. First run the following command, which starts starts a gazebo session a Turtlebot3 with an OpenMANIPULATOR arm.

$ roscore
$ roslaunch turtlebot3_manipulation_gazebo turtlebot3_manipulation_gazebo.launch

Turtlebot3 with an arm.

Next, you need MoveIt to manipulate the arm. Launch the following in a new terminal. Once this node is up and running, start your gazebo simulator by pressing the ▶ button in the bottom left. You should see a message that says, You can start planning now! in the terminal running the move_group.

$ roslaunch turtlebot3_manipulation_moveit_config move_group.launch

Finally, you need some GUI to control the robot arm. The ROBOTIS GUI provides you with a simple window that allows control of the robot arm within gazebo. Use the following command to launch the GUI. Make sure your gazebo simulation is running and not stopped; otherwise the GUI window will not pop up.

$ roslaunch turtlebot3_manipulation_gui turtlebot3_manipulation_gui.launch

ROBOTIS GUI for arm.

The GUI provides the following information,

Let's make sure your simulation robot can move its arm. Press Time Start and then click on Home Pose. You should see your robot arm move to a new position in the simulation. Pay close attention to how the new pose changes the joint and XYZ values.

Manual movement of the arm is possible through the options in the bottom right features of the GUI. There are two options available for this purpose,

The window with an s next to it is for selecting how fast you want the the transformation to occur. Once you are done with your manual selection, send your desired positions to the robot and watch the arm move.

Think about the following questions while you experiment with the GUI,


Arm Control Through Code with the MoveIt Package


The MoveIt ROS package provides a simple, yet powerful interface to control the OpenMANIPULATOR arm on our Turtlebot3. This section outlines the general interface. There is no need to implement anything in the section. Just make sure that you understand the basics of the interface.

First, we setup the interface for controlling the gripper and the arm in the object initialization.

#!/usr/bin/env python3

import rospy
# import the moveit_commander, which allows us to control the arms
import moveit_commander


class Robot(object):

  def __init__(self):

      # initialize this node
      rospy.init_node('turtlebot3_dance')

      # the interface to the group of joints making up the turtlebot3
      # openmanipulator arm
      self.move_group_arm = moveit_commander.MoveGroupCommander("arm")

      # the interface to the group of joints making up the turtlebot3
      # openmanipulator gripper
      self.move_group_gripper = moveit_commander.MoveGroupCommander("gripper")

With this starter code, moving the arm or the gripper using joint angles is fairly simple. Let's try moving the arm,

  def run(self):
      ...
      ...
      # We can use the following function to move the arm
      # self.move_group_arm.go(arm_joint_goal, wait=True)

      # arm_joint_goal is a list of 4 radian values, 1 for each joint
      # wait=True ensures that the movement is synchronous

      # Let's move the arm based on what we have learned

      # First determine at what angle each joint should be.
      # You can use the GUI to find appropriate values based on your need.
      arm_joint_goal = [0.0,
                     math.radians(5.0),
                     math.radians(10.0),
                     math.radians(-20.0)]

      # Move the arm
      self.move_group_arm.go(arm_joint_goal, wait=True)

      # The above should finish once the arm has fully moved.
      # However, to prevent any residual movement,we call the following as well.
      self.move_group_arm.stop()   

Moving the gripper is very similar.

       # We can use the following function to move the gripper
       # self.move_group_gripper.go(gripper_joint_goal, wait=True)

       # gripper_joint_goal is a list of 2 values in meters, 1 for the left gripper and one for the right
       # wait=True ensures that the movement is synchronous

       # Let's move the gripper based on what we have learned

       # First determine what how far the grippers should be from the base position.
       # You can use the GUI to find appropriate values based on your need.
       gripper_joint_goal = [0.009,0.0009]

       # Move the gripper
       self.move_group_gripper.go(gripper_joint_goal, wait=True)

       # The above should finish once the arm has fully moved.
       # However, to prevent any residual movement,we call the following as well.
       self.move_group_gripper.stop()


Class Exercise #3: TrafficBot


In this exercise, we will use the arm of the turtlebot to guide an imaginary traffic. You should not use the robot's wheels for this exercise. You will be working the same groups.

TrafficBot from above.

Getting Started


To get started on this exercise, update the intro_robo class package to get the class_meeting_08_kinematics ROS package and starter code that we'll be using for this activity.

$ cd ~/catkin_ws/src/intro_robo
$ git pull
$ git submodule update --init --recursive
$ cd ~/catkin_ws && catkin_make
$ source devel/setup.bash      

Your Goal


Your goal in this exercise will be to have the robot arm move in a distinct manner based on the direction it receives via the traffic_status topic. Here is an example scenario.
TrafficBot from above.

Running Your Code


First terminal: run roscore.

$ roscore

Second terminal: run your Gazebo simulator with the intersection environment provided in today's class repo.

$ roslaunch class_meeting_08_kinematics turtlebot3_intersection.launch 

Thrid terminal: Launch the MoveIt move_group..

$ roslaunch turtlebot3_manipulation_moveit_config move_group.launch 

Forth terminal: Run the python node that moves your robot arm.

$ rosrun class_meeting_08_kinematics move.py

Steps to Take & Starter Code


There are few steps you would need to take to complete this exercise.

Example Solution Code


Here is the example solution code


Tips & Hints about the Arm & Gripper


Acknowledgments


I want to thank Woolfrey for their helpful Youtube videos on forward and inverse kinematics for helping to inform the content for today's class.