RealsenseMappingState.cpp
Go to the documentation of this file.
2 
3 namespace rsm {
4 
6 }
7 
9 }
10 
12  _joint_states_subscriber = _nh.subscribe("joint_states", 10,
14  _realsense_joint_controller = _nh.advertise<std_msgs::Float64>(
15  "realsense_controller/command", 1, true);
16  ros::NodeHandle nh("rsm");
17  _reset_realsense_position_client = nh.serviceClient<std_srvs::Trigger>(
18  "resetRealsensePosition");
19  _navigation_goal_completed_service = nh.serviceClient<
20  rsm_msgs::GoalCompleted>("navigationGoalCompleted");
21  _name = "E: RealSense Mapping";
22  _swivel_state = -1;
23  _position_reached = false;
24  _message_send = false;
25  _navigation_completed_status = rsm_msgs::GoalStatus::ABORTED;
26 }
27 
30 }
31 
33  switch (_swivel_state) {
34  case MOVE_LEFT: {
35  if (_position_reached) {
37  _position_reached = false;
38  _message_send = false;
39  } else {
40  if (!_message_send) {
41  std_msgs::Float64 realsense_command;
42  realsense_command.data = REALSENSE_LEFT_LIMIT;
43  _realsense_joint_controller.publish(realsense_command);
44  ros::spinOnce();
45  _message_send = true;
46  }
47  }
48  break;
49  }
50  case MOVE_RIGHT: {
51  if (_position_reached) {
53  _position_reached = false;
54  _message_send = false;
55  } else {
56  if (!_message_send) {
57  std_msgs::Float64 realsense_command;
58  realsense_command.data = REALSENSE_RIGHT_LIMIT;
59  _realsense_joint_controller.publish(realsense_command);
60  _message_send = true;
61  }
62  }
63  break;
64  }
65  case MOVE_TO_CENTER: {
66  if (_position_reached) {
67  if (!_interrupt_occured) {
68  _navigation_completed_status = rsm_msgs::GoalStatus::REACHED;
71  }
72  } else {
73  if (!_message_send) {
74  std_msgs::Float64 realsense_command;
75  realsense_command.data = REALSENSE_CENTER_POSITION;
76  _realsense_joint_controller.publish(realsense_command);
77  _message_send = true;
78  }
79  }
80  break;
81  }
82  default: {
83  break;
84  }
85  }
86 }
87 
89  if (!_position_reached) {
90  std_srvs::Trigger srv;
92  ROS_ERROR("Failed to call Reset Realsense Position service");
93  }
94  }
95  if (_navigation_completed_status == rsm_msgs::GoalStatus::ABORTED) {
96  rsm_msgs::GoalCompleted srv;
97  srv.request.status.goal_status = _navigation_completed_status;
98  srv.request.navigation_status = false;
100  ROS_ERROR("Failed to call Complete Navigation Goal service");
101  }
102  }
103 }
104 
106  std::string &message) {
107  success = false;
108  message = "Exploration running";
109 }
110 
112  std::string &message) {
113  success = true;
114  message = "Exploration stopped";
115  _stateinterface->transitionToVolatileState(boost::make_shared<IdleState>());
116 }
117 
119  std::string &message) {
120  success = false;
121  message = "Exploration running";
122 }
123 
125  std::string &message) {
126  success = false;
127  message = "Exploration running";
128 }
129 
131  switch (interrupt) {
134  boost::make_shared<EmergencyStopState>());
135  _interrupt_occured = true;
136  break;
139  boost::make_shared<TeleoperationState>());
140  _interrupt_occured = true;
141  break;
145  _interrupt_occured = true;
146  break;
147  }
148 }
149 
151  sensor_msgs::JointState::ConstPtr joint_state) {
152  switch (_swivel_state) {
153  case MOVE_LEFT: {
154  if (joint_state->position[0] >= REALSENSE_LEFT_LIMIT - POS_TOLERANCE) {
155  _position_reached = true;
156  }
157  break;
158  }
159  case MOVE_RIGHT: {
160  if (joint_state->position[0] <= REALSENSE_RIGHT_LIMIT + POS_TOLERANCE) {
161  _position_reached = true;
162  }
163  break;
164  }
165  case MOVE_TO_CENTER: {
166  if (joint_state->position[0]
168  && joint_state->position[0]
170  _position_reached = true;
171  }
172  break;
173  }
174  }
175 }
176 
177 }
178 
ros::ServiceClient _reset_realsense_position_client
#define POS_TOLERANCE
#define MOVE_RIGHT
boost::shared_ptr< rsm::BaseState > getPluginState(int plugin_type, std::string routine="")
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
#define MOVE_LEFT
ros::Subscriber _joint_states_subscriber
#define REALSENSE_RIGHT_LIMIT
#define NAVIGATION_STATE
void onExplorationStart(bool &success, std::string &message)
void onWaypointFollowingStop(bool &success, std::string &message)
bool call(MReq &req, MRes &res)
void jointStateCallback(sensor_msgs::JointState::ConstPtr joint_state)
#define MOVE_TO_CENTER
void transitionToVolatileState(boost::shared_ptr< rsm::BaseState > next_state)
bool _interrupt_occured
#define TELEOPERATION_INTERRUPT
#define REALSENSE_CENTER_POSITION
void onWaypointFollowingStart(bool &success, std::string &message)
void publish(const boost::shared_ptr< M > &message) const
void onInterrupt(int interrupt)
Called when an operation mode interrupt was received.
#define CALCULATEGOAL_STATE
#define REALSENSE_LEFT_LIMIT
std::string _name
Dummy state for mapping at a reached goal during exploration. Only initiates transition to CalculateG...
StateInterface * _stateinterface
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define EMERGENCY_STOP_INTERRUPT
ros::Publisher _realsense_joint_controller
ros::ServiceClient _navigation_goal_completed_service
void onExplorationStop(bool &success, std::string &message)
#define SIMPLE_GOAL_INTERRUPT
ROSCPP_DECL void spinOnce()
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
#define ROS_ERROR(...)


rsm_additions
Author(s): Marco Steinbrink
autogenerated on Mon Feb 28 2022 23:28:21