-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
Copter: allow adding custom modes from scripting #28110
base: master
Are you sure you want to change the base?
Conversation
9981644
to
7d69509
Compare
|
SubMode guided_mode = SubMode::TakeOff; | ||
bool send_notification; // used to send one time notification to ground station | ||
bool takeoff_complete; // true once takeoff has completed (used to trigger retracting of landing gear) | ||
static SubMode guided_mode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could these cause problems? it makes it shared between all modes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels like a bear trap!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is the vast majority of the guided state is static already. This stuff:
ardupilot/ArduCopter/mode_guided.cpp
Lines 9 to 33 in 25e77a5
static Vector3p guided_pos_target_cm; // position target (used by posvel controller only) | |
bool guided_pos_terrain_alt; // true if guided_pos_target_cm.z is an alt above terrain | |
static Vector3f guided_vel_target_cms; // velocity target (used by pos_vel_accel controller and vel_accel controller) | |
static Vector3f guided_accel_target_cmss; // acceleration target (used by pos_vel_accel controller vel_accel controller and accel controller) | |
static uint32_t update_time_ms; // system time of last target update to pos_vel_accel, vel_accel or accel controller | |
struct { | |
uint32_t update_time_ms; | |
Quaternion attitude_quat; | |
Vector3f ang_vel_body; | |
float yaw_rate_cds; | |
float climb_rate_cms; // climb rate in cms. Used if use_thrust is false | |
float thrust; // thrust from -1 to 1. Used if use_thrust is true | |
bool use_yaw_rate; | |
bool use_thrust; | |
} static guided_angle_state; | |
struct Guided_Limit { | |
uint32_t timeout_ms; // timeout (in seconds) from the time that guided is invoked | |
float alt_min_cm; // lower altitude limit in cm above home (0 = no limit) | |
float alt_max_cm; // upper altitude limit in cm above home (0 = no limit) | |
float horiz_max_cm; // horizontal position limit in cm from where guided mode was initiated (0 = no limit) | |
uint32_t start_time;// system time in milliseconds that control was handed to the external computer | |
Vector3f start_pos; // start position as a distance from home in cm. used for checking horiz_max limit | |
} guided_limit; |
It either has to be all static or all not. With half and half as it is now you can endup being in the wrong sub mode for the targets you have. Making these static is a smaller change than making the existing stuff not.
Currently there should be no issue because there is nothing in the mode exit function so there is no overlap between one version of guided and the next. So long as everything is reset correctly in the mode init then we start clean (which I think it is already).
As you say, this is a bit nasty for the future, but anything else would require a much larger re-work.
This will be a great feature! |
Investigate |
SubMode guided_mode = SubMode::TakeOff; | ||
bool send_notification; // used to send one time notification to ground station | ||
bool takeoff_complete; // true once takeoff has completed (used to trigger retracting of landing gear) | ||
static SubMode guided_mode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels like a bear trap!
7d69509
to
eb62a4c
Compare
I have rebased, now lots of the supporting stuff has been merged in the other PRs this is a much smaller change. |
eb62a4c
to
3a50d49
Compare
This now uses the |
3a50d49
to
0822698
Compare
I just noticed this PR is prefixed "Copter:" - is it going to work in Plane? |
Not in this pr, but eventually yes |
Looking forward to to it. As soon as it's available I'll use it to implement "FOLLOW" mode in Plane :-) |
…ior of flip mode.
…hen registering a custom mode
0822698
to
1fd2a1e
Compare
This allows a script to register a new mode with a given number and name. This is just a wrapper on guided mode, but it allows clearer interaction with the user.
The example re-implements flip mode in a script. It uses mode 100, in MAVProxy you can enter with
mode 100
.In order to allow the flip I added a new guided binding
set_target_rate_and_throttle
. I also found and fixed a issue that the Z controller would throw a flow of control error when moving from guided angle with throttle to guided angle with climb rate.The internal variables of guided mode are changed to static so they apply to to the new modes too.
There are some more changes needed:
anywhere that doing a compare on guided mode by reference or number needs to deal with the new modes.
Come up with a way to communicate to the GCS which modes are available so it could populate its mode list with the new modes (this would also be useful if we want to start removing modes and/or for the custom build server).
Currently scripting is the only way to register a mode, but there is no reason a companion computer could not do the same with a new MAVLink message.
In the future we may want to add more state on the custom mode object, for example a "allow_enter" bool which the script could keep updated. This would allow the script to reject entry if the correct conditions are not met. Currently the flip example will enter but then immediately put the mode back again if it does not like it.
Allow a custom version of guided no-gps as well as full guided.
Currently the mode will fail to add if the script is restated because it is already there, it might be nice to allow a re-add of the same mode, although this is only a issue for script dev.