How to move a ur3 robot arm by using actions?
Dear community,
- I'm absolutely new to ROS, so please excuse my technically perhaps not always quite correct expressions.
- I'm running ROS Kinetic on Ubuntu 16.04 LTS and cloned the "universal robot" package from the following GitHub repository: (https://github.com/ros-industrial/uni...)
- After "building" my Catkin workspace
by typing
catkin_make
everything worked fine so far and I could successfully launch a simulation of an ur3 robot in Gazebo by typingroslaunch ur_gazebo ur3.launch
into a new terminal. - What i wanted to do now, was to
control the total of six joints of
the ur3 without using MoveIt. So i did some research and found the
following Link: Moving the arm
using the Joint Trajectory Action
So basically I wanted to try to control the
ur3 in the Gazebo simulation via an
action client. Since the
description in the link above did
not exactly fit to my robot, I tried to adapt
the
simple_trajectory.cpp
file written there to the ur3 robot.
My "adapted" code file (without the included headers) now looks like shown below.
(The libraries I included by writing #include
are the following: <ros/ros.h>
; <control_msgs/FollowJointTrajectoryAction.h>
and <actionlib/client/simple_action_client.h
)
typedef actionlib::SimpleActionClient <control_msgs::FollowJointTrajectoryAction> TrajClient;
class Ur3Arm
{
private:
// Action client for the follow joint trajectory action used to trigger the arm movement action
TrajClient* traj_client_;
public:
// Initialize the action client and wait for action server to come up.
Ur3Arm()
{
// Tell the action client that we want to spin a thread by default:
traj_client_ = new TrajClient("arm_controller/follow_joint_trajectory_action", true);
// Wait for the action server to come up
while(!traj_client_->waitForServer(ros::Duration(5.0)))
{
ROS_INFO("Wait for the follow_joint_trajectory_action server");
}
}
// Clean up the action client
// -> Destructor of class Ur3Arm
~Ur3Arm()
{
delete traj_client_;
}
// Send the command to start a given trajectory
void startTrajectory(control_msgs::FollowJointTrajectoryGoal goal)
{
// When to start the trajectory: 1s from now
goal.trajectory.header.stamp = ros::Time::now() + ros::Duration(1.0);
traj_client_->sendGoal(goal);
}
// Generates a simple trajectory with two waypoints, used as an example
/* Note that this trajectory contains two waypoints, joined together as a single trajectory.
Alternatively, each of these waypoints could be in its own trajectory - a trajectory can have one
or more waypoints depending on the desired application.
*/
control_msgs::FollowJointTrajectoryGoal armExtensionTrajectory()
{
// The goal variable:
control_msgs::FollowJointTrajectoryGoal goal;
// First, the joint names, which apply to all waypoints
goal.trajectory.joint_names.resize(1);
goal.trajectory.joint_names.push_back("shoulder_pan_joint");
goal.trajectory.joint_names.push_back("shoulder_lift_joint");
goal.trajectory.joint_names.push_back("elbow_joint");
goal.trajectory.joint_names.push_back("wrist_1_joint");
goal.trajectory.joint_names.push_back("wrist_2_joint");
goal.trajectory.joint_names.push_back("wrist_3_joint");
// In this simple case there asre only two waypoints in this goal trajectory
goal.trajectory.points.resize(2);
// First trajectory waypoint
int ind = 0; // Represents the number of the actual waypoint
// Positions:
goal.trajectory.points[ind].positions.resize(6);
goal.trajectory.points[ind].positions[0] = 0.0;
goal.trajectory.points[ind].positions[1] = 0.0;
goal.trajectory.points[ind].positions[2] = 0.0;
goal.trajectory.points[ind].positions[3] = 0.0;
goal.trajectory.points ...
Please do not post answers, unless you are answering your own questions.
For interacting with other posters, please use comments, or edit your original question to add a section to it. Use the
edit
button/link for that.