-
Notifications
You must be signed in to change notification settings - Fork 320
/
kinova_arm.cpp
708 lines (610 loc) · 25.3 KB
/
kinova_arm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
//============================================================================
// Name : kinova_arm.cpp
// Author : WPI, Clearpath Robotics
// Version : 0.5
// Copyright : BSD
// Description : A ROS driver for controlling the Kinova Kinova robotic manipulator arm
//============================================================================
#include "kinova_driver/kinova_arm.h"
#include <string>
#include <boost/lexical_cast.hpp>
#include <kinova_driver/kinova_ros_types.h>
namespace
{
/// \brief Convert Kinova-specific angle degree variations (0..180, 360-181) to
/// a more regular representation (0..180, -180..0).
inline void convertKinDeg(double& qd)
{
static const double PI_180 = (M_PI / 180.0);
// Angle velocities from the API are 0..180 for positive values,
// and 360..181 for negative ones, in a kind of 2-complement setup.
if (qd > 180.0) {
qd -= 360.0;
}
qd *= PI_180;
}
inline void convertKinDeg(std::vector<double>& qds)
{
for (int i = 0; i < qds.size(); ++i) {
double& qd = qds[i];
convertKinDeg(qd);
}
}
inline void convertKinDeg(geometry_msgs::Vector3& qds)
{
convertKinDeg(qds.x);
convertKinDeg(qds.y);
convertKinDeg(qds.z);
}
}
namespace kinova
{
KinovaArm::KinovaArm(KinovaComm &arm, const ros::NodeHandle &nodeHandle, const std::string &kinova_robotType)
: kinova_comm_(arm), node_handle_(nodeHandle), kinova_robotType_(kinova_robotType)
{
for (int i=0;i<COMMAND_SIZE;i++)
{
l_joint_torque_[i] = 0;
l_force_cmd_[i] = 0;
}
//multiple arms
if (node_handle_.hasParam("/kinova_robots"))
{
XmlRpc::XmlRpcValue robot_list;
node_handle_.getParam("/kinova_robots", robot_list);
if (robot_list.getType() != XmlRpc::XmlRpcValue::TypeArray)
{
ROS_ERROR("Parameter controller_list should be specified as an array");
return;
}
robots_.resize(robot_list.size());
for (int i = 0; i < robot_list.size(); ++i)
{
if (!robot_list[i].hasMember("name") || !robot_list[i].hasMember("serial"))
{
ROS_ERROR_STREAM("Name and serial must be specifed for each robot");
continue;
}
robots_[i].name = std::string(robot_list[i]["name"]);
robots_[i].name = std::string(robot_list[i]["type"]);
robots_[i].name = std::string(robot_list[i]["serial"]);
}
}
/* Set up parameters for different robot type */
// example for a kinova_robotType: j2n6s300
if (valid_kinovaRobotType(kinova_robotType_) == false)
{
ROS_WARN("Invalid kinova_robotType error! Obtained: %s.", kinova_robotType_.c_str());
return;
}
// tf_prefix_ = kinova_robotType_ + "_" + boost::lexical_cast<string>(same_type_index); // in case of multiple same_type robots
tf_prefix_ = kinova_robotType_ + "_";
// Maximum number of joints on Kinova-like robots:
robot_category_ = kinova_robotType_[0];
robot_category_version_ = kinova_robotType_[1]-'0';
wrist_type_ = kinova_robotType_[2];
arm_joint_number_ = kinova_robotType_[3]-'0';
robot_mode_ = kinova_robotType_[4];
finger_number_ = kinova_robotType_[5]-'0';
joint_total_number_ = arm_joint_number_ + finger_number_;
if (robot_category_=='j') // jaco robot
{
// special parameters for jaco
if (arm_joint_number_ == 6)
{
if (wrist_type_ == 'n')
robot_type_ = JACOV2_6DOF_SERVICE;
else
robot_type_ = SPHERICAL_6DOF_SERVICE;
}
else if (arm_joint_number_ == 4)
{
robot_type_ = JACOV2_4DOF_SERVICE;
}
else if (arm_joint_number_ == 7)
{
robot_type_ = SPHERICAL_7DOF_SERVICE;
}
}
else if (robot_category_ == 'm') // mico robot
{
// special parameters for mico
if (arm_joint_number_ == 6)
robot_type_ = MICO_6DOF_SERVICE;
else if (arm_joint_number_ == 4)
robot_type_ = MICO_4DOF_SERVICE;
}
else if (robot_category_ == 'r') // roco robot
{
// special parameters for roco
}
else
{
// special parameters for custom robot or other cases
}
if (finger_number_==3)
{
// finger_angle_conv_ratio used to display finger position properly in Rviz
// Approximative conversion ratio from finger position (0..6400) to joint angle
// in radians (0.. 1.4) for 3 finger hand
finger_conv_ratio_= 1.4 / 6400.0;
}
else if(finger_number_==2)
{
// the two finger hand may different
finger_conv_ratio_= 1.4 / 6400.0;
}
else
{
// no fingers
}
for (int i = 0; i<arm_joint_number_; i++)
{
joint_names_.resize(joint_total_number_);
joint_names_[i] = tf_prefix_ + "joint_" + boost::lexical_cast<std::string>(i+1);
}
for (int i = 0; i<finger_number_; i++)
{
joint_names_[arm_joint_number_+i] = tf_prefix_ + "joint_finger_" + boost::lexical_cast<std::string>(i+1);
}
/* Set up Services */
stop_service_ = node_handle_.advertiseService("in/stop", &KinovaArm::stopServiceCallback, this);
start_service_ = node_handle_.advertiseService("in/start", &KinovaArm::startServiceCallback, this);
homing_service_ = node_handle_.advertiseService("in/home_arm", &KinovaArm::homeArmServiceCallback, this);
add_trajectory_ = node_handle_.advertiseService("in/add_pose_to_Cartesian_trajectory",
&KinovaArm::addCartesianPoseToTrajectory, this);
clear_trajectories_ = node_handle_.advertiseService("in/clear_trajectories",
&KinovaArm::clearTrajectoriesServiceCallback, this);
set_force_control_params_service_ = node_handle_.advertiseService("in/set_force_control_params", &KinovaArm::setForceControlParamsCallback, this);
start_force_control_service_ = node_handle_.advertiseService("in/start_force_control", &KinovaArm::startForceControlCallback, this);
stop_force_control_service_ = node_handle_.advertiseService("in/stop_force_control", &KinovaArm::stopForceControlCallback, this);
set_actuator_torques_to_zero_ = node_handle_.advertiseService(
"in/set_zero_torques", &KinovaArm::setJointTorquesToZeroService, this);
run_COM_parameter_estimation_service_ = node_handle_.advertiseService(
"in/run_COM_parameters_estimation",
&KinovaArm::runCOMParameterEstimationService,this);
set_end_effector_offset_service_ = node_handle_.advertiseService("in/set_end_effector_offset",
&KinovaArm::setEndEffectorOffsetCallback, this);
start_null_space_service_ = node_handle_.advertiseService("in/set_null_space_mode_state", &KinovaArm::ActivateNullSpaceModeCallback, this);
set_torque_control_mode_service_ = node_handle_.advertiseService("in/set_torque_control_mode", &KinovaArm::setTorqueControlModeService, this);
set_torque_control_parameters_service_ = node_handle_.advertiseService
("in/set_torque_control_parameters",
&KinovaArm::setTorqueControlParametersService,this);
/* Set up Publishers */
joint_angles_publisher_ = node_handle_.advertise<kinova_msgs::JointAngles>
("out/joint_angles", 2);
joint_torque_publisher_ = node_handle_.advertise<kinova_msgs::JointAngles>
("out/joint_torques", 2);
joint_state_publisher_ = node_handle_.advertise<sensor_msgs::JointState>
("out/joint_state", 2);
tool_position_publisher_ = node_handle_.advertise<geometry_msgs::PoseStamped>
("out/tool_pose", 2);
tool_wrench_publisher_ = node_handle_.advertise<geometry_msgs::WrenchStamped>
("out/tool_wrench", 2);
finger_position_publisher_ = node_handle_.advertise<kinova_msgs::FingerPosition>
("out/finger_position", 2);
// Publish last command for relative motion (read current position cause arm drop)
joint_command_publisher_ = node_handle_.advertise<kinova_msgs::JointAngles>("out/joint_command", 2);
cartesian_command_publisher_ = node_handle_.advertise<kinova_msgs::KinovaPose>("out/cartesian_command", 2);
/* Set up Subscribers*/
joint_velocity_subscriber_ = node_handle_.subscribe("in/joint_velocity", 1,
&KinovaArm::jointVelocityCallback, this);
cartesian_velocity_subscriber_ = node_handle_.subscribe("in/cartesian_velocity", 1,
&KinovaArm::cartesianVelocityCallback, this);
joint_torque_subscriber_ = node_handle_.subscribe("in/joint_torque", 1,
&KinovaArm::jointTorqueSubscriberCallback, this);
cartesian_force_subscriber_ = node_handle_.subscribe("in/cartesian_force", 1,
&KinovaArm::forceSubscriberCallback, this);
node_handle_.param<double>("status_interval_seconds", status_interval_seconds_, 0.1);
// Depending on the API version, the arm might return velocities in the
// 0..360 range (0..180 for positive values, 181..360 for negative ones).
// This indicates that the ROS node should convert them first before
// updating the joint_state topic.
node_handle_.param("convert_joint_velocities", convert_joint_velocities_, true);
status_timer_ = node_handle_.createTimer(ros::Duration(status_interval_seconds_),
&KinovaArm::statusTimer, this);
ROS_INFO("The arm is ready to use.");
}
KinovaArm::~KinovaArm()
{
}
bool KinovaArm::homeArmServiceCallback(kinova_msgs::HomeArm::Request &req, kinova_msgs::HomeArm::Response &res)
{
kinova_comm_.homeArm();
kinova_comm_.initFingers();
res.homearm_result = "KINOVA ARM HAS BEEN RETURNED HOME";
return true;
}
bool KinovaArm::ActivateNullSpaceModeCallback(kinova_msgs::SetNullSpaceModeState::Request &req, kinova_msgs::SetNullSpaceModeState::Response &res)
{
kinova_comm_.SetRedundantJointNullSpaceMotion(req.state);
}
bool KinovaArm::setTorqueControlModeService(kinova_msgs::SetTorqueControlMode::Request &req, kinova_msgs::SetTorqueControlMode::Response &res)
{
kinova_comm_.SetTorqueControlState(req.state);
}
bool KinovaArm::setTorqueControlParametersService(kinova_msgs::SetTorqueControlParameters::Request &req, kinova_msgs::SetTorqueControlParameters::Response &res)
{
float safetyFactor;
node_handle_.param<float>("torque_parameters/safety_factor", safetyFactor,1.0);
kinova_comm_.setToquesControlSafetyFactor(safetyFactor);
std::vector<float> payload;
if (node_handle_.getParam("payload", payload))
{
kinova_comm_.setPayload(payload);
}
std::vector<float> min_torque, max_torque;
if (node_handle_.getParam("torque_parameters/torque_min", min_torque)
&& node_handle_.getParam("torque_parameters/torque_max", max_torque))
{
AngularInfo min_torque_info,max_torque_info;
//since fist 7 members of the struct are float we assume no padding
//and use float pointer to access struct elements
float *min_torque_actuator = &(min_torque_info.Actuator1);
float *max_torque_actuator = &(max_torque_info.Actuator1);
for (int i = 0; i<min_torque.size(); i++)
{
min_torque_actuator[i] = min_torque.at(i);
max_torque_actuator[i] = max_torque.at(i);
}
kinova_comm_.setJointTorqueMinMax(min_torque_info,max_torque_info);
}
std::vector<float> com_parameters;
if (node_handle_.getParam("torque_parameters/com_parameters", com_parameters))
{
bool use_estimated_COM;
node_handle_.param("torque_parameters/use_estimated_COM_parameters",
use_estimated_COM,true);
if (use_estimated_COM == true)
kinova_comm_.setRobotCOMParam(OPTIMAL,com_parameters);
else
kinova_comm_.setRobotCOMParam(MANUAL_INPUT,com_parameters);
}
}
void KinovaArm::jointVelocityCallback(const kinova_msgs::JointVelocityConstPtr& joint_vel)
{
if (!kinova_comm_.isStopped())
{
joint_velocities_.Actuator1 = joint_vel->joint1;
joint_velocities_.Actuator2 = joint_vel->joint2;
joint_velocities_.Actuator3 = joint_vel->joint3;
joint_velocities_.Actuator4 = joint_vel->joint4;
joint_velocities_.Actuator5 = joint_vel->joint5;
joint_velocities_.Actuator6 = joint_vel->joint6;
joint_velocities_.Actuator7 = joint_vel->joint7;
kinova_comm_.setJointVelocities(joint_velocities_);
}
}
void KinovaArm::jointTorqueSubscriberCallback(const kinova_msgs::JointTorqueConstPtr& joint_torque)
{
if (!kinova_comm_.isStopped())
{
l_joint_torque_[0] = joint_torque->joint1;
l_joint_torque_[1] = joint_torque->joint2;
l_joint_torque_[2] = joint_torque->joint3;
l_joint_torque_[3] = joint_torque->joint4;
l_joint_torque_[4] = joint_torque->joint5;
l_joint_torque_[5] = joint_torque->joint6;
l_joint_torque_[6] = joint_torque->joint7;
kinova_comm_.setJointTorques(l_joint_torque_);
}
}
void KinovaArm::forceSubscriberCallback(const kinova_msgs::CartesianForceConstPtr& force)
{
if (!kinova_comm_.isStopped())
{
l_force_cmd_[0] = force->force_x;
l_force_cmd_[1] = force->force_y;
l_force_cmd_[2] = force->force_z;
l_force_cmd_[3] = force->torque_x;
l_force_cmd_[4] = force->torque_y;
l_force_cmd_[5] = force->torque_z;
kinova_comm_.sendCartesianForceCommand(l_force_cmd_);
}
}
/*!
* \brief Handler for "stop" service.
*
* Instantly stops the arm and prevents further movement until start service is
* invoked.
*/
bool KinovaArm::stopServiceCallback(kinova_msgs::Stop::Request &req, kinova_msgs::Stop::Response &res)
{
kinova_comm_.stopAPI();
res.stop_result = "Arm stopped";
ROS_DEBUG("Arm stop requested");
return true;
}
/*!
* \brief Handler for "start" service.
*
* Re-enables control of the arm after a stop.
*/
bool KinovaArm::startServiceCallback(kinova_msgs::Start::Request &req, kinova_msgs::Start::Response &res)
{
kinova_comm_.startAPI();
res.start_result = "Arm started";
ROS_DEBUG("Arm start requested");
return true;
}
bool KinovaArm::addCartesianPoseToTrajectory(kinova_msgs::AddPoseToCartesianTrajectory::Request &req,
kinova_msgs::AddPoseToCartesianTrajectory::Response &res)
{
KinovaPose pose;
pose.X = req.X;
pose.Y = req.Y;
pose.Z = req.Z;
pose.ThetaX = req.ThetaX;
pose.ThetaY = req.ThetaY;
pose.ThetaZ = req.ThetaZ;
kinova_comm_.setCartesianPosition(pose,false);
}
bool KinovaArm::clearTrajectoriesServiceCallback(
kinova_msgs::ClearTrajectories::Request &req,
kinova_msgs::ClearTrajectories::Response &res)
{
kinova_comm_.eraseAllTrajectories();
}
bool KinovaArm::setForceControlParamsCallback(
kinova_msgs::SetForceControlParams::Request &req,
kinova_msgs::SetForceControlParams::Response &res)
{
CartesianInfo inertia, damping, force_min, force_max;
inertia.X = req.inertia_linear.x;
inertia.Y = req.inertia_linear.y;
inertia.Z = req.inertia_linear.z;
inertia.ThetaX = req.inertia_angular.x;
inertia.ThetaY = req.inertia_angular.y;
inertia.ThetaZ = req.inertia_angular.z;
damping.X = req.damping_linear.x;
damping.Y = req.damping_linear.y;
damping.Z = req.damping_linear.z;
damping.ThetaX = req.damping_angular.x;
damping.ThetaY = req.damping_angular.y;
damping.ThetaZ = req.damping_angular.z;
kinova_comm_.setCartesianInertiaDamping(inertia, damping);
force_min.X = req.force_min_linear.x;
force_min.Y = req.force_min_linear.y;
force_min.Z = req.force_min_linear.z;
force_min.ThetaX = req.force_min_angular.x;
force_min.ThetaY = req.force_min_angular.y;
force_min.ThetaZ = req.force_min_angular.z;
force_max.X = req.force_max_linear.x;
force_max.Y = req.force_max_linear.y;
force_max.Z = req.force_max_linear.z;
force_max.ThetaX = req.force_max_angular.x;
force_max.ThetaY = req.force_max_angular.y;
force_max.ThetaZ = req.force_max_angular.z;
kinova_comm_.setCartesianForceMinMax(force_min, force_max);
return true;
}
bool KinovaArm::startForceControlCallback(kinova_msgs::Start::Request &req, kinova_msgs::Start::Response &res)
{
kinova_comm_.startForceControl();
res.start_result = "Start force control requested.";
return true;
}
bool KinovaArm::stopForceControlCallback(kinova_msgs::Stop::Request &req, kinova_msgs::Stop::Response &res)
{
kinova_comm_.stopForceControl();
res.stop_result = "Stop force control requested.";
return true;
}
bool KinovaArm::setJointTorquesToZeroService(kinova_msgs::ZeroTorques::Request &req,
kinova_msgs::ZeroTorques::Response &res)
{
kinova_comm_.setZeroTorque();
return true;
}
bool KinovaArm::runCOMParameterEstimationService(
kinova_msgs::RunCOMParametersEstimation::Request &req,
kinova_msgs::RunCOMParametersEstimation::Response &res)
{
kinova_comm_.runCOMParameterEstimation(robot_type_);
}
bool KinovaArm::setEndEffectorOffsetCallback(kinova_msgs::SetEndEffectorOffset::Request &req, kinova_msgs::SetEndEffectorOffset::Response &res)
{
kinova_comm_.setEndEffectorOffset(req.status, req.offset.x, req.offset.y, req.offset.z);
return true;
}
void KinovaArm::cartesianVelocityCallback(const kinova_msgs::PoseVelocityConstPtr& cartesian_vel)
{
if (!kinova_comm_.isStopped())
{
cartesian_velocities_.X = cartesian_vel->twist_linear_x;
cartesian_velocities_.Y = cartesian_vel->twist_linear_y;
cartesian_velocities_.Z = cartesian_vel->twist_linear_z;
cartesian_velocities_.ThetaX = cartesian_vel->twist_angular_x;
cartesian_velocities_.ThetaY = cartesian_vel->twist_angular_y;
cartesian_velocities_.ThetaZ = cartesian_vel->twist_angular_z;
// orientation velocity of cartesian_velocities_ is based on twist.angular
kinova_comm_.setCartesianVelocities(cartesian_velocities_);
}
}
/*!
* \brief Publishes the current joint angles.
*
* Joint angles are published in both their raw state as obtained from the arm
* (JointAngles), and transformed & converted to radians (joint_state) as per
* the Kinova Kinematics PDF.
*
* Velocities and torques (effort) are only published in the JointStates
* message, only for the first 6 joints as these values are not available for
* the fingers.
*/
void KinovaArm::publishJointAngles(void)
{
FingerAngles fingers;
kinova_comm_.getFingerPositions(fingers);
if (arm_joint_number_ != 4 && arm_joint_number_ != 6 && arm_joint_number_ != 7)
{
ROS_WARN_ONCE("The joint_state publisher only supports 4, 6 and 7 DOF for now.: %d", arm_joint_number_);
}
// Query arm for current joint angles
KinovaAngles current_angles;
kinova_comm_.getJointAngles(current_angles);
kinova_msgs::JointAngles kinova_angles = current_angles.constructAnglesMsg();
AngularPosition joint_command;
kinova_comm_.getAngularCommand(joint_command);
kinova_msgs::JointAngles joint_command_msg = KinovaAngles(joint_command.Actuators).constructAnglesMsg();
sensor_msgs::JointState joint_state;
joint_state.name = joint_names_;
joint_state.header.stamp = ros::Time::now();
// Transform from Kinova DH algorithm to physical angles in radians, then place into vector array
joint_state.position.resize(joint_total_number_);
joint_state.position[0] = kinova_angles.joint1 * M_PI/180;
joint_state.position[1] = kinova_angles.joint2 * M_PI/180;
joint_state.position[2] = kinova_angles.joint3 * M_PI/180;
joint_state.position[3] = kinova_angles.joint4 * M_PI/180;
if (arm_joint_number_ >= 6)
{
joint_state.position[4] = kinova_angles.joint5 * M_PI/180;
joint_state.position[5] = kinova_angles.joint6 * M_PI/180;
}
if (arm_joint_number_ == 7)
{
joint_state.position[6] = kinova_angles.joint7 * M_PI/180;
}
if(finger_number_==2)
{
joint_state.position[joint_total_number_-2] = fingers.Finger1/6800*80*M_PI/180;
joint_state.position[joint_total_number_-1] = fingers.Finger2/6800*80*M_PI/180;
}
else if(finger_number_==3)
{
joint_state.position[joint_total_number_-3] = fingers.Finger1/6800*80*M_PI/180;
joint_state.position[joint_total_number_-2] = fingers.Finger2/6800*80*M_PI/180;
joint_state.position[joint_total_number_-1] = fingers.Finger3/6800*80*M_PI/180;
}
// Joint velocities
KinovaAngles current_vels;
kinova_comm_.getJointVelocities(current_vels);
joint_state.velocity.resize(joint_total_number_);
joint_state.velocity[0] = current_vels.Actuator1;
joint_state.velocity[1] = current_vels.Actuator2;
joint_state.velocity[2] = current_vels.Actuator3;
joint_state.velocity[3] = current_vels.Actuator4;
// no velocity info for fingers
if(finger_number_==2)
{
joint_state.velocity[joint_total_number_-2] = 0;
joint_state.velocity[joint_total_number_-1] = 0;
}
else if(finger_number_==3)
{
joint_state.velocity[joint_total_number_-3] = 0;
joint_state.velocity[joint_total_number_-2] = 0;
joint_state.velocity[joint_total_number_-1] = 0;
}
if (arm_joint_number_ >= 6)
{
joint_state.velocity[4] = current_vels.Actuator5;
joint_state.velocity[5] = current_vels.Actuator6;
}
if (arm_joint_number_ == 7)
{
joint_state.velocity[6] = current_vels.Actuator7;
}
// ROS_DEBUG_THROTTLE(0.1,
// "Raw joint velocities: %f %f %f %f %f %f",
// current_vels.Actuator1,
// current_vels.Actuator2,
// current_vels.Actuator3,
// current_vels.Actuator4,
// current_vels.Actuator5,
// current_vels.Actuator6);
if (convert_joint_velocities_) {
convertKinDeg(joint_state.velocity);
}
// Joint torques (effort)
KinovaAngles joint_tqs;
bool gravity_comp;
node_handle_.param("torque_parameters/publish_torque_with_gravity_compensation", gravity_comp, false);
if (gravity_comp==true)
kinova_comm_.getGravityCompensatedTorques(joint_tqs);
else
kinova_comm_.getJointTorques(joint_tqs);
joint_torque_publisher_.publish(joint_tqs.constructAnglesMsg());
joint_state.effort.resize(joint_total_number_);
joint_state.effort[0] = joint_tqs.Actuator1;
joint_state.effort[1] = joint_tqs.Actuator2;
joint_state.effort[2] = joint_tqs.Actuator3;
joint_state.effort[3] = joint_tqs.Actuator4;
// no effort info for fingers
if(finger_number_==2)
{
joint_state.effort[joint_total_number_-2] = 0;
joint_state.effort[joint_total_number_-1] = 0;
}
else if(finger_number_==3)
{
joint_state.effort[joint_total_number_-3] = 0;
joint_state.effort[joint_total_number_-2] = 0;
joint_state.effort[joint_total_number_-1] = 0;
}
if (arm_joint_number_ >= 6)
{
joint_state.effort[4] = joint_tqs.Actuator5;
joint_state.effort[5] = joint_tqs.Actuator6;
}
if (arm_joint_number_ == 7)
{
joint_state.effort[6] = joint_tqs.Actuator7;
}
joint_angles_publisher_.publish(kinova_angles);
joint_command_publisher_.publish(joint_command_msg);
joint_state_publisher_.publish(joint_state);
}
/*!
* \brief Publishes the current cartesian coordinates
*/
void KinovaArm::publishToolPosition(void)
{
KinovaPose pose;
geometry_msgs::PoseStamped current_position;
kinova_comm_.getCartesianPosition(pose);
CartesianPosition cartesian_command;
kinova_comm_.getCartesianCommand(cartesian_command);
kinova_msgs::KinovaPose cartesian_command_msg = KinovaPose(cartesian_command.Coordinates).constructKinovaPoseMsg();
current_position.pose = pose.constructPoseMsg();
current_position.header.stamp = ros::Time::now();
current_position.header.frame_id = tf_prefix_ + "link_base";
tool_position_publisher_.publish(current_position);
cartesian_command_publisher_.publish(cartesian_command_msg);
}
/*!
* \brief Publishes the current cartesian forces at the end effector.
*/
void KinovaArm::publishToolWrench(void)
{
KinovaPose wrench;
geometry_msgs::WrenchStamped current_wrench;
kinova_comm_.getCartesianForce(wrench);
current_wrench.wrench = wrench.constructWrenchMsg();
current_wrench.header.stamp = ros::Time::now();
// TODO: Rotate wrench to fit the end effector frame.
// Right now, the orientation of the wrench is in the API's (base) frame.
current_wrench.header.frame_id = tf_prefix_ + "link_base";
// Same conversion issue as with velocities:
if (convert_joint_velocities_) {
convertKinDeg(current_wrench.wrench.torque);
}
tool_wrench_publisher_.publish(current_wrench);
}
/*!
* \brief Publishes the current finger positions.
*/
void KinovaArm::publishFingerPosition(void)
{
FingerAngles fingers;
kinova_comm_.getFingerPositions(fingers);
finger_position_publisher_.publish(fingers.constructFingersMsg());
}
void KinovaArm::statusTimer(const ros::TimerEvent&)
{
publishJointAngles();
publishToolPosition();
publishToolWrench();
publishFingerPosition();
}
} // namespace kinova