0
$\begingroup$

I've written a custom plugin for igntion gazebo just to see if I'm doing it right. Below is the .cc file of the plugin and its implementation in the sdf file.

There is a little section at the end that should print an ignmsg, but I don't where this should be printing or if I'm calling the plugin correctly to run the PostUpdate function in the code. I run gazebo with verbosity level 4 yet nothing comes out. If anyone could help me out that would be great!

Edit: As a make do solution for now, I have been using the ignerr command, but I'd like to get the ignmsg command working so I can differentiate between two types of message.

Plugin.cc code

// We'll use a string and the ignmsg command below for a brief example.
// Remove these includes if your plugin doesn't need them.
#include <string>
#include <ignition/common/Console.hh>

// This header is required to register plugins. It's good practice to place it
// in the cc file, like it's done here.
#include <ignition/plugin/Register.hh>

// Don't forget to include the plugin's header.
#include "TestbedWrench.hh"

// This is required to register the plugin. Make sure the interfaces match
// what's in the header.
IGNITION_ADD_PLUGIN(
    testbed_wrench::TestbedWrench,
    ignition::gazebo::System,
    testbed_wrench::TestbedWrench::ISystemPostUpdate)

using namespace testbed_wrench;

// Here we implement the PostUpdate function, which is called at every
// iteration.
void TestbedWrench::PostUpdate(const ignition::gazebo::UpdateInfo &_info,
    const ignition::gazebo::EntityComponentManager &/*_ecm*/)
{
  // This is a simple example of how to get information from UpdateInfo.
  std::string msg = "Testbed Wrench plugin working, ignore that -> ";
  if (!_info.paused)
    msg += "not ";
  msg += "paused.";

  // Messages printed with ignmsg only show when running with verbosity 3 or
  // higher (i.e. ign gazebo -v 3)
  ignmsg << msg << std::endl;
}

Implemtation in sdf file

?xml version="1.0" ?>
<sdf version="1.8">
    <world name="forfly_world">
        <physics name="1ms" type="ignored">
            <max_step_size>0.001</max_step_size>
            <real_time_factor>1.0</real_time_factor>
        </physics>
        <plugin
          filename="libignition-gazebo-apply-link-wrench-system.so"
          name="gz::sim::systems::ApplyLinkWrench">
        </plugin>
        <plugin
            filename="libignition-gazebo-physics-system.so"
            name="ignition::gazebo::systems::Physics">
        </plugin>
        <plugin
            filename="libignition-gazebo-user-commands-system.so"
            name="ignition::gazebo::systems::UserCommands">
        </plugin>
        <plugin
            filename="libignition-gazebo-scene-broadcaster-system.so"
            name="ignition::gazebo::systems::SceneBroadcaster">
        </plugin>
        <plugin
            filename='TestbedWrench' name='testbed_wrench::TestbedWrench'>
        </plugin>

        <light type="directional" name="sun">
            <cast_shadows>true</cast_shadows>
            <pose>0 0 10 0 0 0</pose>
            <diffuse>0.8 0.8 0.8 1</diffuse>
            <specular>0.2 0.2 0.2 1</specular>
            <attenuation>
                <range>1000</range>
                <constant>0.9</constant>
                <linear>0.01</linear>
                <quadratic>0.001</quadratic>
            </attenuation>
            <direction>-0.5 0.1 -0.9</direction>
        </light>

        <model name="ground_plane">
            <static>true</static>
            <link name="link">
                <collision name="collision">
                <geometry>
                    <plane>
                    <normal>0 0 1</normal>
                    </plane>
                </geometry>
                <surface>
                    <friction>
                        <ode>
                            <mu>0.0009</mu> 
                            <mu2>0.0009</mu2>
                        </ode>
                    </friction>
                </surface>
                </collision>
                <visual name="visual">
                <geometry>
                    <plane>
                    <normal>0 0 1</normal>
                    <size>100 100</size>
                    </plane>
                </geometry>
                <material>
                    <ambient>0.8 0.8 0.8 1</ambient>
                    <diffuse>0.8 0.8 0.8 1</diffuse>
                    <specular>0.8 0.8 0.8 1</specular>
                </material>
                </visual>
            </link>
        </model>
    </world>
</sdf>
$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.