CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Rover/AP_ExternalControl_Rover.cpp
Views: 1798
1
/*
2
external control library for rover
3
*/
4
5
6
#include "AP_ExternalControl_Rover.h"
7
#if AP_EXTERNAL_CONTROL_ENABLED
8
9
#include "Rover.h"
10
11
/*
12
set linear velocity and yaw rate. Pass NaN for yaw_rate_rads to not control yaw
13
velocity is in earth frame, NED, m/s
14
*/
15
bool AP_ExternalControl_Rover::set_linear_velocity_and_yaw_rate(const Vector3f &linear_velocity, float yaw_rate_rads)
16
{
17
if (!ready_for_external_control()) {
18
return false;
19
}
20
21
// rover is commanded in body-frame using FRD convention
22
auto &ahrs = AP::ahrs();
23
Vector3f linear_velocity_body = ahrs.earth_to_body(linear_velocity);
24
25
const float target_speed = linear_velocity_body.x;
26
const float turn_rate_cds = isnan(yaw_rate_rads)? 0: degrees(yaw_rate_rads)*100;
27
28
rover.mode_guided.set_desired_turn_rate_and_speed(turn_rate_cds, target_speed);
29
return true;
30
}
31
32
bool AP_ExternalControl_Rover::set_global_position(const Location& loc)
33
{
34
// set_target_location only checks if the rover is in guided mode or not
35
return rover.set_target_location(loc);
36
}
37
38
bool AP_ExternalControl_Rover::ready_for_external_control()
39
{
40
return rover.control_mode->in_guided_mode() && rover.arming.is_armed();
41
}
42
43
#endif // AP_EXTERNAL_CONTROL_ENABLED
44
45