Servers by jDrones

Developing a new mode

Howdy, all I have been trying to develop a new mode for a project and I can’t seem to get it right. Attached are the files I have modified the following files to include the new mode “BIRD” and “shutdown”.
mode.cpp I added new lines of code starting at line 172 to 184
mode_bird.cpp is the file corresponding to bird mode
mode_shutdown.cpp is the file corresponding to shutdown mode
Parameters.cpp I added the values of bird and shutdown under FLTMODE1-6
config.h I added the enable variables such as MODE_SHUTDOWN_ENABLED which can be found in lines 374-388
copter.h I added the class of both bird and shutdown mode, these are lines 234-235 and lines 976 through 985
mode.h defines the flight modes numbers, lines 40-41 and their corresponding class lines 1516-1568.
The picture shows the result of when the toggle switch is set to my custom mode, am I missing anything else? I followed the configuration of stabilize mode. I probably missed something.


mode.cpp (26.6 KB) mode_bird.cpp (3.3 KB) mode_shutdown.cpp (1.6 KB) Parameters.cpp (67.5 KB)

config.h (25.1 KB) Copter.h (33.1 KB) mode.h (51.7 KB)

Can you post a link to your fork of ArduPilot instead of individual source files?
It would be much easier to help you that way.
Also, have you read this wiki page?

Here is the link to my forked repository.

Yes, I followed the steps listed in the link. Have you ever developed your own modes? If so, were you successful simply by following the steps in the link you shared with me? If so, then I can retry again.

This is what happens when I switch in my custom modes on Mission Planner.

My set up is a raspberry pi using a Navio2 as the flight controller. Maybe I need to change where Navio2 looks for the built binary file?

Yes, I’ve added new modes for Plane before e.g. QACRO, but I’m not clear on how to tell a GCS about the new mode.
I ran your master branch in SITL, and in mavproxy, the commands “mode 27” and “mode 28” seem to work ok:

STABILIZE> mode 27
Got MAVLink msg: COMMAND_ACK {command : 11, result : 0}
Mode(27)> mode 28
Got MAVLink msg: COMMAND_ACK {command : 11, result : 0}

I also don’t use MP very much… perhaps @rmackay could help?

Thank you for running that check for me. I am new to this and learning my way through Ardupilot with each mistake I make.

So, if my modes seem okay, in your opinion, how could this issue be resolved? What should my next steps be?

I will be reaching out to rmackay in the next few.

Thank you!

You could use your RC TX to select your new modes:
Or you could just manually enter the mode number from the GCS. I know mavproxy and QGroundControl allow that, but I’m not sure whether MP does.

I see,

When I am testing the new mode I made, I go into mission planner and select the flight modes based on the position of the switches as described by the link you provided. When I move the toggle switch to my custom flight mode that is when I get the warning on Mission Planner “No such mode”. So I have tried the first part, I will however see if there is a way to manually select a flight mode on Mission Planner rather than using TX.

The “No Such Mode” message is coming from the flight controller , not from Mission Planner. (mode.cpp / Copter::set_mode) it got a null pointer instead of the mode handling function pointer…
Which could mean that it got a wrong mode number from mission planner. You should check mavlink communication between FC and Misison Planner (CTRL-F and Mavlink inspector)…

Ok, I downloaded your code and run in SITL. Modified ParameterMetaData.xml FLTMODE1 as this :

  <DisplayName>Flight Mode 1</DisplayName>
  <Description>Flight mode when Channel 5 pwm is &lt;= 1230</Description>

and it works…

Changed the “28:TestMode2” to “29:TestMode2” and look :

So here is my ParameterMetaData.xml file:

I am working with one mode now and will not implement the second one until I get at least one mode implemented.
The following two pictures are what mavlink inspector gives me when I am in stabilize mode and autorotate mode.

The last mode, BIRD, is mode 27, and the following picture shows it is the right number but on my mission planner reports, no such mode exists.

From this information, if the RC is receiving the correct number, 27, where should I look into next?

Quick test; change the Stabilize mode name in the xml to something else, like Xabilize and check if it reflected in Mission Planner as well. Just to rule out issues with the xml file.

a quick google search turns this up:

Nice, but we are talking about Mission Planner here

Oh, sorry… I had forgotten that we’d been here before; New Flight Mode not shown in Mission Planner
How do you get MP to use a local XML file? Do you need to build your own exe?

nvm: finished re-reading that thread

@Luis_Orozco I inserted a printf in mode_bird.cpp

    ::printf("in ModeBIRD::run at %d\n", AP_HAL::millis());

and selected that mode using mavproxy in SITL:
Result in the gdb console was

in ModeBIRD::run at 30226
in ModeBIRD::run at 30228
in ModeBIRD::run at 30231
in ModeBIRD::run at 30233
in ModeBIRD::run at 30236

That’s the way I debug a new flight mode, and it shows that your new mode is active.

So just for clarification, the mode is set up correctly on my set up, (pi+navio2), as in the mode exists and is working well?

Here is the quick test, it looks like it works fine.

The mode exists, and its run() method is being called when I activate it via mavproxy. I can’t say whether it “works well” though :slight_smile:
Are you sure MP is running the right binary for you (if using SITL) or that the FC has the right binary flashed?

I’m baffled.
I compiled your code and ran it as SITL.
Added mode 27 to Mission Planner
And as you saw above it worked fine.

Are you absolutely sure that you running your code in SITL or Flight Controller ? Perhaps you can add some gcs().send_text to the Flight controller code to make it sure…

Servers by jDrones