Adding a new flight mode but failed the compilation for SITL

Hi,

This is my first post here, and I genuinely want to seek some help on adding a new flight mode for SITL.

I followed the instructions here to add a new flight mode called “ADAPTIVE”: Adding a New Flight Mode to Copter — Dev documentation

My current repository is here: GitHub - Sheng-Cheng/geometricL1ArduCopter

I tried to test the newly added mode in SITL and I ran the following code under ArduCopter/
$ …/Tools/autotest/sim_vehicle.py -v ArduCopter --console --map

I got errors below:
[819/884] Compiling ArduCopter/mode_acro.cpp
In file included from …/…/ArduCopter/RC_Channel.h:5:0,
from …/…/ArduCopter/Copter.h:92,
from …/…/ArduCopter/GCS_Mavlink.cpp:1:
…/…/ArduCopter/mode.h:1761:10: error: ‘bool ModeAdaptive::allows_arming(bool) const’ marked ‘override’, but does not override
bool allows_arming(bool from_gcs) const override { return true; };
^~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

In file included from …/…/ArduCopter/RC_Channel.h:5:0,
from …/…/ArduCopter/Copter.h:92,
from …/…/ArduCopter/esc_calibration.cpp:1:
…/…/ArduCopter/mode.h:1761:10: error: ‘bool ModeAdaptive::allows_arming(bool) const’ marked ‘override’, but does not override
bool allows_arming(bool from_gcs) const override { return true; };
^~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

In file included from …/…/ArduCopter/RC_Channel.h:5:0,
from …/…/ArduCopter/Copter.h:92,
from …/…/ArduCopter/surface_tracking.cpp:1:
…/…/ArduCopter/mode.h:1761:10: error: ‘bool ModeAdaptive::allows_arming(bool) const’ marked ‘override’, but does not override
bool allows_arming(bool from_gcs) const override { return true; };
^~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

In file included from …/…/ArduCopter/RC_Channel.h:5:0,
from …/…/ArduCopter/Copter.h:92,
from …/…/ArduCopter/land_detector.cpp:1:
…/…/ArduCopter/mode.h:1761:10: error: ‘bool ModeAdaptive::allows_arming(bool) const’ marked ‘override’, but does not override
bool allows_arming(bool from_gcs) const override { return true; };
^~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

In file included from …/…/ArduCopter/RC_Channel.h:5:0,
from …/…/ArduCopter/Copter.h:92,
from …/…/ArduCopter/mode_rtl.cpp:1:
…/…/ArduCopter/mode.h:1761:10: error: ‘bool ModeAdaptive::allows_arming(bool) const’ marked ‘override’, but does not override
bool allows_arming(bool from_gcs) const override { return true; };
^~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

In file included from …/…/ArduCopter/RC_Channel.h:5:0,
from …/…/ArduCopter/Copter.h:92,
from …/…/ArduCopter/RC_Channel.cpp:1:
…/…/ArduCopter/mode.h:1761:10: error: ‘bool ModeAdaptive::allows_arming(bool) const’ marked ‘override’, but does not override
bool allows_arming(bool from_gcs) const override { return true; };
^~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

In file included from …/…/ArduCopter/RC_Channel.h:5:0,
from …/…/ArduCopter/Copter.h:92,
from …/…/ArduCopter/toy_mode.cpp:1:
…/…/ArduCopter/mode.h:1761:10: error: ‘bool ModeAdaptive::allows_arming(bool) const’ marked ‘override’, but does not override
bool allows_arming(bool from_gcs) const override { return true; };
^~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

In file included from …/…/ArduCopter/RC_Channel.h:5:0,
from …/…/ArduCopter/Copter.h:92,
from …/…/ArduCopter/mode_acro.cpp:1:
…/…/ArduCopter/mode.h:1761:10: error: ‘bool ModeAdaptive::allows_arming(bool) const’ marked ‘override’, but does not override
bool allows_arming(bool from_gcs) const override { return true; };
^~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

Waf: Leaving directory `/home/sheng/ardupilot/build/sitl’
Build failed
→ task in ‘bin/arducopter’ failed (exit status 1):
{task 140410551012432: cxx GCS_Mavlink.cpp → GCS_Mavlink.cpp.40.o}
(run with -v to display more information)
→ task in ‘bin/arducopter’ failed (exit status 1):
{task 140410551104592: cxx esc_calibration.cpp → esc_calibration.cpp.40.o}
(run with -v to display more information)
→ task in ‘bin/arducopter’ failed (exit status 1):
{task 140410551147344: cxx surface_tracking.cpp → surface_tracking.cpp.40.o}
(run with -v to display more information)
→ task in ‘bin/arducopter’ failed (exit status 1):
{task 140410551105360: cxx land_detector.cpp → land_detector.cpp.40.o}
(run with -v to display more information)
→ task in ‘bin/arducopter’ failed (exit status 1):
{task 140410551145296: cxx mode_rtl.cpp → mode_rtl.cpp.40.o}
(run with -v to display more information)
→ task in ‘bin/arducopter’ failed (exit status 1):
{task 140410551012816: cxx RC_Channel.cpp → RC_Channel.cpp.40.o}
(run with -v to display more information)
→ task in ‘bin/arducopter’ failed (exit status 1):
{task 140410551147856: cxx toy_mode.cpp → toy_mode.cpp.40.o}
(run with -v to display more information)
→ task in ‘bin/arducopter’ failed (exit status 1):
{task 140410551105872: cxx mode_acro.cpp → mode_acro.cpp.40.o}
(run with -v to display more information)
SIM_VEHICLE: Build failed
SIM_VEHICLE: Killing tasks

Any suggestions on how to proceed with my new flight mode in SITL would be helpful! Thank you!

bool allows_arming(bool from_gcs) const override { return true; };

You cant change the argument types. it must still be

bool allows_arming(AP_Arming::Method method) const override;

So I guess you want to only arm from the GCS so you would do this:

bool allows_arming(AP_Arming::Method method) const override { return method == AP_Arming::Method::MAVLINK; }

Thank you, Peter!

It’s weird to me: I copied the line of code that you modified from the instructions. But it didn’t work.

Anyway, I tried the two modifications you suggested. The updated repository is here: GitHub - Sheng-Cheng/geometricL1ArduCopter
But I got the following errors when compiling:

[818/884] Compiling ArduCopter/baro_ground_effect.cpp
In file included from …/…/ArduCopter/mode_stabilize_heli.cpp:1:0:
…/…/ArduCopter/Copter.h:990:18: error: cannot declare field ‘Copter::mode_adaptive’ to be of abstract type ‘ModeAdaptive’
ModeAdaptive mode_adaptive;
^~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

In file included from …/…/ArduCopter/AP_Rally.cpp:18:0:
…/…/ArduCopter/Copter.h:990:18: error: cannot declare field ‘Copter::mode_adaptive’ to be of abstract type ‘ModeAdaptive’
ModeAdaptive mode_adaptive;
^~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

In file included from …/…/ArduCopter/mode_stabilize.cpp:1:0:
…/…/ArduCopter/Copter.h:990:18: error: cannot declare field ‘Copter::mode_adaptive’ to be of abstract type ‘ModeAdaptive’
ModeAdaptive mode_adaptive;
^~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

In file included from …/…/ArduCopter/avoidance_adsb.cpp:1:0:
…/…/ArduCopter/Copter.h:990:18: error: cannot declare field ‘Copter::mode_adaptive’ to be of abstract type ‘ModeAdaptive’
ModeAdaptive mode_adaptive;
^~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

In file included from …/…/ArduCopter/motors.cpp:1:0:
…/…/ArduCopter/Copter.h:990:18: error: cannot declare field ‘Copter::mode_adaptive’ to be of abstract type ‘ModeAdaptive’
ModeAdaptive mode_adaptive;
^~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

In file included from …/…/ArduCopter/tuning.cpp:1:0:
…/…/ArduCopter/Copter.h:990:18: error: cannot declare field ‘Copter::mode_adaptive’ to be of abstract type ‘ModeAdaptive’
ModeAdaptive mode_adaptive;
^~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

In file included from …/…/ArduCopter/mode_smart_rtl.cpp:1:0:
…/…/ArduCopter/Copter.h:990:18: error: cannot declare field ‘Copter::mode_adaptive’ to be of abstract type ‘ModeAdaptive’
ModeAdaptive mode_adaptive;
^~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

In file included from …/…/ArduCopter/baro_ground_effect.cpp:1:0:
…/…/ArduCopter/Copter.h:990:18: error: cannot declare field ‘Copter::mode_adaptive’ to be of abstract type ‘ModeAdaptive’
ModeAdaptive mode_adaptive;
^~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

Waf: Leaving directory `/home/sheng/ardupilot/build/sitl’
Build failed
→ task in ‘bin/arducopter’ failed (exit status 1):
{task 139645910824528: cxx mode_stabilize_heli.cpp → mode_stabilize_heli.cpp.40.o}
(run with -v to display more information)
→ task in ‘bin/arducopter’ failed (exit status 1):
{task 139645912366288: cxx AP_Rally.cpp → AP_Rally.cpp.40.o}
(run with -v to display more information)
→ task in ‘bin/arducopter’ failed (exit status 1):
{task 139645910824400: cxx mode_stabilize.cpp → mode_stabilize.cpp.40.o}
(run with -v to display more information)
→ task in ‘bin/arducopter’ failed (exit status 1):
{task 139645911458512: cxx avoidance_adsb.cpp → avoidance_adsb.cpp.40.o}
(run with -v to display more information)
→ task in ‘bin/arducopter’ failed (exit status 1):
{task 139645910825296: cxx motors.cpp → motors.cpp.40.o}
(run with -v to display more information)
→ task in ‘bin/arducopter’ failed (exit status 1):
{task 139645910826704: cxx tuning.cpp → tuning.cpp.40.o}
(run with -v to display more information)
→ task in ‘bin/arducopter’ failed (exit status 1):
{task 139645910824144: cxx mode_smart_rtl.cpp → mode_smart_rtl.cpp.40.o}
(run with -v to display more information)
→ task in ‘bin/arducopter’ failed (exit status 1):
{task 139645911458256: cxx baro_ground_effect.cpp → baro_ground_effect.cpp.40.o}
(run with -v to display more information)
SIM_VEHICLE: Build failed
SIM_VEHICLE: Killing tasks

Something seems wrong with the declaration. Any suggestion would be appreciated!

The instructions are abit out of date.

You need to implement the functions in the .h currently there is no init or allows_arming

You can just to that in the .h. My suggested line implements allows_arming and you can change init to:

bool init(bool ignore_checks) override { return true; }

I tried the line you suggested. But the compilation errors remain.

Instead of following the out-of-date instructions, I simply copied the class definition from mode stabilize. Below is the current version:

class ModeAdaptive : public Mode {
public:
// inherit constructor
using Mode::Mode;

Number mode_number() const override { return Number::ADAPTIVE; }

void run() override;

bool requires_GPS() const override { return false; }
bool has_manual_throttle() const override { return true; }
bool allows_arming(AP_Arming::Method method) const override { return true; };
bool is_autopilot() const override { return false; }
bool allows_save_trim() const override { return true; }
bool allows_autotune() const override { return true; }
bool allows_flip() const override { return true; }

protected:

const char *name() const override {return "ADAPTIVE"; }
const char *name4() const override {return "ADPT"; }
// The name() and name4() methods are for logging and display purposes. 

private:

};

Now there’s only one error (i believe I’m close)
[828/884] Compiling ArduCopter/fence.cpp
…/…/ArduCopter/mode_adaptive.cpp: In member function ‘virtual void ModeAdaptive::run()’:
…/…/ArduCopter/mode_adaptive.cpp:18:69: error: ‘AP_Vehicle::MultiCopter Copter::aparm’ is private within this context
get_pilot_desired_lean_angles(target_roll, target_pitch, copter.aparm.angle_max, copter.aparm.angle_max);
^~~~~
compilation terminated due to -Wfatal-errors.

Thanks!

add you new class as a friend here:

Works! Thanks a lot!

@ShengChen , can you explain what you have made exactly and in with file because I got the same error