24 #include <blackboard/remote.h> 25 #include <blackboard/interface_listener.h> 27 #include <interfaces/ZoneInterface.h> 28 #include <interfaces/Position3DInterface.h> 29 #include <interfaces/TagVisionInterface.h> 30 #include <interfaces/RobotinoLightInterface.h> 31 #include <interfaces/NavGraphWithMPSGeneratorInterface.h> 33 #include <utils/time/time.h> 35 #include <rcll_fawkes_sim_msgs/ExplorationZoneInfo.h> 36 #include <rcll_fawkes_sim_msgs/MPSMarkerArray.h> 37 #include <rcll_fawkes_sim_msgs/MPSLightState.h> 38 #include <rcll_fawkes_sim_msgs/NavgraphWithMPSGenerate.h> 39 #include <geometry_msgs/PoseWithCovarianceStamped.h> 43 #define GET_PRIV_PARAM(P) \ 45 if (! ros::param::get("~" #P, cfg_ ## P ## _)) { \ 46 ROS_ERROR("%s: Failed to retrieve parameter " #P ", aborting", ros::this_node::getName().c_str()); \ 55 case fawkes::RobotinoLightInterface::ON:
56 return rcll_fawkes_sim_msgs::MPSLightState::LIGHT_STATE_ON;
57 case fawkes::RobotinoLightInterface::OFF:
58 return rcll_fawkes_sim_msgs::MPSLightState::LIGHT_STATE_OFF;
59 case fawkes::RobotinoLightInterface::BLINKING:
60 return rcll_fawkes_sim_msgs::MPSLightState::LIGHT_STATE_BLINKING;
62 return rcll_fawkes_sim_msgs::MPSLightState::LIGHT_STATE_UNKNOWN;
65 fawkes::NavGraphWithMPSGeneratorInterface::Side
68 if (side == rcll_fawkes_sim_msgs::NavgraphMPSStation::SIDE_INPUT) {
69 return fawkes::NavGraphWithMPSGeneratorInterface::INPUT;
71 return fawkes::NavGraphWithMPSGeneratorInterface::OUTPUT;
79 : BlackBoardInterfaceListener(
"RcllFawkesSimNode"),
88 for (
size_t i = 0; i < std::min(ifc_tag_vision_->maxlenof_tag_id(),
ifcs_tag_pos_.size()); ++i) {
89 std::string ifc_id =
"/tag-vision/" + std::to_string(i);
96 blackboard_->open_for_reading<fawkes::NavGraphWithMPSGeneratorInterface>(
"/navgraph-generator-mps");
101 bbil_add_data_interface(ifc_tag_vision_);
102 bbil_add_data_interface(ifc_machine_signal_);
103 bbil_add_data_interface(ifc_pose_);
107 rosnode.
advertise<rcll_fawkes_sim_msgs::ExplorationZoneInfo>(
"rcll_sim/explore_zone_info", 10);
109 rosnode.
advertise<rcll_fawkes_sim_msgs::MPSMarkerArray>(
"rcll_sim/mps_marker_array", 10);
111 rosnode.
advertise<rcll_fawkes_sim_msgs::MPSLightState>(
"rcll_sim/mps_light_state", 10);
113 rosnode.
advertise<geometry_msgs::PoseWithCovarianceStamped>(
"rcll_sim/amcl_pose", 10);
115 blackboard_->register_listener(
this, fawkes::BlackBoard::BBIL_FLAG_DATA);
146 if (strcmp(interface->uid(),
ifc_pose_->uid()) == 0) {
147 const fawkes::Time *ts =
ifc_pose_->timestamp();
148 geometry_msgs::PoseWithCovarianceStamped p;
150 p.header.stamp.sec = ts->get_sec();
151 p.header.stamp.nsec = ts->get_nsec();
152 p.pose.pose.position.x =
ifc_pose_->translation(0);
153 p.pose.pose.position.y =
ifc_pose_->translation(1);
154 p.pose.pose.orientation.x =
ifc_pose_->rotation(0);
155 p.pose.pose.orientation.y =
ifc_pose_->rotation(1);
156 p.pose.pose.orientation.z =
ifc_pose_->rotation(2);
157 p.pose.pose.orientation.w =
ifc_pose_->rotation(3);
159 for (
int i = 0; i <
ifc_pose_->maxlenof_covariance(); ++i) {
160 p.pose.covariance[i] =
ifc_pose_->covariance(i);
164 }
else if (strcmp(interface->uid(),
ifc_zone_->uid()) == 0) {
165 rcll_fawkes_sim_msgs::ExplorationZoneInfo rezi;
166 rezi.result = rcll_fawkes_sim_msgs::ExplorationZoneInfo::MPS_IN_ZONE_UNKNOWN;
168 case fawkes::ZoneInterface::NO:
169 rezi.result = rcll_fawkes_sim_msgs::ExplorationZoneInfo::MPS_IN_ZONE_NO;
171 case fawkes::ZoneInterface::YES:
172 rezi.result = rcll_fawkes_sim_msgs::ExplorationZoneInfo::MPS_IN_ZONE_YES;
174 case fawkes::ZoneInterface::MAYBE:
175 rezi.result = rcll_fawkes_sim_msgs::ExplorationZoneInfo::MPS_IN_ZONE_MAYBE;
182 rcll_fawkes_sim_msgs::MPSMarkerArray rma;
187 rcll_fawkes_sim_msgs::MPSMarker rm;
189 rm.pose.header.stamp.sec = ts->get_sec();
190 rm.pose.header.stamp.nsec = ts->get_nsec();
193 rm.pose.visibility_history =
ifcs_tag_pos_[i]->visibility_history();
201 rma.markers.push_back(rm);
206 rcll_fawkes_sim_msgs::MPSLightState rls;
219 rcll_fawkes_sim_msgs::NavgraphWithMPSGenerate::Response &res)
223 res.error_msg =
"Blackboard is not connected";
229 res.error_msg =
"No writer for navgraph generator with MPS interface";
233 std::queue<fawkes::Message *> msgs;
235 ifc_navgraph_gen_->msgq_enqueue(
new fawkes::NavGraphWithMPSGeneratorInterface::ClearMessage());
237 for (
size_t i = 0; i < req.mps_stations.size(); ++i) {
238 const rcll_fawkes_sim_msgs::NavgraphMPSStation &mps = req.mps_stations[i];
239 fawkes::NavGraphWithMPSGeneratorInterface::UpdateStationByTagMessage *upm =
240 new fawkes::NavGraphWithMPSGeneratorInterface::UpdateStationByTagMessage();
241 #ifdef HAVE_OLD_NAVGRAPH_GENMPS_INTERFACE 242 upm->set_id(mps.name.c_str());
244 upm->set_name(mps.name.c_str());
247 upm->set_frame(mps.marker_frame.c_str());
248 upm->set_tag_translation(0, mps.marker_pose.position.x);
249 upm->set_tag_translation(1, mps.marker_pose.position.y);
250 upm->set_tag_translation(2, mps.marker_pose.position.z);
251 upm->set_tag_rotation(0, mps.marker_pose.orientation.x);
252 upm->set_tag_rotation(1, mps.marker_pose.orientation.y);
253 upm->set_tag_rotation(2, mps.marker_pose.orientation.z);
254 upm->set_tag_rotation(3, mps.marker_pose.orientation.w);
259 fawkes::NavGraphWithMPSGeneratorInterface::SetExplorationZonesMessage *sezm =
260 new fawkes::NavGraphWithMPSGeneratorInterface::SetExplorationZonesMessage();
261 bool zones[sezm->maxlenof_zones()];
262 for (
int i = 0; i < sezm->maxlenof_zones(); ++i) zones[i] =
false;
263 for (
size_t i = 0; i < req.exploration_zones.size(); ++i) {
264 int zone_idx = req.exploration_zones[i] - 1;
265 if (zone_idx < 0 || zone_idx > sezm->maxlenof_zones()) {
268 res.error_msg =
"Exploration zone index out of bounds";
271 zones[zone_idx] =
true;
273 sezm->set_zones(zones);
278 fawkes::NavGraphWithMPSGeneratorInterface::SetWaitZonesMessage *swzm =
279 new fawkes::NavGraphWithMPSGeneratorInterface::SetWaitZonesMessage();
280 bool zones[swzm->maxlenof_zones()];
281 for (
int i = 0; i < swzm->maxlenof_zones(); ++i) zones[i] =
false;
282 for (
size_t i = 0; i < req.wait_zones.size(); ++i) {
283 int zone_idx = req.wait_zones[i] - 1;
284 if (zone_idx < 0 || zone_idx > swzm->maxlenof_zones()) {
287 res.error_msg =
"Wait zone index out of bounds";
290 zones[zone_idx] =
true;
292 swzm->set_zones(zones);
296 while (! msgs.empty()) {
297 fawkes::Message *m = msgs.front();
302 fawkes::NavGraphWithMPSGeneratorInterface::ComputeMessage *compmsg =
303 new fawkes::NavGraphWithMPSGeneratorInterface::ComputeMessage();
306 unsigned int msgid = compmsg->id();
308 bool finished =
false;
322 res.error_msg =
"Navgraph generator with MPS interface writer disappeared while waiting";
351 ros::init(argc, argv,
"rcll_fawkes_sim");
355 std::string cfg_fawkes_host_;
356 int cfg_fawkes_port_;
358 std::shared_ptr<RcllFawkesSimNode> node;
367 std::make_shared<fawkes::RemoteBlackBoard>(cfg_fawkes_host_.c_str(), cfg_fawkes_port_);
368 node = std::make_shared<RcllFawkesSimNode>(n,
blackboard_);
371 }
catch (fawkes::Exception &e) {
379 }
else if (! blackboard_->is_alive()) {
381 if (blackboard_->try_aliveness_restore()) {
389 if (node) node->finalize();
fawkes::Position3DInterface * ifc_pose_
std::shared_ptr< fawkes::BlackBoard > blackboard_
ros::Publisher pub_mps_marker_array_
fawkes::NavGraphWithMPSGeneratorInterface::Side ros_to_fawkes_mps_side(int side)
#define ROS_WARN_THROTTLE(rate,...)
void publish(const boost::shared_ptr< M > &message) const
int main(int argc, char **argv)
fawkes::NavGraphWithMPSGeneratorInterface * ifc_navgraph_gen_
virtual void bb_interface_data_changed(fawkes::Interface *interface)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL const std::string & getName()
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
#define GET_PRIV_PARAM(P)
fawkes::RobotinoLightInterface * ifc_machine_signal_
ros::Publisher pub_mps_light_state_
int fawkes_to_ros_light_state(const fawkes::RobotinoLightInterface::LightState &state)
ROSCPP_DECL CallbackQueue * getGlobalCallbackQueue()
fawkes::TagVisionInterface * ifc_tag_vision_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool srv_cb_navgraph_gen(rcll_fawkes_sim_msgs::NavgraphWithMPSGenerate::Request &req, rcll_fawkes_sim_msgs::NavgraphWithMPSGenerate::Response &res)
fawkes::ZoneInterface * ifc_zone_
ros::ServiceServer srv_navgraph_gen_
RcllFawkesSimNode(ros::NodeHandle rn, std::shared_ptr< fawkes::BlackBoard > bb)
std::array< fawkes::Position3DInterface *, 16 > ifcs_tag_pos_
ros::Publisher pub_expl_zone_info_