UTNuclearRoboticsPublic / jog_arm

A real-time robot arm jogger.
45 stars 22 forks source link

Failed to use if condition to process the received message in my callback function in spaceanv_to_twist.cpp #97

Closed stevensu1838 closed 5 years ago

stevensu1838 commented 5 years ago

Hi Andy, I am using your spaceto twist node to subscribe Twist message and convert it into Timestamped message. Also, In order not to make the robot freeze, I want to make sure all the message that I assigned to Timestamped message is smaller than 0.05 and please take a look at the following snippet of code for this purpose. However, when I print the message with ROS_ERROR() , some of the messages are still larger than 0.05(It make the robot freeze). Could you please tell me why? Thanks a lot.

void joyCallback(const geometry_msgs::Twist::ConstPtr& msg)
  {

// Cartesian jogging with the axes
geometry_msgs::TwistStamped twist;
twist.header.stamp = ros::Time::now();
if (msg->linear.x < 0.05 ){
    twist.twist.linear.x = msg->linear.x;}
if (msg->linear.x >= 0.05 ){
    twist.twist.linear.x = 0.05;}

if (msg->linear.y < 0.05 ){          
    twist.twist.linear.y = msg->linear.y;}

if (msg->linear.y >= 0.05 ){          
    twist.twist.linear.y = 0.05;}

if (msg->linear.z < 0.05 ){           
    twist.twist.linear.z = msg->linear.z;}

if (msg->linear.z >= 0.05 ){           
    twist.twist.linear.z = 0.05;}

    ROS_ERROR("Hello %s", "World");
    ROS_ERROR("Hello %f", twist.twist.linear.x);
    ROS_ERROR("Hello %f", twist.twist.linear.y);
    ROS_ERROR("Hello %f", twist.twist.linear.z);

twist.twist.angular.x = 0;
twist.twist.angular.y = 0;
twist.twist.angular.z = 0;

// Joint jogging with the buttons
jog_msgs::JogJoint joint_deltas;
// This example is for a Motoman SIA5. joint_s is the base joint.
joint_deltas.joint_names.push_back("joint_s");

// Button 0: positive on the wrist joint
// Button 1: negative on the wrist joint
//joint_deltas.deltas.push_back(msg->buttons[0] - msg->buttons[1]);
joint_deltas.header.stamp = ros::Time::now();

twist_pub_.publish(twist);
joint_delta_pub_.publish(joint_deltas);
  }
AndyZe commented 5 years ago

You need to think about negatives, too. What is going to happen here:

if (msg->linear.x < 0.05 ){ twist.twist.linear.x = msg->linear.x;}

if msg->linear.x is -0.06