Gazebo | Ignition | Community
Ask Your Question
0

Pose of Collision entity

asked 2013-03-28 05:12:59 -0500

Max Stähr gravatar image

Hi,

I am trying to retrieve the current Pose of all Collision entities. However I just can retrieve the initial Pose before starting the physics engine. The complete plugin code is pasted below.

include <boost bind.hpp=""> include <gazebo.hh> include <physics physics.hh=""> include <common common.hh=""> include <stdio.h>

using namespace std;

namespace gazebo
{   
  class ModelPush : public ModelPlugin
  {
    public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/) 
    {
      // Store the pointer to the model
      this->model = _parent;

      //frame
      frame=0;

      // Listen to the update event. This event is broadcast every
      // simulation iteration.
      this->updateConnection = event::Events::ConnectWorldUpdateBegin(
          boost::bind(&ModelPush::OnUpdate, this, _1));

    }

    // Called by the world update start event
    public: void OnUpdate(const common::UpdateInfo & /*_info*/)
    {
      // Apply a small linear velocity to the model.
      std::cout << "collision test" << std::endl;





      system("clear");
      cout << "frame\t" << frame << endl;
      frame = frame +1;

      physics::Link_V links = model->GetLinks();
      physics::Collision_V colls;
      for (unsigned int i = 0; i < links.size(); i++) {

          cout << links[i]->GetName() << "\t\t" <<links[i]->GetWorldPose() << endl;
          colls = links[i]->GetCollisions();
          for(unsigned i=0; i<colls.size(); i++)
          {
              colls[i]->Update();
              cout << colls[i]->GetName() << "\t\t" << colls[i]->GetWorldPose() << endl;
          }

      }

    }

    // Pointer to the model
    private: physics::ModelPtr model;

    // Pointer to the update event connection
    private: event::ConnectionPtr updateConnection;

    // Frame counter
    private: unsigned int frame;
  };

  // Register this plugin with the simulator
  GZ_REGISTER_MODEL_PLUGIN(ModelPush)
}

Can anyone help? What am I doing wrong?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2013-03-28 06:50:17 -0500

Max Stähr gravatar image

Hi,

there is a litte missunderstanding. I don't want to detect a contact between the the collision entities, rather I would like to know the current pose if the collision entity at each time step. I can manage to retrieve the current Pose of each link but not of any collision geometry...

Cheers Max

edit flag offensive delete link more

Comments

Oh sorry, so you are saying you get a constant value all the time? Is the object moving? Could you also post your sdf file?

AndreiHaidu gravatar imageAndreiHaidu ( 2013-03-28 07:24:41 -0500 )edit

Hi, I solved the problem myself. The WordPose of the corresponding Link is updated. By aggregating the relative Collision pose with the WorldLinkPose I can retrieve the WorldCollisionPose. However, it seems to be a bug in the Collision Code. The WorldPose of collision entities is not updated at runtime.

Max Stähr gravatar imageMax Stähr ( 2013-04-02 01:30:59 -0500 )edit

Hi, I solved the problem myself. The WordPose of the corresponding Link is updated. By aggregating the relative Collision pose with the WorldLinkPose I can retrieve the WorldCollisionPose. However, it seems to be a bug in the Collision Code. The WorldPose of collision entities is not updated at runtime.

Max Stähr gravatar imageMax Stähr ( 2013-04-02 01:31:03 -0500 )edit
0

answered 2013-03-28 05:56:48 -0500

AndreiHaidu gravatar image

Hi,

The way 'OnUpdate' is called on every world update, another function ('onContact') will be called when a collision is detected. Here is the main idea:

// set the collision you wish to check
physics::CollisionPtr collision = this->model->GetLink("link_name")->GetCollision("collision_name");

// during a collision the 'onContact' function will be called every update step
event::ConnectionPtr connection = collision->ConnectContact(boost::bind (&ModelPush::onContact, this, _1, _2));

// the 'onContact' function
void ModelPush::onContact(const std::string &_collisionName, const physics::Contact &_contact)
{ 
// do what you need with the contact 
 ...
}

Here you can find more about physics::Contact.

If you have any trouble implementing it, let me know.

Cheers, Andrei

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2013-03-28 05:12:59 -0500

Seen: 5,007 times

Last updated: Mar 28 '13