Mavproxy/SITL : Issue with Python script, error "servorelayevent channel is already in use"

Hi,
I’m working on a Python script to send commands via Mavproxy to SITL/Arduplane

  • If I’m sending directly to Mavproxy servos commands like “RC 3 1800” it works fine
  • If I’m doing it with the script I’ve got the error message on Mavproxy

servorelayevent channel 3 is already in use

AP: ServoRelayEvent: Channel 2 is already in use
AP: ServoRelayEvent: Channel 1 is already in use
AP: ServoRelayEvent: Channel 3 is already in use

The RC commands in the Python script :

master.mav.command_long_send(
    master.target_system,
    master.target_component,
mavutil.mavlink.MAV_CMD_DO_SET_SERVO,
    0, # confirmation
    2, # param1
    1500, # param2
    0, # param3
    0, # param4
    0, # param5
    0, # param6
    0) # param7

master.mav.command_long_send(
    master.target_system,
    master.target_component,
mavutil.mavlink.MAV_CMD_DO_SET_SERVO,
    0, # confirmation
    1, # param1
    1500, # param2
    0, # param3
    0, # param4
    0, # param5
    0, # param6
    0) # param7


master.mav.command_long_send(
    master.target_system,
    master.target_component,
mavutil.mavlink.MAV_CMD_DO_SET_SERVO,
    0, # confirmation
    3, # param1
    1800, # param2
    0, # param3
    0, # param4
    0, # param5
    0, # param6
    0) # param7

In the config :

SERVO 1 + 2 + 3 are Ok dans MP
SERVO1_FUNCTION = Roll
SERVO2_FUNCTION = Pitch
SERVO3_FUNCTION = Throttle

After searching in the forum, and in the Mavlink documentation, it seems that “RC_CHANNELS_OVERRIDE” can be the solution (but not really sure …)

https://ardupilot.org/dev/docs/mavlink-move-servo.html
https://ardupilot.org/plane/docs/parameters.html#servo1-function-servo-output-function

So I tried these commands below to try to override a config (I don’t know wich one to be honest as all seems to be right…)
long MAVLINK_MSG_ID_RC_CHANNELS_OVERRIDE 0 0 70 0 0 0 0 0
long MAVLINK_MSG_ID_RC_CHANNELS_OVERRIDE 0 0 0 0 0 0 0 0
long MAVLINK_MSG_ID_RC_CHANNELS_OVERRIDE 0 0 1 0 0 0 0 0

And well still same problem, if anyone has an idea, you’re welcome !
Thanks
Nico

MAV_CMD_DO_SET_SERVO

set the servo/motors output, that is different from the rc X XXXX function in mavproxy that set the RC inputs values !

mavproxy code is here : https://github.com/ArduPilot/MAVProxy/blob/master/MAVProxy/modules/mavproxy_rc.py you can copy it !

1 Like

Many thanks @khancyr , I’ll try and reply.

Hi @khancyr

For my knowledge, what is the difference between passing RC servos commands directly to mavproxy through the terminal like “RC 3 1800” and sending these commands by Python ?
The script is connecting with TCP to Mavproxy and it seems that it’s just another way to send these commands.

I’ve checked mavproxy_rc.py, some questions :

  • Is it some piece of code to add to any Python script using RC servo commands, like mine ? Something “generic” to make everything in the right shape ? Or maybe a script to launch ?
  • Is there something to modify in it or I need to use some parts for my needs ?
    Sorry for these questions, I don’t have enough Python level and enough Mavproxy understanding I suppose !

Thanks
Nico

sorry to bothering you but can you please teach me how to take off an fixed wing plane by Python script commands via Mavproxy to SITL/Arduplane? looking foward to your reply

Hi Zhang,

I’m trying to understand the last reply I received, that the answer is in mavproxy_rc.py
https://github.com/ArduPilot/MAVProxy/blob/master/MAVProxy/modules/mavproxy_rc.py

I’m still a bit lost as I don’t know which part of this script I need to use : the whole script seems to be a little bit to much only to send throttle/pitch/yaw/roll to a plane !

Is there another way less complicated ?

I found that : Pymavlink · GitBook

So I’m working on it actually.
Did you make any progress on your side ? Maybe someone can help on this post ? Anyway thanks for your help.

Nico

hi,Nicolas
Glad to hear from you. I thougt the forum is nearly dead before,so your reply really gives me a surprise.The gitbook about ardusub i happened to read not long ago. The good news is that it gives a simple python script example about rotating,but unfortunatly,the bad news is that ,it’s actually differrent from the plane.
The rotating way offered in the gitbook is not that good,either.First,it can’t control the turning speed.Second,the rotate perform in a circulation ,a small angle change in a small rotation step,Which means it is not seriously continueous.And there is a detail that , ardupilot world’s vehicles’ default coordinate system are differrent from each other. For example , i did an experiment on fixed wing plane and helicopterFor a fixed wing plane, if you send command like"send_target_attitude(target_roll,target_pitch,target_yaw)",with a mavutil.mavlink.MAV_FRAME_BODY_NED,.the mavlink message,then the fixed wing will change the attitude from the beginning attitude status,to your target roll,pitch,yaw.However, as for a helicopter sitl,the situation is differrent.the helicopter has a fixed coordinate system.For example,if a helicopter is facing north,you send send_target_attitude(target_roll,target_pitch,target_yaw=90) twice, it will turn 90 at first,but the second time it will not turn at all,because the system think that the plane is already in 90 in yaw!
As for other complaints for the pymavlink pythonscript way,i found no way to control the precise time for a movement.For example, set_target_attitude(3, -7, 0),I can only use time.sleep(1),to make sure the plane complete the process.The disadvantage of this way is obvious,we cannot make sure the next process begins just after the front one is complete.
As for your RC command’s problem, i am sad to tell you that i do not find ardupilot works well on manual mode,in my sitl,i just try python script in guide or auto mode.Or maybe you can ask chatgpt for manual details.ArduPilot之遥控器数据读取_渎取无人机摇控码_Chasing中的小强的博客-CSDN博客The blog might help.
In conclusion, my sitl doesn’t need the RC control yet.although we are differrent,i hope my experience in sitl guidedmode/auto mode might give you inspirations.the vehicles are different.the format of mavlink message matters

Hi Zhang,
To be honest using Python scripts to move a plane is not an easy task in Ardupilot. Maybe Mavsdk to be studied but it needs Px4 board, not same cost.