test_controllers.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 
27 #include <string>
28 
30 {
31 }
32 
34 {
35 }
36 
38 {
39  hw = boost::shared_ptr<pr2_hardware_interface::HardwareInterface>(new pr2_hardware_interface::HardwareInterface());
40 
41  // add a fake FFJ3 actuator
43  actuator->state_.is_enabled_ = true;
44  hw->addActuator(actuator.get());
45 
46  robot = boost::shared_ptr<pr2_mechanism_model::Robot>(new pr2_mechanism_model::Robot(hw.get()));
47 
48  model = boost::shared_ptr<tinyxml2::XMLDocument>(new tinyxml2::XMLDocument());
49 
50  ros::NodeHandle rosnode;
51  std::string urdf_param_name;
52  std::string urdf_string;
53  // search and wait for robot_description on param server
54  while (urdf_string.empty())
55  {
56  ROS_DEBUG("Waiting for urdf: %s on the param server.", "sh_description");
57  if (rosnode.searchParam("sh_description", urdf_param_name))
58  {
59  rosnode.getParam(urdf_param_name, urdf_string);
60  ROS_DEBUG("found upstream\n%s\n------\n%s\n------\n%s", "sh_description", urdf_param_name.c_str(),
61  urdf_string.c_str());
62  }
63  else
64  {
65  rosnode.getParam("sh_description", urdf_string);
66  ROS_DEBUG("found in node namespace\n%s\n------\n%s\n------\n%s", "sh_description", urdf_param_name.c_str(),
67  urdf_string.c_str());
68  }
69  usleep(100000);
70  }
71  ROS_DEBUG("Parsing xml...");
72 
73  // initialize tinyxml2::XMLDocument doc with a string
74  if (!model->Parse(urdf_string.c_str()) && model->Error())
75  {
76  ROS_ERROR("Failed to parse urdf: %s\n",
77  urdf_string.c_str());
78  }
79  else
80  {
81  robot->initXml(model->RootElement());
82 
83  robot_state = boost::shared_ptr<pr2_mechanism_model::RobotState>(new pr2_mechanism_model::RobotState(robot.get()));
84 
85  joint_state = robot_state->getJointState("FFJ3");
86  joint_state->calibrated_ = true;
87 
89  controller->starting();
90 
91  // initialize the controller:
92  joint_state->position_ = 0.0;
93  controller->update();
94  }
95 }
96 
97 /* For the emacs weenies in the crowd.
98  Local Variables:
99  c-basic-offset: 2
100  End:
101 */
pr2_mechanism_model::JointState * joint_state
#define ROS_ERROR(...)
#define ROS_DEBUG(...)
boost::shared_ptr< tinyxml2::XMLDocument > model
boost::shared_ptr< pr2_mechanism_model::Robot > robot
boost::shared_ptr< pr2_mechanism_model::RobotState > robot_state
virtual ~TestControllers()
virtual void init_controller()=0
boost::shared_ptr< sr_actuator::SrMotorActuator > actuator
boost::shared_ptr< pr2_hardware_interface::HardwareInterface > hw


sr_mechanism_controllers
Author(s): Ugo Cupcic
autogenerated on Mon Feb 28 2022 23:52:31