Home        Store        Docs        Blog

Creating newflight mode in Ardusub

Hi Guys,

I am new to forum and working on with ArduSub stable version. I am trying to create a newflightmode of operation in the current firmware of Pixhawk. Using the documentation provided for Copter-3.5 & earlier ( https://ardupilot.org/dev/docs/apmcopter-adding-a-new-flight-mode-35.html ) i tried to workout the problem in the same way, but it didn’t work. If any one who is familiar with this, creating newflightmode of opertation like ( stabilize ,circle,Auto etc…) kinldy provide your help here. Your help is appreciatable.

Hi,

Ok first off, I did this quite a while ago, but hopefully I can still help. There are several things you have to do. Also this is in no particular order, its just as I remember.

Create control_myFlightMode.cpp

/ardupilot/ArduSub/control_myFlightMode.cpp

This one is mostly up to you to implement. Essentially just make a controller for your flight mode. It’s probably a good idea to start it by copying one of the existing flightmodes.

Set up some enums that will be used

ardupilot/libraries/AP_JSButton/AP_JSBottton.h

add k_mode_my_flightmode = aNumberThatMakesSense, to the big typedef enum
The other flight modes are also defined here, so you can look to them for guidance.

ardupilot/ArduSub/defines.h

add MY_FLIGHTMODE = aNumThatMakesSense to the enum control_mode_t
I just added mine as the last element in the enum and gave it a value of 21

Modify Sub.h

ardupilot/ArduSub/sub.h

add prototypes for 2 methods concerning your flightmode. Can realistically put anywhere, but probably better convention to put near another flightmode.
Should look like :
bool myflightmode_init(void);
void myflightmode_run();

Modify flight_mode.cpp

ardupilot/ArduSub/flight_mode.cpp

I added my flight mode to switch statements in side of the set_mode and update_flight_mode methods.
Just look at the existing cases, copy, and modify them for your flightmode. These will use the enums you set in defines.h

in joystick.cpp

ardupilot/ArduSub/joystick.cpp

add a case to the handle_jsbutton_press method. Again just look to the cases for other flight modes when writing yours. This will use both the enums you added (k_mode_my_flightmode and MY_FLIGHTMODE).

Okay, well that’s about all I can think of right now. If it doesn’t work, the error messages from compiler can be quite useful.

I guess I should mention that mavproxy wont recognize the name of your mode, so in order to switch to it you will have to use the mavproxy command mode theNumberOfMyFlightMode where theNumberOfMyFlightMode is whatever number you set MY_FLIGHTMODE to in defines.h.

If you want your flightmode to appear in QGC, you have to modify and build it if you want it to recognize your flightmode and say the name when you swap and all that.

Hope this helps!

2 Likes

thank you Mr. @JaylTheGreat , program part has compiled, now working on with the QGC , in QGC is not yet detected, when i get it i will tell you

Cool, I don’t really have time right now to write walkthrough to do what you need to for QGC; however, I can share that my method was basically finding an example of one of the flightmodes that did exist in QGC (like depth_hold) and then basically ctl+f to find where that was being used. And then essentially just copying over how it was used. Note that it always took me a long time to compile QGC( > 5mins), so I would try to be more thorough before hitting build than usual.

Good luck :slight_smile:

thank you @JaylTheGreat i worked out it, finally after editing Qgc repo with the following ref- (https://github.com/mavlink/qgroundcontrol/search?q=depth+hold&unscoped_q=depth+hold) it got worked, it was just a copy of ALT_HOLD mode. When i simulated it with Sitl, it worked but when i flashed the same in the hardware(pixhawk) it is not working or being active in controller.

1 Like

I’m sorry, what do you mean it’s not being active in controller? like it’s not actually changing to the flightmode when you press the assigned button?

Regardless, I’m pretty busy with school for the next couple weeks and I can’t really help you troubleshoot this, perhaps one of the bluerobotics people can help you. In the past @williangalvani has been especially helpful in troubleshooting some of my issues.

1 Like