joint_0_transmission_for_muscle.cpp
Go to the documentation of this file.
1 
29 #include <string>
30 
31 using std::string;
33 using ros_ethercat_model::RobotState;
34 using ros_ethercat_model::Transmission;
35 
36 PLUGINLIB_EXPORT_CLASS(sr_mechanism_model::J0TransmissionForMuscle, Transmission)
37 
38 namespace sr_mechanism_model
39 {
40 
41  bool J0TransmissionForMuscle::initXml(TiXmlElement *elt, RobotState *robot)
42  {
43  if (!SimpleTransmissionForMuscle::initXml(elt, robot))
44  {
45  return false;
46  }
47 
48  string joint2_name = joint_->joint_->name;
49  joint2_name[joint2_name.size() - 1] = '2';
50  joint2_ = robot->getJointState(joint2_name);
51 
52  return true;
53  }
54 
55  void J0TransmissionForMuscle::propagatePosition()
56  {
57  // the size is either 2 or 0 when the joint hasn't been updated yet
58  // (joint 0 is composed of the 2 calibrated values: joint 1 and joint 2)
59  SrMuscleActuator *act = static_cast<SrMuscleActuator *>(actuator_);
60  size_t size = act->muscle_state_.calibrated_sensor_values_.size();
61  if (size == 0)
62  {
63  ROS_DEBUG_STREAM("READING pos " << act->state_.position_
64  << " J1 " << act->muscle_state_.calibrated_sensor_values_[0]
65  << " J2 " << act->muscle_state_.calibrated_sensor_values_[1]);
66 
67  joint_->position_ = act->muscle_state_.calibrated_sensor_values_[0];
68  joint2_->position_ = act->muscle_state_.calibrated_sensor_values_[1];
69 
70  joint_->velocity_ = act->state_.velocity_ / 2.0;
71  joint2_->velocity_ = act->state_.velocity_ / 2.0;
72 
73  // We don't want to define a modified version of JointState, as that would imply using a modified version
74  // of robot_state.hpp, controller manager, ethercat_hardware and ros_etherCAT main loop
75  // So we will encode the two uint16_t that contain the data from the muscle pressure sensors
76  // into the double effort_. (We don't have any measured effort in the muscle hand anyway).
77  // Then in the joint controller we will decode that back into uint16_t.
78  joint_->effort_ = (static_cast<double>((act->muscle_state_.pressure_[1]) * 0x10000))
79  + static_cast<double>(act->muscle_state_.pressure_[0]);
80  joint2_->effort_ = (static_cast<double>((act->muscle_state_.pressure_[1]) * 0x10000))
81  + static_cast<double>(act->muscle_state_.pressure_[0]);
82  }
83  }
84 
85 } // namespace sr_mechanism_model
86 
87 /* For the emacs weenies in the crowd.
88 Local Variables:
89  c-basic-offset: 2
90 End:
91  */
SrMuscleActuatorState muscle_state_
This is the implementation of the transmission for the joint 0s. We need a specific transmission whic...
std::vector< double > calibrated_sensor_values_
#define ROS_DEBUG_STREAM(args)


sr_mechanism_model
Author(s): Ugo Cupcic
autogenerated on Tue Oct 13 2020 03:55:44