New mode - how to directly control motor?

Good day,

I’ll start by giving some background information, just so you can understand what I’m trying to do: I’m trying to create a new custom mode for my quad and I wanted to directly control a motor based on a transmitter signal. I wish to control a brushless motor which is connected to a blheli_s ESC (using dshot).

For the past 5 days, I have been analysing the code from arducopter, trying to figure out how can I control that motor in a new mode. Previously to this, I also tried to find information online about this, but unfortunately, wasn’t succesful. I was already making my code when I saw Copter: Add new TURTLE mode - Flip over after crash by andyp1per · Pull Request #18140 · ArduPilot/ardupilot ( which confirmed me I was doing things in the right way. I thought everything was going great until I test the code. The motor indeed spinned, but I could hear a lot of scrapping noise (and that is the reason for creating this topic).

I tried to debug the code and ended up with a final version, in which in my run() I only have: “motors->rc_write(AP_MOTORS_MOT_1, 1300);” (since I’m using dshot, a value between 1000 and 2000 should be written). Unfortunately, when I run it, the motor still does a lot of scrapping noise, so clearly, there is a problem with motors->rc_write() and the way I’m using it (which is used in a similar way to the new mode turtleMode). I’m saying this is an issue with the way I’m using motors->rc_write() because when I change to Stabilize mode, and speed up that motor, it runs very smoothly.

Can someone point me in the right direction, tell me what I’m doing wrong or where I can find information on how to implement this?

For reference, at the moment, the new code is simply the following (haven’t posted the rest of modifications which enable you to use a new mode - followed this tutorial Adding a New Flight Mode to Copter — Dev documentation (

void ModeTest::run()
    motors->rc_write(AP_MOTORS_MOT_1, 1300);

Can you share your branch.


I have commented everything and have only the rc_write in the mode. The init and exit are just for a set of servos.

I think you need to make sure both the vehicle and motors are armed.

I previously did it, in here: if( || !copter.ap.rc_receiver_present || !motors->armed()){ (have tested again with this line). But same behaviour. Also, the motor only starts after arming the motors.

By the way, this is the sound the motor does, which is very different from the one in stabilize mode, even at 100% throttle (this is kinda scrapping):

Do you get the same noise if you use turtle mode?

I haven’t tried turtle mode, but I can give it a try. Just give me 10 minutes.

It seems I can’t enter turtle mode. In telemetry I’m getting the following line: " Mode change to TURTLE failed: initialisation failed". I will try to see the log because this is the only thing I had in mission planner.


Copter-4.1.0 added a new parameter, SERVO_DSHOT_ESC. I will change it and test the code.


Just tested and the answer is yes. Turtle mode makes also this very strange motor noise (like scrapping, similar to timing problems).


Should have added previously, in the beggining, but with this noise the motor gets hot very quickly and doesn’t seem to spin at the same speed as previously (in stabilize mode, for same throttle).

You can get to very high throttle this way (so motors get hot), but I’m not aware that the signal is any different to other modes.

I have just made a video so you can compare the sound difference between stabilize (first mode) and turtle mode (the same problem I was having with rc_write()). In both modes I went to full throttle. This is the current master branch, just compiled and uploaded to Pixhawk1. Sorry for the beeping sound, the battery of my transmitter is dead and I need to change it for a new one.
This happens with all the motors, but only one connected for the video.

These motors for maximum throttle without propeller shouldn’t get this hot (they are like 60ºC). During the test of my code, I also had to change motors because one started to clog with the rc_write() (but changing the mode to stabilize makes it work again).

I don’t know that much about the intrinsics of the code (just learning) - I think I say this a lot of time -, but attitudecontrol can’t cause this? It continues to update, right? (maybe this is just nonsense, but the problem is clearly from rc_write())

Might also be interesting to test how they sound via motor test…

Can you try this to see if it helps in turtle mode?

1 Like

In motor test they sound just like in stabilize mode. This with Copter-4.0.7. But I can test latter on current master.


Motor works as it should with motor test (although it seemed to be a bit louder, but maybe just from my head - not any near the sound turtle mode was doing).

I will test it in 2h and get back to you. Also will test the motor test.


Your new branch solves the issue.

I think this thread can be closed (solved), as andyp1per exposes in this PR, issue on using rc_write() was from dual motor output from both Mode::run() and Copter::motors_output().

Thanks for the help.

1 Like