PlantWaypointTool.cpp
Go to the documentation of this file.
2 
3 namespace rsm {
4 
6  moving_flag_node_( NULL), current_flag_property_( NULL) {
7  shortcut_key_ = 'w';
8  ros::NodeHandle nh("rsm");
9  _add_waypoint_client = nh.serviceClient<rsm_msgs::AddWaypoint>(
10  "addWaypoint");
11 }
12 
14  for (unsigned i = 0; i < flag_nodes_.size(); i++) {
15  scene_manager_->destroySceneNode(flag_nodes_[i]);
16  }
17 }
18 
20  flag_resource_ = "package://rsm_rviz_plugins/media/flag.dae";
21 
23  ROS_ERROR("PlantWaypointTool: failed to load model resource '%s'.",
24  flag_resource_.c_str());
25  return;
26  }
27 
29  scene_manager_->getRootSceneNode()->createChildSceneNode();
30  Ogre::Entity* entity = scene_manager_->createEntity(flag_resource_);
31  moving_flag_node_->attachObject(entity);
32  moving_flag_node_->setVisible(false);
33 }
34 
36  if (moving_flag_node_) {
37  moving_flag_node_->setOrientation(Ogre::Quaternion());
38  moving_flag_node_->setVisible(true);
39 
41  "Waypoint " + QString::number(flag_nodes_.size()));
44  state_ = Moving;
45  }
46 }
47 
49  if (moving_flag_node_) {
50  moving_flag_node_->setVisible(false);
53  }
54 }
55 
57  if (!moving_flag_node_) {
58  return Render;
59  }
60  Ogre::Vector3 intersection;
61  Ogre::Plane ground_plane(Ogre::Vector3::UNIT_Z, 0.0f);
62  if (rviz::getPointOnPlaneFromWindowXY(event.viewport, ground_plane, event.x,
63  event.y, intersection)) {
64  moving_flag_node_->setVisible(true);
65  if (state_ == Moving) {
66  moving_flag_node_->setPosition(intersection);
67  current_flag_property_->setVector(intersection);
68  }
69  if (event.leftDown()) {
70  state_ == Position;
71  pos_ = intersection;
72  moving_flag_node_->setPosition(pos_);
74  return Render;
75  } else if (event.type == QEvent::MouseMove && event.left()
76  && state_ == Orientation) {
77  //compute angle in x-y plane
78  double angle = atan2(intersection.y - pos_.y,
79  intersection.x - pos_.x);
80  moving_flag_node_->setVisible(true);
81 
82  //we need base_orient, since the arrow goes along the -z axis by default (for historical reasons)
83  moving_flag_node_->setOrientation(
84  Ogre::Quaternion(Ogre::Radian(angle),
85  Ogre::Vector3::UNIT_Z));
86  return Render;
87  } else if (event.leftUp() && state_ == Orientation) {
88  //compute angle in x-y plane
89  double angle = atan2(intersection.y - pos_.y,
90  intersection.x - pos_.x);
91  makeFlag(pos_, angle);
92  return (Finished | Render);
93  }
94  } else {
95  moving_flag_node_->setVisible(false); // If the mouse is not pointing at the ground plane, don't show the flag.
96  return Render;
97  }
98 }
99 
100 void PlantWaypointTool::makeFlag(const Ogre::Vector3& position, double angle) {
101  rsm_msgs::AddWaypoint srv;
102  rsm_msgs::Waypoint waypoint;
103  waypoint.pose.position.x = position.x;
104  waypoint.pose.position.y = position.y;
105  waypoint.pose.position.z = position.z;
106  waypoint.pose.orientation = tf::createQuaternionMsgFromYaw(angle);
107  srv.request.waypoint = waypoint;
108  srv.request.position = -1;
109  if (!_add_waypoint_client.call(srv)) {
110  ROS_ERROR("Failed to call Add Waypoint service");
111  }
112 }
113 
114 
116 }
117 
119 }
120 
121 } // end namespace rsm
122 
Ogre::SceneManager * scene_manager_
#define NULL
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
Serves as a Tool plugin for RViz which enables planting waypoints on a desired location with an adjus...
rviz::VectorProperty * current_flag_property_
virtual bool setVector(const Ogre::Vector3 &vector)
Ogre::Viewport * viewport
f
bool call(MReq &req, MRes &res)
Ogre::MeshPtr loadMeshFromResource(const std::string &resource_path)
char shortcut_key_
ros::ServiceClient _add_waypoint_client
virtual void setReadOnly(bool read_only)
bool getPointOnPlaneFromWindowXY(Ogre::Viewport *viewport, Ogre::Plane &plane, int window_x, int window_y, Ogre::Vector3 &intersection_out)
void load(const rviz::Config &config)
static geometry_msgs::Quaternion createQuaternionMsgFromYaw(double yaw)
Ogre::SceneNode * moving_flag_node_
virtual void addChild(Property *child, int index=-1)
void save(rviz::Config config) const
INLINE Rall1d< T, V, S > atan2(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
virtual Property * getPropertyContainer() const
std::vector< Ogre::SceneNode * > flag_nodes_
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
#define ROS_ERROR(...)
void makeFlag(const Ogre::Vector3 &position, double angle)
int processMouseEvent(rviz::ViewportMouseEvent &event)


rsm_rviz_plugins
Author(s): Marco Steinbrink
autogenerated on Tue Mar 16 2021 02:44:40