Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scale parameter for imu visualization #89

Open
wants to merge 1 commit into
base: noetic-devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions rviz_plugin_tutorials/src/imu_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ ImuDisplay::ImuDisplay()
"0 is fully transparent, 1.0 is fully opaque.",
this, SLOT( updateColorAndAlpha() ));

scale_property_ = new rviz::FloatProperty( "Scale", 1.0,
"Scale of the acceleration arrows.",
this, SLOT( updateScale() ));

history_length_property_ = new rviz::IntProperty( "History Length", 1,
"Number of prior measurements to display.",
this, SLOT( updateHistoryLength() ));
Expand Down Expand Up @@ -104,6 +108,17 @@ void ImuDisplay::updateColorAndAlpha()
}
}

// Set the current scale value for each visual.
void ImuDisplay::updateScale()
{
float scale = scale_property_->getFloat();

for( size_t i = 0; i < visuals_.size(); i++ )
{
visuals_[ i ]->setScale( scale );
}
}

// Set the number of past visuals to show.
void ImuDisplay::updateHistoryLength()
{
Expand Down Expand Up @@ -147,6 +162,7 @@ void ImuDisplay::processMessage( const sensor_msgs::Imu::ConstPtr& msg )
float alpha = alpha_property_->getFloat();
Ogre::ColourValue color = color_property_->getOgreColor();
visual->setColor( color.r, color.g, color.b, alpha );
visual->setScale(scale_property_->getFloat());

// And send it to the end of the circular buffer
visuals_.push_back(visual);
Expand Down
2 changes: 2 additions & 0 deletions rviz_plugin_tutorials/src/imu_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Q_OBJECT
private Q_SLOTS:
void updateColorAndAlpha();
void updateHistoryLength();
void updateScale();

// Function to handle an incoming ROS message.
private:
Expand All @@ -109,6 +110,7 @@ private Q_SLOTS:
// User-editable property variables.
rviz::ColorProperty* color_property_;
rviz::FloatProperty* alpha_property_;
rviz::FloatProperty* scale_property_;
rviz::IntProperty* history_length_property_;
};
// END_TUTORIAL
Expand Down
11 changes: 8 additions & 3 deletions rviz_plugin_tutorials/src/imu_visual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ void ImuVisual::setMessage( const sensor_msgs::Imu::ConstPtr& msg )
Ogre::Vector3 acc( a.x, a.y, a.z );

// Find the magnitude of the acceleration vector.
float length = acc.length();
float length = acc.length() * scale_;

// Scale the arrow's thickness in each dimension along with its length.
Ogre::Vector3 scale( length, length, length );
acceleration_arrow_->setScale( scale );
acceleration_arrow_->setScale(Ogre::Vector3(length, length, length));

// Set the orientation of the arrow to match the direction of the
// acceleration vector.
Expand All @@ -98,6 +97,12 @@ void ImuVisual::setColor( float r, float g, float b, float a )
{
acceleration_arrow_->setColor( r, g, b, a );
}

// Scale is passed through to the Arrow object.
void ImuVisual::setScale(float s)
{
scale_ = s;
}
// END_TUTORIAL

} // end namespace rviz_plugin_tutorials
Expand Down
7 changes: 7 additions & 0 deletions rviz_plugin_tutorials/src/imu_visual.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,17 @@ class ImuVisual
// parameters and therefore don't come from the Imu message.
void setColor( float r, float g, float b, float a );

// Set the scale of the visual, which are user-editable
// parameters and therefore don't come from the Imu message.
void setScale(float s);

private:
// The object implementing the actual arrow shape
boost::shared_ptr<rviz::Arrow> acceleration_arrow_;

// arrow scale
float scale_;

// A SceneNode whose pose is set to match the coordinate frame of
// the Imu message header.
Ogre::SceneNode* frame_node_;
Expand Down