TF Lab

From Introduction to Robotics (CS460)
Jump to: navigation, search
Lab 01: Shape Drawing

Lab Objectives

The objective of this lab is understand how tfpackage works in ROS, and develop programs that uses tf broadcaster and listeners.

Tasks

Task 1: Do the Tutorials

In the first task, you must do the following tf tutorials:

When completed, respond to the following questions:

  • What is the advantage of using tf in ROS?
  • What are the main steps to broadcast a transformation with tf package? Write the steps in your own words, no need to copy any code.
  • What are the main steps to listen to a transformation with tf package? Write the steps in your own words, no need to copy any code.
  • How to set the translational part of a transformation using tf?
  • How to set the rotational part of a transformation using tf?

Task 2: Modify the code

Now, we would like to modify the code such that the turtle2 does not overlap exactly on turtle1, but keeps a safe distance of 2 between each other.
Write the modified part of the code only.

Task 3: Do it yourself

In the file, copy and paste the following void move(double speed, double distance, bool isForward) that makes the robot moves in a straight line either forward or backward for the specified distance with the specified speed.

void move(double speed, double distance, bool isForward){
	geometry_msgs::Twist vel_msg;
  //set a random linear velocity in the x-axis
   if (isForward)
	   vel_msg.linear.x =abs(speed);
   else
	   vel_msg.linear.x =-abs(speed);
  vel_msg.linear.y =0;
   vel_msg.linear.z =0;
   //set a random angular velocity in the y-axis
   vel_msg.angular.x = 0;
   vel_msg.angular.y = 0;
   vel_msg.angular.z =0;
 
   double t0 = ros::Time::now().toSec();
   double current_distance = 0.0;
   ros::Rate loop_rate(100);
   do{
	   velocity_publisher.publish(vel_msg);
	   double t1 = ros::Time::now().toSec(); 
	   current_distance = speed * (t1-t0);
 	   ros::spinOnce();
	   loop_rate.sleep();
	   //cout<<(t1-t0)<<", "<<current_distance <<", "<<distance<<endl;
  }while(current_distance<distance);
  vel_msg.linear.x =0;
  velocity_publisher.publish(vel_msg);

}

Observe that the distance is controlled by the time (see bold text), which is not efficient.
In this task, you will modify the code and tf to calculate the traveled distance instead of using time.
hint: You must create a transform listener between the /world frame and the /turtle1 frame. Before moving, you determine the current pose (x0, y0) and orientation theta0 of the robot at time t0=0. Then, while moving, you update the pose of the robot (xt, yt, theta_t) using the tf transform listener and you stop the motion of the robot, when the traveled distance between the initial pose (x0, y0) and (xt, yt) becomes larger that the distance parameter.

Task 4: OPTIONAL

Do the same as Task 4, but for the method void rotate (double angular_speed, double relative_angle, bool clockwise)

void rotate (double angular_speed, double relative_angle, bool clockwise){

	geometry_msgs::Twist vel_msg;
	   //set a random linear velocity in the x-axis
	   vel_msg.linear.x =0;
	   vel_msg.linear.y =0;
	   vel_msg.linear.z =0;
	   //set a random angular velocity in the y-axis
	   vel_msg.angular.x = 0;
	   vel_msg.angular.y = 0;
	   if (clockwise)
	   		   vel_msg.angular.z =-abs(angular_speed);
	   	   else
	   		   vel_msg.angular.z =abs(angular_speed);

	   double t0 = ros::Time::now().toSec();
	   double current_angle = 0.0;
	   ros::Rate loop_rate(1000);
	   do{
		   velocity_publisher.publish(vel_msg);
		   double t1 = ros::Time::now().toSec();
		   current_angle = angular_speed * (t1-t0);
		   ros::spinOnce();
		   loop_rate.sleep();
		   //cout<<(t1-t0)<<", "<<current_angle <<", "<<relative_angle<<endl;
	   }while(current_angle<relative_angle);
	   vel_msg.angular.z =0;
	   velocity_publisher.publish(vel_msg);
}


What to Submit

Your responses in this Word document

How to Submit

Send your response to the email of the instructor.

Grading

  • Grade: 10 points
  • Deadline: Monday November 23, 2015