Home        Store        Learn        Blog

Pymavlink outputs PWM to the motor

How to use pymavlink to send PWM to control the motor, and the motor is connected to the mainout of pixhawk

I use the official MAV_ CMD_ DO_ SET_ The servo method, channel 1 and PWM 1100-1900, seems not feasible

Hi @Teshla, welcome to the forum :slight_smile:

The MAV_CMD_DO_SET_SERVO command only applies to non-motor outputs. If a PWM output is assigned as a motor then you won’t be able to control it as a servo. Control of individual thrusters with a single message isn’t possible with the current MAVLink specification, but there are some workarounds for it discussed here if you’re interested.

Is there a particular reason you want/need to control individual thrusters? Generally control is simpler when it’s abstracted to the motion directions you want to command (e.g. forwards, turn left, etc), so I’m curious what your use-case is.

I would note that if you’re wanting to make your own control algorithm instead of the ones that are already available in ArduSub, you’ll have much lower latency and more frequent sensor updates if you implement your algorithm(s) within ArduSub (e.g. as a custom/modified flight mode), rather than in Pymavlink. I understand Python is generally easier to get started with when testing things, but if your use-case requires high performance control then it makes the most sense to implement that in the flight controller board firmware :slight_smile:

By the way, I don’t need to control a single motor. I just want to use pymavlink to carry out some manual operations on the handle, such as forward and backward. In theory, the official manual_ control_ Can send help me with these operations

Right, ok. In that case I’d suggest looking at our Send RC (Joystick) or Manual Control examples. I’ve recently made a more complete program here, if that’s of interest :slight_smile:

I have another question. Do you want to use GStreamer to get the video returned by raspberry Pi?

I’m not sure what you’re asking here - what I want to do with my video streams is unrelated to what you might want to do with yours.

If you’re asking for details on how the current video streaming system works, the Companion software (on the Raspberry Pi) by default forwards a H264-encoded stream from the camera as a UDP stream to the topside computer at port 5600. You can receive that with gstreamer, VLC, or your software of choice. QGroundControl uses gstreamer internally, if that’s relevant :slight_smile:

Relevant, OK, thank you for your clarification