HI, I’ve had some trouble running the python scripts from the example documentation. I wrote some code to make it just go straight but it keeps popping up with a bunch of errors every time, if I keep trying to run it one of maybe 10-15 attempts will work and the auv will go straight as expected.
here are the types of errors that come up:
EDIT: Upon changing the mode from ALT_HOLD to STABILIZE, it run the code (haven’t tested it underwater yet) but I’m still not sure why I can’t make the depth hold mode work. More intriguingly why it sometimes worked
I expect you need to filter for specifically autopilot heartbeats - otherwise every time it detects a different type of heartbeat it will internally change which options are available, and error out if you try to perform some unsupported operation for that component.
I’m not certain what’s happening there, but depending on how+where you’re running your code you may be preventing BlueOS from opening one of its MAVLink Endpoints, or you could be running some alternative server (perhaps in an extension) that is using a port it’s trying to make use of, so there’s a conflict when it tries to open a MAVLink connection there.
this is super helpful, I will give it a go but this explains a lot, Thanks!
I’m not exactly sure how the endpoints work. You can see in my code that I used 14550 as an endpoint and that also somehow started working after messing (almost randomly) with the endpoint a bit. I can give you more information on the status of endpoints when I have access to the robot again (tomorrow). I can confirm tho that I have not used any extension beyond the vscode one.
this is actually a great point, I didn’t verify the depth sensor readings at the time of running this. Although I have tested the same code before with the depth sensor confirmed working and got the same ALT_MODE keyerror although admittedly much less frequently.
these are all my endpoints, I think the ardupilot failing may be causing me more issues because it sometimes just shows no heartbeat and crashes (needs power cycle). I usually dont have any extensions beyond vscode running so any help there would be appreciated.
I also tried filtering for heartbeats as the post you linked mentioned, here is the test code I used to just change the auv to depth_hold mode.
import signal
import sys
import math
from pymavlink.quaternion import QuaternionBase
from pymavlink import mavutil
from pprint import pprint
def change_control_mode(mode: str) -> None:
mode_id = master.mode_mapping()[mode]
while not master.wait_heartbeat().custom_mode == mode_id:
print(f"Attempting to set mode {mode}")
master.mav.command_long_send(
master.target_system,
master.target_component,
mavutil.mavlink.MAV_CMD_DO_SET_MODE,
0,
1, mode_id, 0, 0, 0, 0, 0)
print(f"set mode {str}")
def disarm_vehicle() -> None:
"""
Disarms the vehicle, disabling actuation.
"""
if master:
change_control_mode("MANUAL")
print("disarming")
master.arducopter_disarm()
master.motors_disarmed_wait()
print("disarmed")
def exit_gracefully(a, b):
# set_rc_channel_pwmsing(5)
disarm_vehicle()
sys.exit(-1)
signal.signal(signal.SIGINT, exit_gracefully)
signal.signal(signal.SIGTERM, exit_gracefully)
# Connect to mavlink
master = mavutil.mavlink_connection('udpout:0.0.0.0:14550')
boot_time = time.time()
print("waiting connection")
msg = None
while not msg:
master.mav.ping_send(
int(time.time() * 1e6), # Unix time in microseconds
0, # ping count
0, # request ping of all systems
0, # request ping of all components
)
msg = master.recv_match()
time.sleep(0.5)
print("connected")
master.wait_heartbeat()
ensure_autopilot_heartbeat = (
f'HEARTBEAT.get_srcSystem() == {master.target_system} and '
f'HEARTBEAT.get_srcComponent() == {mavutil.mavlink.MAV_COMP_ID_AUTOPILOT1}'
)
master.recv_match(type='HEARTBEAT', condition=ensure_autopilot_heartbeat, blocking=True)
print("waited")
pprint(msg.to_dict())
print("starting")
change_control_mode("ALT_HOLD")
time.sleep(5)
disarm_vehicle()
I have tried this with and without the master.wait_heartbeat() line and it just stops after printing “connected”. The LEDs on the navigator board keep flashing red and green and I am unable to arm the vehicle even using the vehicle setup page on blueos.
Hi @kushion -
Have you verified that you can drive the vehicle manually, before trying your script? The motion sensors need to be calibrated before the vehicle will arm, due to failsafe checks…
You shouldn’t need to add any endpoints to get manual or script control working!
I am also able to individually control all the thrusters through the vehicle setup page. I have no tether or such since this was always meant to be an auv build so I haven’t tried manual control yet
EDIT2: just installed Qgc and switched to depth hold there and it did it no worries. (all depth contributing thrusters spin up continuously because I’m guessing it’s in air right now)
Hi @kushion -
I’d suggest you follow the advice already shared by Eliot! You’re not filtering for the heartbeat type in the code you shared, as he linked an example on how to do…The vehicle working as expected is a good sign that things should proceed smoothly!
14550 is just the port of the udp GCS server link, I believe it’s correct to use this, however giving more information on the context you’re running your code in would be helpful - are you at the BlueOS terminal or in a docker container? Are you running manually after the vehicle finishes starting up?
I thought the following code is what was linked in the post and I used to filter for heartbeats.
I’m running this code on blueos while connected to the companion computer over hotspot. The code is run via blueos terminal.
I think my endpoint in blueos for 14550 is set to UDP client and not server, it’s possible that someone else in my team changed it in the past since it’s editable. Should it be set to server? Also, since I am running this code on the companion computer, should I be using 9000 endpoint?
EDIT: this worked for the test code which is now running as expected. Just making sure I didn’t fix something small and break something big in the process since i don’t know what I’m doing.