RobotGoalsArrayVisual.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <ros/ros.h>
31 
32 #include <OGRE/OgreVector3.h>
33 #include <OGRE/OgreMatrix3.h>
34 #include <OGRE/OgreSceneNode.h>
35 #include <OGRE/OgreSceneManager.h>
36 
38 
39 namespace tuw_multi_robot_rviz {
40 
41 RobotGoalsArrayVisual::RobotGoalsArrayVisual ( Ogre::SceneManager* scene_manager, Ogre::SceneNode* parent_node ) {
42  scene_manager_ = scene_manager;
43 
44  // Ogre::SceneNode s form a tree, with each node storing the
45  // transform (position and orientation) of itself relative to its
46  // parent. Ogre does the math of combining those transforms when it
47  // is time to render.
48  //
49  // Here we create a node to store the pose of the MarkerDetection's header frame
50  // relative to the RViz fixed frame.
51  frame_node_ = parent_node->createChildSceneNode();
52 
53 }
54 
56  // Destroy the frame node since we don't need it anymore.
57  scene_manager_->destroySceneNode ( frame_node_ );
58 }
59 
60 void RobotGoalsArrayVisual::setMessage ( const tuw_multi_robot_msgs::RobotGoalsArray::ConstPtr& msg ) {
61 
62  goals_.resize(msg->robots.size());
63 
64  for (size_t i = 0; i < msg->robots.size(); i++){
65  goals_[i].reset ( new rviz::Arrow( scene_manager_, frame_node_ ) );
68  if(msg->robots[i].destinations.size() == 0) {
69  continue;
70  }
71 
73  const geometry_msgs::Pose &pose = msg->robots[i].destinations.back();
74 
75  Ogre::Vector3 position = Ogre::Vector3 ( pose.position.x, pose.position.y, pose.position.z );
76  Ogre::Quaternion orientation = Ogre::Quaternion ( pose.orientation.x, pose.orientation.y, pose.orientation.z, pose.orientation.w );
77 
78 
79  // Arrow points in -Z direction, so rotate the orientation before display.
80  // TODO: is it safe to change Arrow to point in +X direction?
81  Ogre::Quaternion rotation1 = Ogre::Quaternion ( Ogre::Degree( -90 ), Ogre::Vector3::UNIT_Y );
82  Ogre::Quaternion rotation2 = Ogre::Quaternion ( Ogre::Degree( -180 ), Ogre::Vector3::UNIT_X );
83  orientation = rotation2 * rotation1 * orientation;
84 
85  arrow->setPosition( position );
86  arrow->setOrientation( orientation );
87  }
88 }
89 
90 // Position is passed through to the SceneNode.
91 void RobotGoalsArrayVisual::setFramePosition ( const Ogre::Vector3& position ) {
92  frame_node_->setPosition ( position );
93 }
94 
95 // Orientation is passed through to the SceneNode.
96 void RobotGoalsArrayVisual::setFrameOrientation ( const Ogre::Quaternion& orientation ) {
97  frame_node_->setOrientation ( orientation );
98 }
99 
100 // Scale is passed through to the pose Shape object.
102 
104  goal->setScale ( Ogre::Vector3 ( scale, scale, scale ));
105  }
106  scale_pose_ = scale;
107 }
108 
109 // Color is passed through to the pose Shape object.
110 void RobotGoalsArrayVisual::setColorPose ( Ogre::ColourValue color ) {
112  goal->setColor ( color );;
113  }
114  color_pose_ = color;
115 }
116 
117 } // end namespace tuw_multi_robot_rviz
118 
std::vector< boost::shared_ptr< rviz::Arrow > > goals_
void setFrameOrientation(const Ogre::Quaternion &orientation)
void setMessage(const tuw_multi_robot_msgs::RobotGoalsArray::ConstPtr &msg)
RobotGoalsArrayVisual(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node)
void setFramePosition(const Ogre::Vector3 &position)


tuw_multi_robot_rviz
Author(s): Benjamin Binder
autogenerated on Mon Jun 10 2019 15:42:40