Robotics StackExchange | Archived questions

Animation plugin, animation with known positions

hi, guys. I am working on this project to simulate a short video of vehicles in Gazebo. I have followed the animated box tutorials, and my intention is to spawn animate cars' trajectory with known x,y locations, running with gazebo 7 with ubuntu 16.04. I have some codes that import an excel file containing the x,y coordinates into posArray, and want to animate each individual cars with different sets of x, y coordinates. So far, I can get one car moving but to populate more vehicles, I need to add multiple models in my world files, which are not very desirable. Any advice?

namespace gazebo {

class AnimatedBox : public ModelPlugin { public: void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf) {

            int numLines = CountLines();

            if (_sdf->HasElement("velocity"))                       
                    velocity = _sdf->Get<string>("velocity");

             std::cout << "velocity is " << velocity << std::endl;
            //this->SetVelocity(velocity);
            float posArray[100][2] = {0.00}; //initialise the position array;

            GetPosition(posArray);

            // Store the pointer to the model
            this->model = _parent;

            // create the animation
            //  for (int i = 0; i < 2; i ++){
            gazebo::common::PoseAnimationPtr anim(
                // name the animation "test",
                // make it last 10 seconds,
                // and set it on a repeat loop
                new gazebo::common::PoseAnimation("test", 10, true));

            gazebo::common::PoseKeyFrame *key;

            for (int i = 0; i < 30; i++)
            {

                    key = anim->CreateKeyFrame(i);
                    key->Translation(ignition::math::Vector3d(posArray[i][0], posArray[i][1], 0));
            }
            _parent->SetAnimation(anim);
    }


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

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

};

// Register this plugin with the simulator
GZ_REGISTER_MODEL_PLUGIN(AnimatedBox)

}

Asked by rob00009 on 2019-03-18 13:51:05 UTC

Comments

Answers