# Creating newflight mode in Ardusub

**URL:** <https://discuss.bluerobotics.com/t/creating-newflight-mode-in-ardusub/6776>\
**Category:** Blue Robotics Software\
**Tags:** ardusub, sitl, simulate\
**Created:** [January 30, 2020, 6:42am UTC](https://discuss.bluerobotics.com/t/creating-newflight-mode-in-ardusub/6776 "2020-01-30T06:42:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bala](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@Bala](https://discuss.bluerobotics.com/u/Bala)\
**Post date:** [January 30, 2020, 6:42am UTC](https://discuss.bluerobotics.com/t/creating-newflight-mode-in-ardusub/6776/1 "2020-01-30T06:42:05Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![JaylTheGreat](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@JaylTheGreat](https://discuss.bluerobotics.com/u/JaylTheGreat)\
**Post date:** [February 8, 2020, 7:24pm UTC](https://discuss.bluerobotics.com/t/creating-newflight-mode-in-ardusub/6776/2 "2020-02-08T19:24:33Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Bala](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@Bala](https://discuss.bluerobotics.com/u/Bala)\
**Post date:** [February 12, 2020, 5:34am UTC](https://discuss.bluerobotics.com/t/creating-newflight-mode-in-ardusub/6776/3 "2020-02-12T05:34:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JaylTheGreat](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@JaylTheGreat](https://discuss.bluerobotics.com/u/JaylTheGreat)\
**Post date:** [February 14, 2020, 3:42pm UTC](https://discuss.bluerobotics.com/t/creating-newflight-mode-in-ardusub/6776/4 "2020-02-14T15:42:58Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![Bala](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@Bala](https://discuss.bluerobotics.com/u/Bala)\
**Post date:** [February 17, 2020, 4:56am UTC](https://discuss.bluerobotics.com/t/creating-newflight-mode-in-ardusub/6776/5 "2020-02-17T04:56:32Z")

</div>

thank you @JaylTheGreat i worked out it, finally after editing Qgc repo with the following ref- ([Search · depth hold · GitHub](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.

---

<div class="post-metadata">

**Author:** ![JaylTheGreat](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@JaylTheGreat](https://discuss.bluerobotics.com/u/JaylTheGreat)\
**Post date:** [February 19, 2020, 3:16pm UTC](https://discuss.bluerobotics.com/t/creating-newflight-mode-in-ardusub/6776/6 "2020-02-19T15:16:31Z")

</div>

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.
