Gazebo | Ignition | Community
Ask Your Question
0

error: cannot convert ‘ignition::gazebo::v3::components::Component<std::vector<double> to ‘float’

asked 2021-04-14 18:25:29 -0500

updated 2021-04-14 18:29:00 -0500

I am trying to get the joint's position for my Cessna plugin using this method

float rudder =  _ecm.Component<components::JointPosition>(this->joint[5.0]);

which gives me this error in the line shown above

 error: cannot convert ‘ignition::gazebo::v3::components::Component<std::vector<double>, ignition::gazebo::v3::components::JointPositionTag, ignition::gazebo::v3::serializers::VectorDoubleSerializer>*’ to ‘float’ in initialization

     float rightFlap =  _ecm.Component<components::JointPosition>(this->joint[3.0]);

code snippet

    void CessnaPlugin::PublishState(EntityComponentManager &_ecm)

    {
        IGN_PROFILE("CessnaPlugin::PublishState");

        // Read current state

        double propellerRpms = _ecm.ComponentData<components::JointVelocity>(this->joint[6.0])/(2.0*M_PI)*60.0;

        float propellerSpeed = propellerRpms / this->propellerMaxRpm;

        float leftAileron = _ecm.Component<components::JointPosition>(this->joint[2500]);

        float leftFlap =  _ecm.Component<components::JointPosition>(this->joint[1.0]);

        float rightAileron =  _ecm.Component<components::JointPosition>(this->joint[2.0]);

       float rightFlap =  _ecm.Component<components::JointPosition>(this->joint[3.0]);

        float elevators =  _ecm.Component<components::JointPosition>(this->joint[4.0]);

        float rudder =  _ecm.Component<components::JointPosition>(this->joint[5.0]); ----> error occurs here

}

joint entity as declared

std::array<ignition::gazebo::Entity, 7> joint;

parameters

   private: static const unsigned int kLeftAileron  = 0;

    private: static const unsigned int kLeftFlap     = 1;

    private: static const unsigned int kRightAileron = 2;

   private: static const unsigned int kRightFlap    = 3;

    private: static const unsigned int kElevators    = 4;

    private: static const unsigned int kRudder       = 5;

    private: static const unsigned int kPropeller    = 6;

Any solution for this?

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2021-04-16 06:19:39 -0500

updated 2021-04-16 06:24:20 -0500

refer this issue.

Thanks to Diego Ferigo for this answer.

A joint in its most generic form can have more than one degree of freedom. This is the reason why the JointPosition component stores a vector:

ign-gazebo/include/ignition/gazebo/components/JointPosition.hh

Lines 38 to 39 in a41cf80

 using JointPosition = Component<std::vector<double>, class JointPositionTag, 
                                 serializers::VectorDoubleSerializer>;

In 99% of cases, you're using either a revolute or prismatic joint, therefore the vector contains only one element:

const auto& jointPosition = _ecm.ComponentData<components::JointVelocity>(jointEntity);
assert(jointPosition.size() == 1);
const double position = jointPosition[0];
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-04-14 18:25:29 -0500

Seen: 93 times

Last updated: Apr 16 '21