ros-industrial / ur_modern_driver

(deprecated) ROS 1 driver for CB1 and CB2 controllers with UR5 or UR10 robots from Universal Robots
Apache License 2.0
301 stars 341 forks source link

How to control UR5 by ros_control method #376

Closed LQY-hust closed 3 years ago

LQY-hust commented 3 years ago

Hello, I used to use moveit to control ur5 and the package is useful,but now I want to use the control to control UR5. When I started the launch file with command"roslaunch ur_modern_driver ur5_ros_control".I modified the ip address and successfully connected to the robot,I can see some of the topics on ros, one of these topics is "/pos_based_pos_traj_controller/command" , I guess I should post messages(the type is trajectory_msgs::JointTrajectory) on this topic to control the robot, but it doesn't work. I don't know what's wrong with my code, please help me, Thanks. My code:

int main(int argc, char **argv) 
{
  ROS_INFO("test");
  ros::init(argc, argv,"test"); 
  ros::NodeHandle n2;
  ros::AsyncSpinner spinner(1);
  spinner.start();

  ros::Publisher pubJoints = n2.advertise<trajectory_msgs::JointTrajectory>("/pos_based_pos_traj_controller/command",100);
  trajectory_msgs::JointTrajectory Joints;
  trajectory_msgs::JointTrajectoryPoint joint;

  Joints.header.seq =0;
  ros::Time time;
  time = ros::Time::now();
  Joints.header.stamp = time;

  Joints.joint_names.resize(6);
  Joints.joint_names[0] ="shoulder_pan_joint";  
  Joints.joint_names[1] ="shoulder_lift_joint";
  Joints.joint_names[2] ="elbow_joint";
  Joints.joint_names[3] ="wrist_1_joint";
  Joints.joint_names[4] ="wrist_2_joint";
  Joints.joint_names[5] ="wrist_3_joint";

  Joints.points.reserve(10);
  joint.positions.resize(6);
  joint.velocities.resize(6);
  joint.accelerations.resize(6);
  joint.effort.resize(6);

  int i=0;
  for(i=0;i<10;i++)
  {

     joint.positions[0] = 0;
     joint.positions[1] = -1.57+0.01*i;
     joint.positions[2] = 0;
     joint.positions[3] = -1.57;
     joint.positions[4] = 0;
     joint.positions[5] = 0;
     joint.time_from_start.sec = (i-1)*1;
     Joints.points.push_back(joint);    
  }

  pubJoints.publish(Joints); 
  ros::shutdown();
  return 0;
}
gavanderhoorn commented 3 years ago

Please tell us what what sort of controller you have: CB2 or CB3, and what the version of system software is.

LQY-hust commented 3 years ago

Please tell us what what sort of controller you have: CB2 or CB3, and what the version of system software is.

I'm sorry I forgot to tell you, my robot is Cb3 , the version of system software is 3.3.1.237

gavanderhoorn commented 3 years ago

I'm sorry, but ur_modern_driver is deprecated when using a CB3. Please use Universal_Robots_ROS_Driver instead.

See #367.