Multiple MAVs in MissionPlanner Python Script

I am trying to implement flocking via Python in MissionPlanner. So far, when I have multiple UAVs connected via one RFD900 radio on the ground station, ‘cs’ only gives me the information from the UAV in selected in the dropdown in the top right. I can’t find anything in the documentation for how to access the other MAVs. Is there a way to receive position updates from (and send RC commands to) all UAVs connected to MissionPlanner?

If not, what is your suggested implementation?

Thanks,
Chris

1 Like

since you are using one radio. look at

MAV.MAVlist[0].cs etc.

Awesome, thanks! Where would I find more documentation about stuff like this? Given that data structure, I can receive all information I need, but I need to send RC overrides or similar to each UAS, which the examples do by using Script.SendRC(). Is there another way?

Chris

to send to other MAV’s you will need to craft the packet yourself. at this point in time.

Thanks! I dug around for a while and haven’t been able to find a function to send an arbitrary MAVlink packet from the Python interface. Could you point me in the right direction? Would problems arise from just writing to ‘MAV.sysidcurrent’ for each MAV? Some documentation implies that that can be bad, but I’m grasping at straws to get this to work

I hope that someone in the future finds this and can use the insight you are providing as well.

Chris

please check example2.py in the scripts MP folder.

and
MAV.sendPacket(commandlong,sysid,compid)

I can’t believe I missed that!

mavlink_command_int_t.param1.SetValue(commandlong,cmdToSend1 )

expects cmdToSend1 to be a single, but the MAVlink command looks to be sending UInt16s. Is the correct way to proceed to generate several singles with bits that are equivalent to 2 uint16s, and set param1,param2, etc?

I investigated two other routes of sending the command:

RC = MAVLink.mavlink_rc_channels_override_t()
RC.chan1_raw = x
...
MAV.sendPacket(RC, RC.target_system, RC.target_component )

,
yields a warning:

warning: RuntimeWarning: Setting field chan1_raw on value type mavlink_rc_channels_override_t may result in updating a copy. Use mavlink_rc_channels_override_t.chan1_raw.SetValue(instance, value) if this is safe. For more information help(mavlink_rc_channels_override_t.chan1_raw.SetValue).

and has no effect.

MAVLink.mavlink_rc_channels_override_t.chan1_raw.SetValue(instance,x)

, but I am not sure of what to use for instance. MAVID seems not to work.

I also found that, in SITL with XPlane, when using Script.SendRC(), stopping the script results in MissionPlanner keeping the RC override last sent when the script was aborted. I worry about this from an FMEA perspective. Have I misconfigured something, or is this just the way things are? Would unplugging the ground-station give control back to actual RC transmitters? Is there a way in MissionPlanner to return all RC control to the physical RC transmitters?

Thanks again for all your help!

So, though some very sketch code, I got the bits of two UNIT_16s into a Single, and sent that using the following code:

x= 1500
y=1700
MAVID=1
cmdToSend1=struct.unpack('@f',struct.pack('@H',x ) + struct.pack('@H',y ))
cmdToSend1 = Single(cmdToSend1[0])

commandlong = mavlink_command_long_t()
mavlink_command_long_t.param1.SetValue(commandlong,cmdToSend1)
mavlink_command_long_t.command.SetValue(commandlong, 70)
mavlink_command_long_t.target_system.SetValue(commandlong,MAVID)
mavlink_command_long_t.target_component.SetValue(commandlong,190)
MAV.sendPacket(commandlong,255,190)

I also attempted a variety of target_component, as well as sending component and sending system values, including sending from 255:90, 255:1, 255:0, all to no effect. Note that example2.py calls sendPacket with only one parameter, which seems to no longer work. I am seeing no confirmation that MissionPlanner or my MAV are receiving the commends.

Could you point me further in the right direction?

Thank you,
Chris

Hi Chris,

I am working on a very similar project and I was wondering how you got all of the UAVs connected through a Python script? That is the part that I am struggling with right now.