2 #include "sensor_msgs/JointState.h" 4 #include "hebiros/AddGroupFromNamesSrv.h" 5 #include "hebiros/TrajectoryAction.h" 8 #define M_PI 3.14159265358979323846 11 #define M_PI_2 1.57079632679489661923 26 const TrajectoryResultConstPtr& result) {
27 std::cout <<
"Final state: " << state.
toString() << std::endl;
29 for (
int i = 0; i < result->final_state.name.size(); i++) {
30 std::cout << result->final_state.name[i] <<
": " << std::endl;
31 std::cout <<
" Position: " << result->final_state.position[i] << std::endl;
32 std::cout <<
" Velocity: " << result->final_state.velocity[i] << std::endl;
33 std::cout <<
" Effort: " << result->final_state.effort[i] << std::endl;
42 std:: cout <<
"Goal just went active" << std::endl;
48 std::cout <<
"Trajectory percent completion: " << feedback->percent_complete << std::endl;
52 int main(
int argc,
char **argv) {
55 ros::init(argc, argv,
"example_04_trajectory_node");
59 std::string group_name =
"my_group";
61 int num_waypoints = 5;
65 "/hebiros/add_group_from_names");
72 AddGroupFromNamesSrv add_group_srv;
75 add_group_srv.request.group_name = group_name;
76 add_group_srv.request.names = {
"base",
"shoulder",
"elbow"};
77 add_group_srv.request.families = {
"HEBI"};
80 while(!add_group_client.
call(add_group_srv)) {}
91 goal.times.resize(num_waypoints);
92 goal.waypoints.resize(num_waypoints);
95 waypoint.names.resize(num_joints);
96 waypoint.positions.resize(num_joints);
97 waypoint.velocities.resize(num_joints);
98 waypoint.accelerations.resize(num_joints);
100 double nan = std::numeric_limits<float>::quiet_NaN();
102 std::vector<double> times = {0, 5, 10, 15, 20};
103 std::vector<std::string> names = {
"HEBI/base",
"HEBI/shoulder",
"HEBI/elbow"};
106 std::vector<std::vector<double>> positions = {{
feedback.position[0], 0,
M_PI_2, 0, 0},
109 std::vector<std::vector<double>> velocities = {{0, nan, nan, nan, 0},
110 {0, nan, nan, nan, 0},
111 {0, nan, nan, nan, 0}};
112 std::vector<std::vector<double>> accelerations = {{0, nan, nan, nan, 0},
113 {0, nan, nan, nan, 0},
114 {0, nan, nan, nan, 0}};
117 for (
int i = 0; i < num_waypoints; i++) {
118 for (
int j = 0; j < num_joints; j++) {
119 waypoint.names[j] = names[j];
120 waypoint.positions[j] = positions[j][i];
121 waypoint.velocities[j] = velocities[j][i];
122 waypoint.accelerations[j] = accelerations[j][i];
124 goal.times[i] = times[i];
125 goal.waypoints[i] = waypoint;
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
bool waitForServer(const ros::Duration &timeout=ros::Duration(0, 0)) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void feedback_callback(sensor_msgs::JointState data)
sensor_msgs::JointState feedback
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
void trajectory_feedback(const TrajectoryFeedbackConstPtr &feedback)
std::string toString() const
int main(int argc, char **argv)
void sendGoal(const Goal &goal, SimpleDoneCallback done_cb=SimpleDoneCallback(), SimpleActiveCallback active_cb=SimpleActiveCallback(), SimpleFeedbackCallback feedback_cb=SimpleFeedbackCallback())
ROSCPP_DECL void shutdown()
void trajectory_done(const actionlib::SimpleClientGoalState &state, const TrajectoryResultConstPtr &result)
ROSCPP_DECL void spinOnce()