Controlling digital servo through PWM output(s) on VOXL 2 IO expander board
-
Hi, I am trying to control a gimbal from onboard a VOXL 2 connected through the m0065 expander board. PWM channels 5-8 are apparently usable but I have no idea how to actually control them onboard the drone (i.e. I have no clue what QGC is doing under the hood in the actuators tab). Ideally the gimbal control script would fit cleanly into the set of ROS2 nodes I already have running on the drone, but it doesn't seem like the microdds agent advertises / subscribes to any of the uOrb messages related to servo control. If it's possible with MAVLINK directly I'll look to do it that way, but I wanted to ask for input first.
I was wondering if you guys could suggest a working approach to go about this, or provide some documentation I may have missed. Thanks!
-
@jonathankampia said in Controlling digital servo through PWM output(s) on VOXL 2 IO expander board:
Hi, I am trying to control a gimbal from onboard a VOXL 2 connected through the m0065 expander board. PWM channels 5-8 are apparently usable but I have no idea how to actually control them onboard the drone (i.e. I have no clue what QGC is doing under the hood in the actuators tab). Ideally the gimbal control script would fit cleanly into the set of ROS2 nodes I already have running on the drone, but it doesn't seem like the microdds agent advertises / subscribes to any of the uOrb messages related to servo control. If it's possible with MAVLINK directly I'll look to do it that way, but I wanted to ask for input first.
@jonathankampia the DDS does not publish to the servos actuator - technically you can add this to your microdds yaml and rebuild px4 for the voxl2 and then install the deb and that would work however I do not recommend this approach.
What QGC is doing is sending a mavlink command with the proper actuator/pwm signal to the bird in which the mavlink module in px4 on the drone decodes it and then publishes to uorb to the system for the driver to move the servos. To control the actuator/servo/gimbal ONBOARD the drone, I recommend using a tool like mavSDK: https://github.com/mavlink/MAVSDK-Python/tree/main
There is also a cpp implementation as well if that fits cleaner into your ros environment. Here is a modalAI docker instance that builds mavsdk for you and communicates over port 14551 provided it is enabled in vision hub.
https://gitlab.com/voxl-public/voxl-docker-images/voxl-docker-mavsdk/-/tree/main?ref_type=heads
Zach
-
@Zachary-Lowell-0 Hi, thanks for the reply. Based on what I have read, I think MAV_CMD_DO_SET_SERVO (183) from the MAVLINK common message set would be the correct one to send? With the fields set to channel=5 and PWM=pwm value.
import asyncio from mavsdk import System from mavsdk.mission import MissionItem, MissionPlan async def set_servo_pwm(channel, pwm_value): drone = System() await drone.connect(system_address="udp://:14540") # Wait for the drone to connect async for state in drone.core.connection_state(): if state.is_connected: print("Drone connected") break # Send the MAV_CMD_DO_SET_SERVO command await drone.action.do_set_servo(channel, pwm_value) print(f"Set servo on channel {channel} to PWM {pwm_value}") asyncio.run(set_servo_pwm(channel=5, pwm_value=1500))
I asked chatgpt for a quick example and it came up with this.
I mostly just want to avoid overriding a PWM value that the mixer is sending to channels 1-4 to actually fly the drone... Not completely sure if he pwm channel mappings make logical sense or are flipped or something weird.
-
@jonathankampia , were you able to first confirm that you can control the gimbal using the actuator test in QGC for the pwm channel 5 (make sure to remove propellers for testing, just in case)? it should work just like any other pwm channel, i am assuming you already have channels 1-4 already set up and working with ESCs?
If PWM actuator test is working through QGC, then you have VOXL2 IO board set up correctly and the rest of the logic for actually driving the pwm signal should be the same as for regular PX4 drone (which does not use VOXL).
At the end of the day, the VOXL2 IO driver receives 8 channel values from the mixer and just sends the desired pwm values out to the VOXL2 IO board. All the logic above the mixer is standard PX4 and if you have a question about that, you can also try the PX4 forum (since we are not necessarily the best PX4 experts).
You can try your python script, make sure propellers are off until you know exactly what you are doing and are ready to fly
Alex