Skip to content

Commit 161bc68

Browse files
Peter BurkePeter Burke
authored andcommitted
goto works
1 parent 8e016a0 commit 161bc68

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

socketio_handlers.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,64 @@ def handle_send_command(data):
356356
success, msg_send = _send_mavlink_command_handler(mavutil.mavlink.MAV_CMD_MISSION_CLEAR_ALL, p2=0) # p2=0 for MAV_MISSION_TYPE_ALL
357357
cmd_type = 'info' if success else 'error'
358358
msg = 'CLEAR_MISSION command sent.' if success else f'CLEAR_MISSION Failed: {msg_send}'
359+
elif cmd == 'GOTO':
360+
try:
361+
lat = float(data.get('lat'))
362+
lon = float(data.get('lon'))
363+
# Use current relative altitude as default if not provided
364+
current_rel_alt = _drone_state.get('alt_rel', 10.0)
365+
alt = float(data.get('alt', current_rel_alt))
366+
367+
_log_wrapper_for_caller_info("GOTO_START", data, f"Initiating GOTO to Lat:{lat:.7f}, Lon:{lon:.7f}, Alt:{alt:.1f}m using SET_POSITION_TARGET_GLOBAL_INT", "INFO")
368+
369+
current_mav_connection = _get_mavlink_connection()
370+
371+
if current_mav_connection and hasattr(current_mav_connection, 'target_system') and current_mav_connection.target_system != 0:
372+
current_target_system = current_mav_connection.target_system
373+
current_target_component = current_mav_connection.target_component
374+
375+
# Set type mask to ignore velocities, accelerations, and yaw
376+
type_mask = (
377+
mavutil.mavlink.POSITION_TARGET_TYPEMASK_VX_IGNORE |
378+
mavutil.mavlink.POSITION_TARGET_TYPEMASK_VY_IGNORE |
379+
mavutil.mavlink.POSITION_TARGET_TYPEMASK_VZ_IGNORE |
380+
mavutil.mavlink.POSITION_TARGET_TYPEMASK_AX_IGNORE |
381+
mavutil.mavlink.POSITION_TARGET_TYPEMASK_AY_IGNORE |
382+
mavutil.mavlink.POSITION_TARGET_TYPEMASK_AZ_IGNORE |
383+
mavutil.mavlink.POSITION_TARGET_TYPEMASK_YAW_IGNORE |
384+
mavutil.mavlink.POSITION_TARGET_TYPEMASK_YAW_RATE_IGNORE
385+
)
386+
387+
current_mav_connection.mav.set_position_target_global_int_send(
388+
0, # time_boot_ms
389+
current_target_system, current_target_component,
390+
mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT_INT,
391+
type_mask,
392+
int(lat * 1e7), int(lon * 1e7), alt,
393+
0, 0, 0, 0, 0, 0, 0, 0 # vx, vy, vz, afx, afy, afz, yaw, yaw_rate (all ignored)
394+
)
395+
success = True
396+
msg = f'GOTO to Lat:{lat:.7f}, Lon:{lon:.7f}, Alt:{alt:.1f}m command sent using SET_POSITION_TARGET_GLOBAL_INT.'
397+
_log_wrapper_for_caller_info("GOTO_SENT", data, msg, "INFO")
398+
else:
399+
success = False
400+
msg = "GOTO Failed: MAVLink connection not available or target system not identified."
401+
if current_mav_connection and hasattr(current_mav_connection, 'target_system'):
402+
msg += f" (target_sys={current_mav_connection.target_system})"
403+
_log_wrapper_for_caller_info("GOTO_FAIL", data, msg, "ERROR")
404+
405+
cmd_type = 'info' if success else 'error'
406+
407+
except (ValueError, TypeError) as e:
408+
success = False
409+
msg = f"GOTO Error: Invalid coordinates - lat: '{data.get('lat')}', lon: '{data.get('lon')}', alt: '{data.get('alt')}'. Details: {e}"
410+
cmd_type = 'error'
411+
_log_wrapper_for_caller_info("GOTO_ERROR", data, f"EXCEPTION: {msg}", "ERROR")
412+
except Exception as e:
413+
success = False
414+
msg = f"GOTO Error: Unexpected error processing GOTO command: {str(e)}"
415+
cmd_type = 'error'
416+
_log_wrapper_for_caller_info("GOTO_ERROR_EXC", data, f"EXCEPTION: {msg}", "ERROR")
359417
else:
360418
msg = f'Unknown command: {cmd}'
361419
cmd_type = 'warning'

0 commit comments

Comments
 (0)