How to change transparency/visibility of visual using gazeboRos modelplugin

asked 2016-08-23 06:30:56 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

I am trying to change the transparency of the cones in the attached picture online image description

First some system info:

  • Ubuntu 14.04
  • Gazebo 7.3
  • Gazebo 5.1
  • ROS JADE

I have tested with both Gazobo 7 and Gazobo 5, to determine if this was a version problem, but the problem remains the same. I made a plugin for ROS to change the transparancy, but it does not seem to have any affect on the chosen visual in gazebo.

#include "generic_sprayer_plugin/generic_sprayer_plugin.h"
#include <cmath>

namespace gazebo
{


    GenericSprayerPlugin::GenericSprayerPlugin()
    {
        alive_ = false;
    }

    GenericSprayerPlugin::~GenericSprayerPlugin() {
    }

    void GenericSprayerPlugin::Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)
    {

        this->parent = _parent;

        this->gzNode = transport::NodePtr(new transport::Node());
        this->gzNode->Init();

        this->visPub = this->gzNode->Advertise<gazebo::msgs::Visual>("~/visual");

        gazebo_ros_ = GazeboRosPtr(new GazeboRos(_parent, _sdf, "GenericSprayerPlugin"));

        // Make sure the ROS node for Gazebo has already been initialized
        gazebo_ros_->isInitialized();

        gazebo_ros_->getParameter < std::string > (sprayer_viz_topic_, "sprayerVizTopic", "/aiSim/gen_sprayer");

        last_update_time_ = parent->GetWorld()->GetSimTime();

        spray_link = parent->GetChildLink("sprayer_1");

        Sprayer_inputMsg.valve = true;

        alive_ = true;

        ros::SubscribeOptions so =
            ros::SubscribeOptions::create<generic_sprayer_plugin::Sprayer_input> ( sprayer_viz_topic_, 1,
            boost::bind ( &GenericSprayerPlugin::onVizUpdate, this, _1 ),
            ros::VoidPtr(), &queue_ );

        subscriber_ = gazebo_ros_->node()->subscribe ( so );

        ROS_INFO ( "%s: Subscribe to %s!", gazebo_ros_->info(), sprayer_viz_topic_.c_str() );

        // start custom queue for diff drive
        this->callback_queue_thread_ = boost::thread ( boost::bind ( &GenericSprayerPlugin::QueueThread, this ) );

        // listen to the update event (broadcast every simulation iteration)
        this->update_connection_ = event::Events::ConnectWorldUpdateBegin(
                boost::bind(&GenericSprayerPlugin::OnUpdate, this));
    }

    void GenericSprayerPlugin::OnUpdate()
    {

        std::string _name = "generic_sprayer::sprayer_1::spray_cone";
            std::string _parentName = "generic_sprayer::sprayer_1";

        msgs::Visual visualMsg;
        visualMsg.set_name(_name);
        visualMsg.set_parent_name(_parentName);

        //ROS_ERROR("HELL");


        //std::string _tt = spray_link->GetScopedName();



        //ROS_ERROR(_tt.c_str());
        //ROS_ERROR(parent->GetScopedName().c_str());

        if (!Sprayer_inputMsg.valve)
            visualMsg.set_transparency(0);
        else
            visualMsg.set_transparency(1.0);

        visPub->Publish(visualMsg);

    }

    void GenericSprayerPlugin::QueueThread()
    {
        static const double timeout = 0.01;
        while ( alive_ && gazebo_ros_->node()->ok() ) {
            queue_.callAvailable ( ros::WallDuration ( timeout ) );
        }
    }

    // Finalize the plugin
    void GenericSprayerPlugin::FiniChild()
    {
        alive_ = false;
        queue_.clear();
        queue_.disable();
        gazebo_ros_->node()->shutdown();
        callback_queue_thread_.join();
    }

    void GenericSprayerPlugin::onVizUpdate(const generic_sprayer_plugin::Sprayer_input::ConstPtr& msg)
    {
        Sprayer_inputMsg.header = msg->header;
        Sprayer_inputMsg.valve = msg->valve;
    }
}

I think I am either not publishing the msgs::Visual message correctly or connection incorrectly to ("~/visual"); But I have not found a way to verify what is actually going wrong.

I have tried to implement similar solution to the code in : HaptixWorldPlugin FootballDemoPlugin whitout any succes for both cases.

The main difference is that I am also using ROS and therefore using a differrent type of gazebo plugin. I hope I can get some hints on what I am doing wrong :-\

edit retag flag offensive close merge delete

Comments

Do you see your message being published while echoing it? `gz topic -e /gazebo/default/visual` Also double check the visual name. Finally, could you try starting from an opaque cone? It could be that the original transparency is interfering with the new one, that would be a bug.

chapulina gravatar imagechapulina ( 2016-08-23 10:18:51 -0600 )edit