Sunday, March 29, 2015

Creating a robotic arm model using MoveIT


In this video tutorial, I explained multiple details for creating robotic arm using moveIT, and viewing it in rviz. This tutorial is divided into following steps. In order to cover all the details follow the steps explained in video.

1. Installing moveit.

2. Creating a static robotic arm model,

3. Running the moveit Setup assistant,

4. Loading the urdf model,

5. Generating the collision matrix,

6. Creating Virtual joints,

7. Adding the right arm planning group,

8. Adding the gripper joints,

9. Defining robot poses

10. Generating the Configuration files.



References
1. wiki ROS.
2. Wiki MoveIT,
3, ROS by example v2 book

Creating and Playing the ROSBAG file

This tutorial is a video tutorial that describes how to create a rosbag file, how to replay the ros bag file and how to run the hokuyo node. so video is divided into following steps.

1. Allowing hokuyo node to connect with.
2. Deploying roscore
3. Running Hokuyo node
4. Checking for topic scan
5. Looking in RVIZ for data view
6. creating a bag file for recording scan topic
7. Stopping every thing except roscore.
8. playing bag file.
9. Viewing the data in rviz again and comparing it will recorded data.


Tuesday, March 3, 2015

Creating Publisher and Subscriber for TurtleSim in ROS


This tutorial explains the creation of publisher and subscriber. It also explains how to get the message details and call backs for each subscriber. In second portion it creates a publisher for turtlesim.

In order to create the publisher and subscriber for turtlesim provided by ROS follow the following steps.

1. run roscore on the terminal, For this open the terminal and write "roscore".



2. Open new terminal using "Ctrl+Shift+N" or using mouse and run the turtlesim using following command
"  rosrun turtlesim turtlesim_node "



3. See the list of topic , for this open new terminal and write
" rostopic list "




4. There are three topics for the turtlesim naming

  • /turtle1/cmd_vel
  • /turtle1/color_sensor
  • /turtle1/pose


5. Now lets see which topic need subscriber and which one need publisher, for this run the following command

" rostopic info /turtle1/color_sensor" 




and this shows it needs a subscriber as it is a published topic having type " turtlesim/Color "

now run the command
" rostopic info /turtle1/pose "



and this shows it needs a subscriber as it is a published topic having type " turtlesim/Pose "

now run the command for third topic
 "rostopic info /turtle1/cmd_vel "



and this shows it needs a publisher as it is a subscriber on the topic " geometry_msgs/Twist "

6. Once we know about the subscribers and publisher , we can continue our programming. First we will create subscriber, so in order to create , create an empty file named " subscriber_tsim.cpp ". and copy the following code.

#include "ros/ros.h"
#include "turtlesim/Color.h"
#include "turtlesim/Pose.h"

// Topic messages callback
void color_callback(const turtlesim::Color::ConstPtr& col)
{
ROS_INFO("red: %d, green: %d, blue: %d", col->r, col->g, col->b);
}

//pose_callback
void pose_callback(const turtlesim::Pose& msgIn){

ROS_INFO_STREAM(std::setprecision(2) << std::fixed
<< "position=(" << msgIn.x << "," << msgIn.y << ")"
<< "direction=" << msgIn.theta); 
  
}

int main(int argc, char **argv)
{
    // Initiate a new ROS node named "subTsim"
ros::init(argc, argv, "subTsim");
//create a node handle: it is reference assigned to a new node
ros::NodeHandle node;

    // Subscribe to a given topic, in this case "chatter".
//color_callback: is the name of the callback function that will be executed each time a message is received.
    ros::Subscriber subscriber_color = node.subscribe("/turtle1/color_sensor", 1000, color_callback);

    
    ros::Subscriber subscriber_pose=node.subscribe("turtle1/pose", 1000, pose_callback);
    // Enter a loop, pumping callbacks
    ros::spin();

    return 0;
}


7. Now, we have to change the makings on CMakeLists.txt . add the following lines

add_executable(subtsim src/subscriber_tsim.cpp)
target_link_libraries (subtsim ${catkin_LIBRARIES})
add_dependencies(subtsim beginner_tutorials_generate_message_cpp)


8. Now, open the terminal and compile the code. for this type following

cd catkin_ws
catkin_make

if the compilation is successful then we can proceed.

9. now run the node we created , for this run the following code.
" rosrun beginner_tutorials subtsim




10. Now, we will create the publisher, for this create a file named "publisher_tsim.cpp " and copy the following code

#include "ros/ros.h"
#include "geometry_msgs/Twist.h"
#include "geometry_msgs/Pose.h"
#include <sstream>


int main(int argc, char **argv)
{
// Initiate new ROS node named "talker"
ros::init(argc, argv, "pubTsim");
ros::NodeHandle n;

ros::Publisher velocity_publisher = n.advertise<geometry_msgs::Twist>("/turtle1/cmd_vel", 1000);
ros::Rate loop_rate(1); //1 message per second

   int count = 0;
   /* initialize random seed: */
     srand (time(NULL));
   while (ros::ok()) // Keep spinning loop until user presses Ctrl+C
   {

  geometry_msgs::Twist vel_msg;
  //set a random linear velocity in the x-axis
  vel_msg.linear.x =(double)(rand() % 10 +1)/4.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;
  vel_msg.angular.z =(double)(rand() % 10 - 5)/2.0;

  //print the content of the message in the terminal
   ROS_INFO("[Random Walk] linear.x = %.2f, angular.z=%.2f\n", vel_msg.linear.x, vel_msg.angular.z);

  //publish the message
  velocity_publisher.publish(vel_msg);
       ros::spinOnce(); // Need to call this function often to allow ROS to process incoming messages

      loop_rate.sleep(); // Sleep for the rest of the cycle, to enforce the loop rate
       count++;
   }
   return 0;
}

save the file.

11. Now go to CMakeLists.txt and add the following lines
add_executable(pubtsim src/publisher_tsim.cpp)
target_link_libraries (pubtsim ${catkin_LIBRARIES})
add_dependencies(pubtsim beginner_tutorials_generate_message_cpp)



12.  Now, open the terminal and compile the code. for this write 
cd catkin_ws
catkin_make

13. Now, launch the node, this will make the turtlesim run as random walk. you can also view the values from subscriber node.





14. For more details you can watch the video tutorial at