Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct Copter guided submode change #27121

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions ArduCopter/mode_guided.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,13 @@ bool ModeGuided::set_destination(const Location& dest_loc, bool use_yaw, float y
return true;
}

// set position target and zero velocity and acceleration
Vector3f pos_target_f;
bool terrain_alt;
if (!wp_nav->get_vector_NEU(dest_loc, pos_target_f, terrain_alt)) {
return false;
}

// if configured to use position controller for position control
// ensure we are in position control mode
if (guided_mode != SubMode::Pos) {
Expand All @@ -465,13 +472,6 @@ bool ModeGuided::set_destination(const Location& dest_loc, bool use_yaw, float y
// set yaw state
set_yaw_state(use_yaw, yaw_cd, use_yaw_rate, yaw_rate_cds, relative_yaw);

// set position target and zero velocity and acceleration
Vector3f pos_target_f;
bool terrain_alt;
if (!wp_nav->get_vector_NEU(dest_loc, pos_target_f, terrain_alt)) {
return false;
}

// initialise terrain following if needed
if (terrain_alt) {
// get current alt above terrain
Expand Down
41 changes: 37 additions & 4 deletions Tools/autotest/arducopter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4599,10 +4599,7 @@ def fly_guided_stop(self,
m.climb < climb_tolerance):
break

def fly_guided_move_global_relative_alt(self, lat, lon, alt):
startpos = self.mav.recv_match(type='GLOBAL_POSITION_INT',
blocking=True)

def send_set_position_target_global_int(self, lat, lon, alt):
self.mav.mav.set_position_target_global_int_send(
0, # timestamp
1, # target system_id
Expand All @@ -4622,6 +4619,12 @@ def fly_guided_move_global_relative_alt(self, lat, lon, alt):
0, # yawrate
)

def fly_guided_move_global_relative_alt(self, lat, lon, alt):
startpos = self.mav.recv_match(type='GLOBAL_POSITION_INT',
blocking=True)

self.send_set_position_target_global_int(lat, lon, alt)

tstart = self.get_sim_time()
while True:
if self.get_sim_time_cached() - tstart > 200:
Expand Down Expand Up @@ -11345,6 +11348,35 @@ def check_altitude(mav, m):
self.context_pop()
self.reboot_sitl(force=True)

def GuidedForceArm(self):
'''ensure Guided acts appropriately when force-armed'''
self.set_parameters({
"EK3_SRC2_VELXY": 5,
"SIM_GPS_DISABLE": 1,
})
self.load_default_params_file("copter-optflow.parm")
self.reboot_sitl()
self.delay_sim_time(30)
self.change_mode('GUIDED')
self.arm_vehicle(force=True)
self.takeoff(20, mode='GUIDED')
location = self.offset_location_ne(self.sim_location(), metres_north=0, metres_east=-300)
self.progress("Ensure we don't move for 10 seconds")
tstart = self.get_sim_time()
startpos = self.sim_location_int()
while True:
now = self.get_sim_time_cached()
if now - tstart > 10:
break
self.send_set_position_target_global_int(int(location.lat*1e7), int(location.lng*1e7), 10)
dist = self.get_distance_int(startpos, self.sim_location_int())
if dist > 10:
raise NotAchievedException("Wandered too far from start position")
self.delay_sim_time(1)

self.disarm_vehicle(force=True)
self.reboot_sitl()

def tests2b(self): # this block currently around 9.5mins here
'''return list of all tests'''
ret = ([
Expand Down Expand Up @@ -11431,6 +11463,7 @@ def tests2b(self): # this block currently around 9.5mins here
self.AutoRTL,
self.EK3_OGN_HGT_MASK,
self.FarOrigin,
self.GuidedForceArm,
])
return ret

Expand Down
Loading