34 #include <std_msgs/Float64.h> 35 #include <std_srvs/Empty.h> 37 #include <gazebo_msgs/SetModelConfiguration.h> 46 ROS_INFO(
"This ROS interface is built for Gazebo.");
49 std::string searched_param;
52 n_tilde.searchParam(
"gazebo_joint_states_prefix", searched_param);
53 n_tilde.param(searched_param, prefix, std::string());
54 std::string full_topic = prefix +
"joint_states";
55 gazebo_subscriber = node.subscribe(full_topic, 2, &VirtualArm::gazeboCallback,
this);
57 ROS_INFO(
"This ROS interface is not built for Gazebo.");
74 std::string topic_prefix =
"/";
75 std::string topic_suffix =
"/command";
76 std::string full_topic =
"";
82 full_topic = topic_prefix +
"sa_sr_position_controller" + topic_suffix;
83 gazebo_publishers.push_back(node.advertise<std_msgs::Float64>(full_topic, 2));
91 full_topic = topic_prefix +
"sa_ss_position_controller" + topic_suffix;
92 gazebo_publishers.push_back(node.advertise<std_msgs::Float64>(full_topic, 2));
100 full_topic = topic_prefix +
"sa_es_position_controller" + topic_suffix;
101 gazebo_publishers.push_back(node.advertise<std_msgs::Float64>(full_topic, 2));
109 full_topic = topic_prefix +
"sa_er_position_controller" + topic_suffix;
110 gazebo_publishers.push_back(node.advertise<std_msgs::Float64>(full_topic, 2));
126 ros::ServiceClient gazebo_phys_client = node.serviceClient<std_srvs::Empty>(
"/gazebo/pause_physics");
127 std_srvs::Empty empty_srv;
129 gazebo_phys_client.
call(empty_srv);
132 ros::ServiceClient set_pos_client = node.serviceClient<gazebo_msgs::SetModelConfiguration>(
133 "/gazebo/set_model_configuration");
134 gazebo_msgs::SetModelConfiguration model_srv;
135 model_srv.request.model_name =
"shadow_model";
136 model_srv.request.urdf_param_name =
"robot_description";
137 model_srv.request.joint_names.push_back(
"ElbowJSwing");
138 model_srv.request.joint_positions.push_back(2.0);
141 set_pos_client.
call(model_srv);
144 for (
int i = 0; i < 500; ++i)
151 gazebo_phys_client = node.serviceClient<std_srvs::Empty>(
"/gazebo/unpause_physics");
153 gazebo_phys_client.
call(empty_srv);
161 JointsMap::iterator iter =
joints_map.find(joint_name);
164 std_msgs::Float64 target_msg;
170 ROS_DEBUG(
"Joint %s not found.", joint_name.c_str());
177 if (target < tmpData.
min)
179 target = tmpData.
min;
181 if (target > tmpData.
max)
183 target = tmpData.
max;
188 target_msg.data =
toRad(target);
204 JointsMap::iterator iter =
joints_map.find(joint_name);
210 iter->second.temperature = 0.0;
211 iter->second.current = 0.0;
213 iter->second.force = 0.0;
221 ROS_ERROR(
"Joint %s not found.", joint_name.c_str());
253 ROS_WARN(
"The setContrl method is not yet implemented");
259 ROS_WARN(
"The getContrl method is not yet implemented");
266 ROS_WARN(
"The set config function is not implemented in the virtual arm.");
272 ROS_WARN(
"The get config function is not implemented in the virtual arm.");
278 std::vector<DiagnosticData> returnVect;
288 tmpDiag.
target = it->second.target;
289 tmpDiag.
position = it->second.position;
291 returnVect.push_back(tmpDiag);
299 void VirtualArm::gazeboCallback(
const sensor_msgs::JointStateConstPtr &
msg)
303 for (
unsigned int index = 0; index < msg->name.size(); ++index)
305 std::string joint_name = msg->name[index];
306 JointsMap::iterator iter =
joints_map.find(joint_name);
318 tmpData.
force = msg->effort[index];
virtual int16_t sendupdate(std::string joint_name, double target)
virtual JointData getJointData(std::string joint_name)
virtual std::vector< DiagnosticData > getDiagnostics()
std::string flags
a string containing flags: FORCE, TEMPERATURE, ... indicating the different cutouts / warning sent by...
std::string joint_name
the name of the joint
bool call(MReq &req, MRes &res)
std::map< std::string, JointData > JointsMap
int target_sensor_num
the channel number of the target sensor
int position_sensor_num
the channel number of the position sensor
virtual JointsMap getAllJointsData()
virtual int16_t setConfig(std::vector< std::string > myConfig)
bool waitForExistence(ros::Duration timeout=ros::Duration(-1))
JointsMap joints_map
A mapping between the joint names and the information regarding those joints.
This is a parent class for the different types of Shadowhand we can have. It makes it possible to swa...
virtual int16_t setContrl(std::string contrlr_name, JointControllerData ctrlr_data)
boost::mutex joints_map_mutex
The virtual arm can be used as a simulator. It modelizes the Shadow Robot muscle arm.
virtual void getConfig(std::string joint_name)
int16_t level
the level of alert: 0 = OK, 1 = WARNING, 2 = ERROR
double target
the actual value of the target
double position
the actual value of the position
virtual JointControllerData getContrl(std::string ctrlr_name)
double toDegrees(double rad)