SMACC
Loading...
Searching...
No Matches
smacc_rviz_display.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/OgreSceneNode.h>
31#include <OGRE/OgreSceneManager.h>
32
33#include <tf/transform_listener.h>
34
35#include <rviz/visualization_manager.h>
36#include <rviz/properties/color_property.h>
37#include <rviz/properties/float_property.h>
38#include <rviz/properties/int_property.h>
39#include <rviz/frame_manager.h>
40
41#include "imu_visual.h"
42
43#include "smacc_rviz_display.h"
44
45namespace smacc_rviz_plugin
46{
47
48// BEGIN_TUTORIAL
49// The constructor must have no arguments, so we can't give the
50// constructor the parameters it needs to fully initialize.
52{
53
54 /*
55 color_property_ = new rviz::ColorProperty( "Color", QColor( 204, 51, 204 ),
56 "Color to draw the acceleration arrows.",
57 this, SLOT( updateColorAndAlpha() ));
58
59 alpha_property_ = new rviz::FloatProperty( "Alpha", 1.0,
60 "0 is fully transparent, 1.0 is fully opaque.",
61 this, SLOT( updateColorAndAlpha() ));
62
63 history_length_property_ = new rviz::IntProperty( "History length", 1,
64 "Number of prior measurements to display.",
65 this, SLOT( updateHistoryLength() ));
66 */
67
68 current_state_ = new rviz::StringProperty( "CurrentState", "",
69 "current smacc state",
70 this, SLOT( updateCurrentState() ));
71
72
73 topic_property_ = new rviz::RosTopicProperty( "Topic", "",
74 "", "",
75 this, SLOT( updateTopic() ));
76
77 QString message_type = QString::fromStdString( ros::message_traits::datatype<smacc_msgs::SmaccStatus>() );
78 topic_property_->setMessageType( message_type );
79 topic_property_->setDescription( message_type + " topic to subscribe to." );
80
81
82 //history_length_property_->setMin( 1 );
83 //history_length_property_->setMax( 100000 );
84}
85
87 {
89 reset();
90 subscribe();
91 context_->queueRender();
92 }
93
95 {
96 current_state_->setValue(QString(""));
97 sub_ = nh_.subscribe<smacc_msgs::SmaccStatus>(topic_property_->getTopic().toStdString(), 1, &SmaccRvizDisplay::processMessage , this);
98 }
99
101 {
102 current_state_->setValue(QString(""));
103 sub_.shutdown();
104
105 }
106// After the top-level rviz::Display::initialize() does its own setup,
107// it calls the subclass's onInitialize() function. This is where we
108// instantiate all the workings of the class. We make sure to also
109// call our immediate super-class's onInitialize() function, since it
110// does important stuff setting up the message filter.
111//
112// Note that "MFDClass" is a typedef of
113// ``MessageFilterDisplay<message type>``, to save typing that long
114// templated class name every time you need to refer to the
115// superclass.
117{
118 //MFDClass::onInitialize();
119 current_state_->setValue(QString(""));
120}
121
123{
124}
125
126// Clear the visuals by deleting their objects.
128{
129 //MFDClass::reset();
130 //visuals_.clear();
131 current_state_->setValue(QString(""));
132}
133
135{
136}
137
138// This is our callback to handle an incoming message.
139void SmaccRvizDisplay::processMessage( const smacc_msgs::SmaccStatus::ConstPtr& msg )
140{
141 std::string concatenated;
142
143 for(auto& state: msg->current_states)
144 {
145 concatenated = concatenated + std::string("/")+ state;
146 }
147
148 ROS_DEBUG("current state: %s", concatenated.c_str());
149 current_state_->setValue(QString(concatenated.c_str()));
150 // Here we call the rviz::FrameManager to get the transform from the
151 // fixed frame to the frame in the header of this Imu message. If
152 // it fails, we can't do anything else so we return.
153 /*
154 Ogre::Quaternion orientation;
155 Ogre::Vector3 position;
156 if( !context_->getFrameManager()->getTransform( msg->header.frame_id,
157 msg->header.stamp,
158 position, orientation ))
159 {
160 ROS_DEBUG( "Error transforming from frame '%s' to frame '%s'",
161 msg->header.frame_id.c_str(), qPrintable( fixed_frame_ ));
162 return;
163 }
164
165 // We are keeping a circular buffer of visual pointers. This gets
166 // the next one, or creates and stores it if the buffer is not full
167 boost::shared_ptr<ImuVisual> visual;
168 if( visuals_.full() )
169 {
170 visual = visuals_.front();
171 }
172 else
173 {
174 visual.reset(new ImuVisual( context_->getSceneManager(), scene_node_ ));
175 }*/
176
177 // Now set or update the contents of the chosen visual.
178 //visual->setMessage( msg );
179 //visual->setFramePosition( position );
180 //visual->setFrameOrientation( orientation );
181
182 /*
183 float alpha = alpha_property_->getFloat();
184 Ogre::ColourValue color = color_property_->getOgreColor();
185 visual->setColor( color.r, color.g, color.b, alpha );
186
187 // And send it to the end of the circular buffer
188 visuals_.push_back(visual);
189 */
190}
191
192} // end namespace rviz_plugin_tutorials
193
194// Tell pluginlib about this class. It is important to do this in
195// global scope, outside our package's namespace.
196#include <pluginlib/class_list_macros.h>
198// END_TUTORIAL
PLUGINLIB_EXPORT_CLASS(cl_move_base_z::backward_global_planner::BackwardGlobalPlanner, nav_core::BaseGlobalPlanner)
void processMessage(const smacc_msgs::SmaccStatus::ConstPtr &msg)
rviz::RosTopicProperty * topic_property_