Why publish the same command multiple times to reach a position?
Hi,
I am learning Baxter Robot using ROS in C++ language. For getting used to with ROS and Baxter, I am writing a C++ program to control Joint position. A joint position is defined and it is published to /robot/limb/right/joint_command
topic. Below is the snippet of the code-
int main(int argc, char **argv)
{
//Initializen the ros
ros::init(argc, argv, "move_joints");
//Declare the node handle
ros::NodeHandle node;
//Decleare a joint state publisher
ros::Publisher joint_pub = node.advertise<baxter_core_msgs::JointCommand>("/robot/limb/right/joint_command",10);
//Define the joint state
baxter_core_msgs::JointCommand joint_cmd;
//Set the mode
joint_cmd.mode = baxter_core_msgs::JointCommand::POSITION_MODE;
//names is a std::vector<std::string>
joint_cmd.names.push_back("right_e0");//Joint 1
joint_cmd.names.push_back("right_e1");//Joint 2
joint_cmd.names.push_back("right_s0");//Joint 3
joint_cmd.names.push_back("right_s1");//Joint 4
joint_cmd.names.push_back("right_w0");//Joint 5
joint_cmd.names.push_back("right_w1");//Joint 6
joint_cmd.names.push_back("right_w2");//Joint 7
//position is a std::vector<double>
joint_cmd.command.push_back(degree_to_radian(30.0));//Joint 1
joint_cmd.command.push_back(degree_to_radian(0.0));//Joint 2
joint_cmd.command.push_back(degree_to_radian(0.0));//Joint 3
joint_cmd.command.push_back(degree_to_radian(0.0));//Joint 4
joint_cmd.command.push_back(degree_to_radian(0.0));//Joint 5
joint_cmd.command.push_back(degree_to_radian(0.0));//Joint 6
joint_cmd.command.push_back(degree_to_radian(0.0));//Joint 7
//command the robot to move
joint_pub.publish(joint_cmd);
ros::spinOnce();
cout << joint_cmd << endl;
return 0;
}
The above code DOES NOT work. But when I put the publish method, inside a while (ros::ok())
loop in the following way, it works fine-
ros::Rate loop_rate(10);
while (ros::ok())
{
//command the robot to move
joint_pub.publish(joint_cmd);
ros::spinOnce();
loop_rate.sleep();
cout << joint_cmd << endl;
}
I was expecting to move the right arm and reach to the desired position in a single command. But it did not move in a single command. My question is that why we need to send the joint command multiple times? What is the reason behind this? More preciously, how many times a command must be published so that it executes?