Developing a new mode

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 :

<FLTMODE1>
  <DisplayName>Flight Mode 1</DisplayName>
  <Description>Flight mode when Channel 5 pwm is &lt;= 1230</Description>
  <Values>0:Stabilize,1:Acro,2:AltHold,3:Auto,4:Guided,5:Loiter,6:RTL,7:Circle,9:Land,11:Drift,13:Sport,14:Flip,15:AutoTune,16:PosHold,17:Brake,18:Throw,19:Avoid_ADSB,20:Guided_NoGPS,21:Smart_RTL,22:FlowHold,23:Follow,24:ZigZag,25:SystemID,26:Heli_Autorotate,27:TestMode1,28:TestMode2</Values>
  <User>Standard</User>
</FLTMODE1>  

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…

How do I tell Mission Planner about running a certain binary in SITL?

Because even in SITL on my end it appears as this.

I appreciate the information though. By running well I mean, that my new mode is recognized correctly by your set up including SITL it appears. :slight_smile:

Let me try that gcs().send_text. Under which file is it under? Or do I include it in my mode_bird.cpp file?

You can put in somewhere that gets executed. Let’s say in mode.cpp right at the begining of

bool Copter::set_mode(Mode::Number mode, ModeReason reason)
{
gcs().send_text(MAV_SEVERITY_INFO, “Mode change initiated…”);


So here is the added code,
image
and build the code once more using the waf system.

alias waf=“$PWD/modules/waf/waf-light”
waf configure --board=navio2
waf --targets bin/arducopter

I am assuming the message should appear under the messages tab in mission planner, and here is the result after changing through different modes under simulation.


I switched through the first three flight modes, it looks like I am not running my built code?

Are you also using the waf system to compile your code?

Not sure how useful this may be but here is how I go about editing code:
with ardupilot cloned to my pi,
I use WinSCP to get the files I will be making edits to such as mode.cpp from the pi to my PC
Then on my PC, I make the edits using sublime text editor, save the file, then copy my edited file back to the pi via WinSCP
I set up the waf build system on my pi and compile the code.
I use putty as my terminal for the pi.

OK.

  1. You are definitely not running your compiled code.
  2. I’m not familiar with navio, but I think you should check the “Launching a Custom Ardupilot binary” part here https://docs.emlid.com/navio/common/ardupilot/installation-and-running/ perhaps there is a step that you skipped

Sounds good to me! I will begin here and see how far I get. This is all new to me but I really appreciate all the help you all have given me and for being patient with me!

Update on the status of my issue. It was the fact that I was not running the compiled code and the link you shared with me helped me realize what I was missing, once I followed and experimented with the steps i was able to successfully implement my custom modes. So thank you again! I am really grateful. :smile:

1 Like

Curios, which one is your favorite? :slightly_smiling_face:

Can you please tell how did you ran your ardupiliot in mission planner. I am trying in SITL but even after adding the new mode it shows unknown mode in the terminal.