bitcraze / crazyflie-simulation

MIT License
61 stars 27 forks source link

Get Multicopter velocity control to work with the crazyflie model #6

Open knmcguire opened 2 years ago

knmcguire commented 2 years ago

The multi copter velocity control in gazebo could also control the crazyflie, but it needs the right drag and thrust constants and the right gains.

knmcguire commented 2 years ago

See this branch https://github.com/bitcraze/crazyflie-simulation/tree/pid_gazebo

mhl787156 commented 3 months ago

Hi @knmcguire I've just started using the aerostack2 crazyflie sim stack for a project I'm working on! I've managed to get their model to takeoff (gazebo topics updated)! But the multicopter-velocity-control plugin is just not working:

      <plugin
        filename="ignition-gazebo-multicopter-control-system"
        name="ignition::gazebo::systems::MulticopterVelocityControl">
        <robotNamespace>model/{{ namespace }}</robotNamespace>
        <commandSubTopic>cmd_vel</commandSubTopic>
        <motorControlPubTopic>command/motor_speed</motorControlPubTopic>
        <enableSubTopic>velocity_controller/enable</enableSubTopic>
        <comLinkName>base_link</comLinkName>
        <velocityGain>1000 1000 5000</velocityGain>
        <attitudeGain>0.5 0.5 0.5</attitudeGain>
        <angularRateGain>1.5 1.5 1.5</angularRateGain> 

        <rotorConfiguration>
          <rotor>
            <jointName>crazyflie/m1_joint</jointName>
            <forceConstant>1.28192e-08</forceConstant>
            <momentConstant>0.005964552</momentConstant>
            <direction>1</direction>
          </rotor>
          <rotor>
            <jointName>crazyflie/m2_joint</jointName>
            <forceConstant>1.28192e-08</forceConstant>
            <momentConstant>0.005964552</momentConstant>
            <direction>-1</direction>
          </rotor>
          <rotor>
            <jointName>crazyflie/m3_joint</jointName>
            <forceConstant>1.28192e-08</forceConstant>
            <momentConstant>0.005964552</momentConstant>
            <direction>1</direction>
          </rotor>
          <rotor>
            <jointName>crazyflie/m4_joint</jointName>
            <forceConstant>1.28192e-08</forceConstant>
            <momentConstant>0.005964552</momentConstant>
            <direction>-1</direction>
          </rotor>
        </rotorConfiguration>
      </plugin>

I think they copied a model from this repo about a year/two years ago. No idea if the drag, thrusts, force or moment constants are correct, and I have no idea where the gains come from.

You can see a plotjuggler picture of the current controller here.

Wondering if you had any suggestions on how I might be able to tune the thing? I've spent a day semi-randomly testing gains and it all looks really similar! The drone just oscillates around weirdly semi-stably and randomly limps towards a target. I'm not sure if there's a way of isolating the rates or attitude controllers.

Or whether this is more hassle than its worth and I should try and interate the PID(?) Controller you have in this repo. End of the day all i want is some stable flight!

Thanks!

knmcguire commented 3 months ago

hmm oke interesting that aerostack2 wasn't able to get this to work either to work in all this time, which is a bit worrying.

The difference is that they tried to get it to work with the gazebo's embedded velocity controller (based on lee's controller) https://gazebosim.org/api/gazebo/6.7/classignition_1_1gazebo_1_1systems_1_1MulticopterVelocityControl.html. I think this might be the most chance of success here, but unfortunate I wouldn't know how to tune this properly I'm afraid