Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <moveit_sim_controller/moveit_sim_hw_interface.h>
00040
00041
00042 #include <rosparam_shortcuts/rosparam_shortcuts.h>
00043
00044 namespace moveit_sim_controller
00045 {
00046 MoveItSimHWInterface::MoveItSimHWInterface(ros::NodeHandle& nh, urdf::Model* urdf_model)
00047 : ros_control_boilerplate::SimHWInterface(nh, urdf_model), name_("moveit_sim_hw_interface")
00048 {
00049
00050 ros::NodeHandle rpnh(nh_, name_);
00051 std::size_t error = 0;
00052 error += !rosparam_shortcuts::get(name_, rpnh, "joint_model_group", joint_model_group_);
00053 error += !rosparam_shortcuts::get(name_, rpnh, "joint_model_group_pose", joint_model_group_pose_);
00054 rosparam_shortcuts::shutdownIfError(name_, error);
00055 }
00056
00057 void MoveItSimHWInterface::init()
00058 {
00059
00060 SimHWInterface::init();
00061
00062
00063 robot_model_loader_.reset(new robot_model_loader::RobotModelLoader(ROBOT_DESCRIPTION));
00064
00065
00066 loadDefaultJointValues();
00067
00068 ROS_INFO_STREAM_NAMED(name_, "MoveItSimHWInterface Ready.");
00069 }
00070
00071 void MoveItSimHWInterface::loadDefaultJointValues()
00072 {
00073
00074 robot_model::RobotModelPtr robot_model = robot_model_loader_->getModel();
00075
00076
00077 if (!robot_model->hasJointModelGroup(joint_model_group_))
00078 {
00079 ROS_WARN_STREAM_NAMED(name_, "Unable to find joint model group '" << joint_model_group_
00080 << "' for the fake controller manager");
00081 return;
00082 }
00083
00084 moveit::core::JointModelGroup* jmg = robot_model->getJointModelGroup(joint_model_group_);
00085
00086
00087 moveit::core::RobotState robot_state(robot_model);
00088
00089
00090 robot_state.setToDefaultValues();
00091
00092
00093 if (!robot_state.setToDefaultValues(jmg, joint_model_group_pose_))
00094 {
00095 ROS_WARN_STREAM_NAMED(name_, "Unable to find pose " << joint_model_group_pose_ << " for the fake controller "
00096 "manager");
00097 return;
00098 }
00099 ROS_INFO_STREAM_NAMED(name_, "Set joints to pose " << joint_model_group_pose_);
00100
00101 for (std::size_t i = 0; i < joint_names_.size(); ++i)
00102 {
00103 const moveit::core::JointModel* jm = robot_state.getJointModel(joint_names_[i]);
00104
00105
00106 if (!jm)
00107 {
00108 ROS_WARN_STREAM_NAMED(name_, "Unable to find joint model group: " << joint_names_[i]);
00109 continue;
00110 }
00111 if (jm->getVariableCount() != 1)
00112 {
00113 ROS_WARN_STREAM_NAMED(name_, "Fake joint controller does not currently accept more than 1 "
00114 "variable per joint");
00115 continue;
00116 }
00117
00118
00119 joint_position_[i] = robot_state.getJointPositions(jm)[0];
00120 joint_position_command_[i] = joint_position_[i];
00121
00122 if (std::isnan(joint_position_[i]))
00123 {
00124 ROS_ERROR_STREAM_NAMED(name_, "NaN found");
00125 std::cout << std::endl;
00126 std::cout << "i: " << i << " name: " << jm->getName() << std::endl;
00127 std::cout << "joint_model_group: " << jmg->getName() << std::endl;
00128 std::cout << "getVariableCount(): " << jm->getVariableCount() << std::endl;
00129 std::cout << "joint_position_[i]: " << joint_position_[i] << std::endl;
00130 std::cout << "joint_position_command_[i]: " << joint_position_command_[i] << std::endl;
00131 robot_state.printStateInfo();
00132 exit(-1);
00133 }
00134 }
00135 }
00136
00137 }