hello, we are uploading a code to our robot to go straight. We run the code on the raspberry pi. we use the send_rc_channels_pwm function for this. Instead of the movements we send, the robot turns around and makes meaningless movements. Can you help me?
My code is :
# Import mavutil
from pymavlink import mavutil
import time
# connection
master = mavutil.mavlink_connection(
'/dev/ttyACM0',
baud=115200)#
#arm robot
master.arducopter_arm()
time.sleep(3)
master.mav.set_mode_send(
master.target_system,
mavutil.mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED,
0) # stabilize mode
time.sleep(3)
def set_rc_channel_pwm(id, pwm=1500):
if id < 1:
print("Channel does not exist.")
return
if id < 9:
rc_channel_values = [65535 for _ in range(8)]
rc_channel_values[id - 1] = pwm
master.mav.rc_channels_override_send(
master.target_system,
master.target_component,
*rc_channel_values)
#forward
value = 1550
set_rc_channel_pwm(5, value)
time.sleep(5)
master.mav.command_long_send(
master.target_system,
master.target_component,
mavutil.mavlink.MAV_CMD_COMPONENT_ARM_DISARM,
0,
0, 0, 0, 0, 0, 0, 0) #disarm
Is there a reason this is via private message instead of as a public post? I’ll still see it if it’s public, and that also means others can chime in (possibly before I get to it), and others in the community can benefit from the solution afterwards as well.
I’m unsure what your custom flight mode does, so it’s not possible for me to tell you why the ROV isn’t moving as you expect.
This post is likely relevant:
Given this is a direct serial connection to the autopilot board I assume you’re trying to do this autonomously, and also likely not using our companion computer image - is that correct?
A few side-notes:
you can use master.motors_armed_wait() to wait until arming has succeeded (instead of waiting for a fixed period that provides no guarantees about the autopilot state, and could be unnecessarily long)
you can use master.arducopter_disarm() to disarm if you want to
it may be worth adding a master.motors_disarmed_wait() to the end of your program to make sure the disarming was actually successful.