PX4 / PX4-gazebo-models

Model repo in app.gazebosim.org
BSD 3-Clause "New" or "Revised" License
20 stars 64 forks source link

Is there any way to contorl the gimbal in x500_gimbal #55

Open brunocentanaro opened 2 months ago

brunocentanaro commented 2 months ago

Hello, I could add x500_gimbal and now seeking help on how to move the gimbal for my needs. I noticed at the end of the file the plugins with the sub-topics for the joints but running gz topic -l I could not find these.

Thanks in advance!

hamishwillee commented 2 months ago

Perhaps @StefanoColli or @Jaeyoung-Lim can answer your question. Looking at the equivalent PX4 PR https://github.com/PX4/PX4-Autopilot/pull/23382 I'd guess it isn't quite ready for use.

brunocentanaro commented 2 months ago

Actually I actually kind of got it working with that PR! This are the steps I followed:

import asyncio
from mavsdk import System

drone = System()

DELAY_FOR_CORRECTING_GIMBAL = 0.3

async def manual_control_drone(my_drone):
    while True:
        await asyncio.sleep(DELAY_FOR_CORRECTING_GIMBAL)
        async for attitude in drone.telemetry.attitude_euler():
            roll = attitude.roll_deg
            pitch = attitude.pitch_deg
            await my_drone.gimbal.set_angles(-roll, -pitch, -180)

async def run_drone():
    await drone.connect(system_address="udp://:14540")
    async for state in drone.core.connection_state():
        if state.is_connected:
            print(f"-- Connected to drone!")
            break
    # Checking if Global Position Estimate is ok
    async for health in drone.telemetry.health():
        if health.is_global_position_ok and health.is_home_position_ok:
            print("-- Global position state is good enough for flying.")
            break
    asyncio.ensure_future(manual_control_drone(drone))

async def run():
    await asyncio.gather(run_drone())

def main():
    asyncio.ensure_future(run())
    asyncio.get_event_loop().run_forever()

I got my gimbal stabilized. I could not have it working with ros topics/messages unfortunately so I don't think I can change the behaviour for the gimbal programatically but for my use case this is mostly fine.

DronecodeBot commented 2 months ago

This issue has been mentioned on Discussion Forum for PX4, Pixhawk, QGroundControl, MAVSDK, MAVLink. There might be relevant details there:

https://discuss.px4.io/t/how-to-control-the-gimbal-with-ros2-in-gazebo/40727/3

StefanoColli commented 2 months ago

Yes, as @hamishwillee mentioned you will be able to control the x500_gimbal only once this PR gets merged into PX4