14 #include <ros/console.h> 15 #include <std_srvs/Empty.h> 17 #include <unordered_map> 24 _nh = ros::NodeHandlePtr(
new ros::NodeHandle());
33 this->
gz_service = this->
_nh->serviceClient<gazebo_msgs::SetModelState>(
"/gazebo/set_model_state");
38 static gazebo_msgs::SetModelStateRequest request;
39 static gazebo_msgs::SetModelStateResponse response;
42 request.model_state = model_state;
44 bool status = this->
gz_service.call(request, response);
46 if (!(status && response.success)) {
47 ROS_ERROR_STREAM(
"Error while calling set_model_state " << model_state);
55 for (uint32_t i = 0; i < model_states->size(); i++) {
57 ROS_ERROR_STREAM(
"Error while calling set_team_state at i = " << i);
66 static std::unordered_map<simulation_command_t, std::string> topics_table({
75 if (topics_table[command] ==
"") {
78 ros::service::call(topics_table[command], msg);
void reconnect_service_client()
Attempts to reconnect gz_service ServiceClient if connection dropped.
bool set_model_state(gazebo_msgs::ModelState model_state)
Set the state of one entity.
bool send_command(simulation_command_t command)
Send command to gazebo.
bool set_models_state(state_vector_t *model_states)
Set state of multiple entities.
std::vector< gazebo_msgs::ModelState > state_vector_t
Helper type to set the states of multiple entites at once.
ros::ServiceClient gz_service
ReplacerSender()
Construct a new Replacer Sender object.
simulation_command_t
All possible commands to send to Gazebo.