Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

array elements are skipped

I want to make the joints of robot rotated at 0, 90, 180, 270 degrees, but it only shows 90 and 270 degrees repeatedly. I output the joint's angle to the terminal, and actually four angles show periodically. However I do the different test, it always skips one element between two array elements. Does anyone know how to solve this problem? Here is my plugin code.

#include <functional>
#include <gazebo/gazebo.hh>
#include <gazebo/common/common.hh>
#include <ignition/math/Vector3.hh>
#include <gazebo/physics/physics.hh>
#include <stdio.h>

using namespace std;

namespace gazebo
{
  int count = 0;
  float pos[4] = {0, 1.57, 3.14, 4.71};

  class ModelPush : public ModelPlugin
  {
    public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/)
    {
      this->model = _parent;
      this->updateConnection = event::Events::ConnectWorldUpdateBegin(std::bind(&ModelPush::OnUpdate, this));
    }

    public: void OnUpdate()
    {
       this->model->GetJoint("joint1")->SetPosition(0, pos[count%4]);
       this->model->GetJoint("joint1")->>Update();
       this->model->GetJoint("joint2")->SetPosition(0, pos[count%4]);
       this->model->GetJoint("joint2")->>Update();

       cout << fixed << this->model->GetJoint("joint1")->GetAngle(0).Radian() << "\t";
       cout << fixed << this->model->GetJoint("joint2")->GetAngle(0).Radian() << "\t" << endl;

       count++;
       usleep(500000);
    }

    private: physics::ModelPtr model;
    private: event::ConnectionPtr updateConnection;
  };
  GZ_REGISTER_MODEL_PLUGIN(ModelPush)
}

array elements are skipped

I want to make the joints of robot rotated at 0, 90, 180, 270 degrees, but it only shows 90 and 270 degrees repeatedly. I output the joint's angle to the terminal, and actually four angles show periodically. However I do the different test, it always skips one element between two array elements. Does anyone know how to solve this problem? Here is my plugin code.

#include <functional>
#include <gazebo/gazebo.hh>
#include <gazebo/common/common.hh>
#include <ignition/math/Vector3.hh>
#include <gazebo/physics/physics.hh>
#include <stdio.h>

using namespace std;

namespace gazebo
{
  int count = 0;
  float pos[4] = {0, 1.57, 3.14, 4.71};

  class ModelPush : public ModelPlugin
  {
    public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/)
    {
      this->model = _parent;
      this->updateConnection = event::Events::ConnectWorldUpdateBegin(std::bind(&ModelPush::OnUpdate, this));
    }

    public: void OnUpdate()
    {
       this->model->GetJoint("joint1")->SetPosition(0, pos[count%4]);
       this->model->GetJoint("joint1")->>Update();
       this->model->GetJoint("joint2")->SetPosition(0, pos[count%4]);
       this->model->GetJoint("joint2")->>Update();

       cout << fixed << this->model->GetJoint("joint1")->GetAngle(0).Radian() << "\t";
       cout << fixed << this->model->GetJoint("joint2")->GetAngle(0).Radian() << "\t" << endl;

       count++;
       usleep(500000);
    }

    private: physics::ModelPtr model;
    private: event::ConnectionPtr updateConnection;
  };
  GZ_REGISTER_MODEL_PLUGIN(ModelPush)
}

array Array elements are skipped

I want to make move the joints of my robot rotated at 0, 90, 180, 270 degrees, but it only shows displays the state of 90 and 270 degrees on gazebo repeatedly. I output the joint's angle results to the terminal, and actually four angles show periodically. periodically, and counts are formally 0,1,2,3,4,5,6.... However I do the different test, it tests, the robot always skips one element between two array elements. elements on gazebo. Does anyone know how to solve this problem? Here is my plugin code.

#include <functional>
#include <gazebo/gazebo.hh>
#include <gazebo/common/common.hh>
#include <ignition/math/Vector3.hh>
#include <gazebo/physics/physics.hh>
#include <stdio.h>

using namespace std;

namespace gazebo
{
  int count = 0;
  float pos[4] = {0, 1.57, 3.14, 4.71};

  class ModelPush : public ModelPlugin
  {
    public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/)
    {
      this->model = _parent;
      this->updateConnection = event::Events::ConnectWorldUpdateBegin(std::bind(&ModelPush::OnUpdate, this));
    }

    public: void OnUpdate()
    {
       this->model->GetJoint("joint1")->SetPosition(0, pos[count%4]);
       this->model->GetJoint("joint1")->>Update();
       this->model->GetJoint("joint2")->SetPosition(0, pos[count%4]);
       this->model->GetJoint("joint2")->>Update();

       cout << fixed << this->model->GetJoint("joint1")->GetAngle(0).Radian() << "\t";
       cout << fixed << this->model->GetJoint("joint2")->GetAngle(0).Radian() << "\t" << count << endl;

       count++;
       usleep(500000);
    }

    private: physics::ModelPtr model;
    private: event::ConnectionPtr updateConnection;
  };
  GZ_REGISTER_MODEL_PLUGIN(ModelPush)
}

Array elements are skipped

I want to move the joints of my robot at 0, 90, 180, 270 degrees, but it only displays the state of 90 and 270 degrees on gazebo repeatedly. I output the results to the terminal, and actually four angles show periodically, and counts are formally 0,1,2,3,4,5,6.... However I do the different tests, the robot always skips one element between two array elements on gazebo. Does anyone know how to solve this problem? Here is my plugin code.

#include <functional>
#include <gazebo/gazebo.hh>
#include <gazebo/common/common.hh>
#include <ignition/math/Vector3.hh>
#include <gazebo/physics/physics.hh>
#include <stdio.h>

using namespace std;

namespace gazebo
{
  int count = 0;
  float pos[4] = {0, 1.57, 3.14, 4.71};

  class ModelPush : public ModelPlugin
  {
    public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/)
    {
      this->model = _parent;
      this->updateConnection = event::Events::ConnectWorldUpdateBegin(std::bind(&ModelPush::OnUpdate, this));
    }

    public: void OnUpdate()
    {
       this->model->GetJoint("joint1")->SetPosition(0, pos[count%4]);
       this->model->GetJoint("joint1")->>Update();
       this->model->GetJoint("joint2")->SetPosition(0, pos[count%4]);
       this->model->GetJoint("joint2")->>Update();

       cout << fixed << this->model->GetJoint("joint1")->GetAngle(0).Radian() << "\t";
       cout << fixed << this->model->GetJoint("joint2")->GetAngle(0).Radian() << "\t" << count << endl;

       count++;
       usleep(500000);
    }

    private: physics::ModelPtr model;
    private: event::ConnectionPtr updateConnection;
  };
  GZ_REGISTER_MODEL_PLUGIN(ModelPush)
}

Array elements are skipped

I want to move the joints of my robot at 0, 90, 180, 270 degrees, but it only displays the state of 90 and 270 degrees on gazebo repeatedly. I output the results to the terminal, and actually four angles show periodically, and counts are formally 0,1,2,3,4,5,6.... However I do the different tests, the robot always skips one element between two array elements on gazebo. Does anyone know how to solve this problem? Here is my plugin code.

#include <functional>
#include <gazebo/gazebo.hh>
#include <gazebo/common/common.hh>
#include <ignition/math/Vector3.hh>
#include <gazebo/physics/physics.hh>
#include <stdio.h>

using namespace std;

namespace gazebo
{
  int count = 0;
  float pos[4] = {0, 1.57, 3.14, 4.71};

  class ModelPush : public ModelPlugin
  {
    public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/)
    {
      this->model = _parent;
      this->updateConnection = event::Events::ConnectWorldUpdateBegin(std::bind(&ModelPush::OnUpdate, this));
    }

    public: void OnUpdate()
    {
       this->model->GetJoint("joint1")->SetPosition(0, pos[count%4]);
       this->model->GetJoint("joint1")->>Update();
       this->model->GetJoint("joint2")->SetPosition(0, pos[count%4]);
       this->model->GetJoint("joint2")->>Update();

       cout << fixed << this->model->GetJoint("joint1")->GetAngle(0).Radian() << "\t";
       cout << fixed << this->model->GetJoint("joint2")->GetAngle(0).Radian() << "\t" << count << endl;

       count++;
       usleep(500000);
    }

    private: physics::ModelPtr model;
    private: event::ConnectionPtr updateConnection;
  };
  GZ_REGISTER_MODEL_PLUGIN(ModelPush)
}

Array elements are skipped

I want to move the joints of my robot at 0, 90, 180, 270 degrees, but it only displays the state of 90 and 270 degrees on gazebo repeatedly. I output the results to the terminal, and actually four angles show periodically, and counts are formally 0,1,2,3,4,5,6.... However I do the different tests, the robot always skips one element between two array elements on gazebo. Does anyone know how to solve this problem? Here is my plugin code.

#include <functional>
#include <gazebo/gazebo.hh>
#include <gazebo/common/common.hh>
#include <ignition/math/Vector3.hh>
#include <gazebo/physics/physics.hh>
#include <stdio.h>

using namespace std;

namespace gazebo
{
  int count = 0;
  float pos[4] = {0, 1.57, 3.14, 4.71};

  class ModelPush : public ModelPlugin
  {
    public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/)
    {
      this->model = _parent;
      this->updateConnection = event::Events::ConnectWorldUpdateBegin(std::bind(&ModelPush::OnUpdate, this));
    }

    public: void OnUpdate()
    {
       this->model->GetJoint("joint1")->SetPosition(0, pos[count%4]);
       this->model->GetJoint("joint1")->>Update();
       this->model->GetJoint("joint2")->SetPosition(0, pos[count%4]);
       this->model->GetJoint("joint2")->>Update();

       cout << fixed << this->model->GetJoint("joint1")->GetAngle(0).Radian() << "\t";
       cout << fixed << this->model->GetJoint("joint2")->GetAngle(0).Radian() << "\t" << count << endl;

       count++;
       usleep(500000);
    }

    private: physics::ModelPtr model;
    private: event::ConnectionPtr updateConnection;
  };
  GZ_REGISTER_MODEL_PLUGIN(ModelPush)
}