I'm a little bit confused about this one. As what I understood, rc channel_overrides are one-liner codes that sends a command for three seconds (as what I've observed. I tried running only the rc channel overrides and the commands are implemented for three seconds, too.)
I tried doing loops to see if it stops once the loop is finished, however, it does not. There will always be an offset of three seconds (my estimation) until it stops even though I have overridden the RC signal by 1500. My min and max values are 1100 and 1900. Here's the sample code.
counter = 0
while counter != 1000:
vehicle.channels.overrides = {'3':1900}
counter += 1
vehicle.channels.overrides = {'3':1500}
Now, when I tried doing recursive function, it works. Here's my sample code:
def forward(seconds):
if seconds <= 3:
vehicle.channels.overrides = {'3':1900}
time.sleep(seconds)
vehicle.channels.overrides = {'3':1500}
else:
vehicle.channels.overrides = {'3':1900}
time.sleep(3)
forward(seconds - 3)
Now, I'm curious why it doesn't work under while loops and works in recursive functions. Also, I'm trying to send an rc signal and make a full stop once a condition is met that's why I need to understand the problem with using the loops. Thanks
Your implementation of the "while" loop does not work because your logic is wrong.
Look at the first two lines of logic in your first example. First, you set counter to 100. Then, you say if the counter is not 100, then override the rc channel to the 1900 max. The line that reads vehicle.channels.overrides = {'3':1900}
is not run because the value of counter is set to 100.
Also, be aware that overriding the rc channels is a bit of a "hacky" solution. Per the dronekit-python docs:
Channel overrides (a.k.a. “RC overrides”) are highly dis-commended (they are primarily intended for simulating user input and when implementing certain types of joystick control).
Instead use the appropriate MAVLink commands like DO_SET_SERVO/DO_SET_RELAY, or more generally set the desired position or direction/speed.
If you have no choice but to use a channel-override please explain why in a Github issue and we will attempt to find a better alternative.
Because of this, I would also advise you to not rely on the RC override lasting for 3 seconds.