joint_0_transmission.cpp
Go to the documentation of this file.
1 
31 #include <string>
32 
33 using std::string;
35 using ros_ethercat_model::RobotState;
36 using ros_ethercat_model::Transmission;
37 
38 PLUGINLIB_EXPORT_CLASS(sr_mechanism_model::J0Transmission, Transmission)
39 
40 namespace sr_mechanism_model
41 {
42 
43  bool J0Transmission::initXml(TiXmlElement *elt, RobotState *robot)
44  {
45  if (!SimpleTransmission::initXml(elt, robot))
46  {
47  return false;
48  }
49 
50  string joint2_name = joint_->joint_->name;
51  joint2_name[joint2_name.size() - 1] = '2';
52  joint2_ = robot->getJointState(joint2_name);
53 
54  return true;
55  }
56 
57  void J0Transmission::propagatePosition()
58  {
59  // the size is either 2 or 0 when the joint hasn't been updated yet
60  // (joint 0 is composed of the 2 calibrated values: joint 1 and joint 2)
61 
62  SrMotorActuator *act = static_cast<SrMotorActuator *>(actuator_);
63  size_t size = act->motor_state_.calibrated_sensor_values_.size();
64  if (size == 2)
65  {
66  ROS_DEBUG_STREAM("READING pos " << act->state_.position_
67  << " J1 " << act->motor_state_.calibrated_sensor_values_[0]
68  << " J2 " << act->motor_state_.calibrated_sensor_values_[1]);
69 
70  joint_->position_ = act->motor_state_.calibrated_sensor_values_[0];
71  joint2_->position_ = act->motor_state_.calibrated_sensor_values_[1];
72 
73  joint_->velocity_ = act->state_.velocity_ / 2.0;
74  joint2_->velocity_ = act->state_.velocity_ / 2.0;
75 
76  joint_->effort_ = act->state_.last_measured_effort_;
77  joint2_->effort_ = act->state_.last_measured_effort_;
78  }
79  else if (size == 0)
80  {
81  ROS_DEBUG_STREAM("READING pos from Gazebo " << act->state_.position_
82  << " J1 " << act->state_.position_ / 2.0
83  << " J2 " << act->state_.position_ / 2.0);
84 
85  // use a real formula for the coupling??
86  // GAZEBO
87  joint_->position_ = act->state_.position_ / 2.0;
88  joint2_->position_ = act->state_.position_ / 2.0;
89 
90  joint_->velocity_ = act->state_.velocity_ / 2.0;
91  joint2_->velocity_ = act->state_.velocity_ / 2.0;
92 
93  joint_->effort_ = act->state_.last_measured_effort_ / 2.0;
94  joint2_->effort_ = act->state_.last_measured_effort_ / 2.0;
95  }
96  }
97 
98 } // namespace sr_mechanism_model
99 
100 /* For the emacs weenies in the crowd.
101 Local Variables:
102  c-basic-offset: 2
103 End:
104  */
std::vector< double > calibrated_sensor_values_
#define ROS_DEBUG_STREAM(args)
This is the implementation of the transmission for the joint 0s. We need a specific transmission whic...
SrMotorActuatorState motor_state_


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