SMACC
Loading...
Searching...
No Matches
imu_visual.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 <OGRE/OgreVector3.h>
31#include <OGRE/OgreSceneNode.h>
32#include <OGRE/OgreSceneManager.h>
33
34#include <rviz/ogre_helpers/arrow.h>
35
36#include "imu_visual.h"
37
39{
40
41// BEGIN_TUTORIAL
42ImuVisual::ImuVisual( Ogre::SceneManager* scene_manager, Ogre::SceneNode* parent_node )
43{
44 scene_manager_ = scene_manager;
45
46 // Ogre::SceneNode s form a tree, with each node storing the
47 // transform (position and orientation) of itself relative to its
48 // parent. Ogre does the math of combining those transforms when it
49 // is time to render.
50 //
51 // Here we create a node to store the pose of the Imu's header frame
52 // relative to the RViz fixed frame.
53 frame_node_ = parent_node->createChildSceneNode();
54
55 // We create the arrow object within the frame node so that we can
56 // set its position and direction relative to its header frame.
57 acceleration_arrow_.reset(new rviz::Arrow( scene_manager_, frame_node_ ));
58}
59
61{
62 // Destroy the frame node since we don't need it anymore.
63 scene_manager_->destroySceneNode( frame_node_ );
64}
65
66void ImuVisual::setMessage( const sensor_msgs::Imu::ConstPtr& msg )
67{
68 const geometry_msgs::Vector3& a = msg->linear_acceleration;
69
70 // Convert the geometry_msgs::Vector3 to an Ogre::Vector3.
71 Ogre::Vector3 acc( a.x, a.y, a.z );
72
73 // Find the magnitude of the acceleration vector.
74 float length = acc.length();
75
76 // Scale the arrow's thickness in each dimension along with its length.
77 Ogre::Vector3 scale( length, length, length );
78 acceleration_arrow_->setScale( scale );
79
80 // Set the orientation of the arrow to match the direction of the
81 // acceleration vector.
82 acceleration_arrow_->setDirection( acc );
83}
84
85// Position and orientation are passed through to the SceneNode.
86void ImuVisual::setFramePosition( const Ogre::Vector3& position )
87{
88 frame_node_->setPosition( position );
89}
90
91void ImuVisual::setFrameOrientation( const Ogre::Quaternion& orientation )
92{
93 frame_node_->setOrientation( orientation );
94}
95
96// Color is passed through to the Arrow object.
97void ImuVisual::setColor( float r, float g, float b, float a )
98{
99 acceleration_arrow_->setColor( r, g, b, a );
100}
101// END_TUTORIAL
102
103} // end namespace rviz_plugin_tutorials
ImuVisual(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node)
Definition: imu_visual.cpp:42
void setFramePosition(const Ogre::Vector3 &position)
Definition: imu_visual.cpp:86
void setMessage(const sensor_msgs::Imu::ConstPtr &msg)
Definition: imu_visual.cpp:66
void setColor(float r, float g, float b, float a)
Definition: imu_visual.cpp:97
boost::shared_ptr< rviz::Arrow > acceleration_arrow_
Definition: imu_visual.h:76
void setFrameOrientation(const Ogre::Quaternion &orientation)
Definition: imu_visual.cpp:91
Ogre::SceneManager * scene_manager_
Definition: imu_visual.h:84
Ogre::SceneNode * frame_node_
Definition: imu_visual.h:80