joint_0_transmission.cpp
Go to the documentation of this file.
1 /*
2 * Copyright 2011 Shadow Robot Company Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16 
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(tinyxml2::XMLElement *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 
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  */
bool initXml(tinyxml2::XMLElement *config, ros_ethercat_model::RobotState *robot)
ros_ethercat_model::JointState * joint2_
bool initXml(tinyxml2::XMLElement *config, ros_ethercat_model::RobotState *robot)
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 Mon Feb 28 2022 23:52:12