How to drive ESC Motor from Ardupilot Firmware

Hi Guys,

i have an CubeOrange and want to drive an ESC Motor.
I flashed the Examples for RCOutput and AP_Motors but i dont get the motor to run.
After flashing AP_Motors example i can connect with CubeOrange as follows:

mavproxy.py --setup --master /dev/serial/by-id/....

I only get the following printf:

Press 't' to run motor orders test, 's' to run stability patch test. Be careful the motors will spin.

When i press ‘t’ nothing happens and even the output that motor test is running does not print.

I plugged the rc outputs to an oscilloscope and could not measure anything.
Can someone help me or give an example on how to drive an esc motor?

Thanks for your help

Have you followed the “first time setup” instructions in the wiki?
https://ardupilot.org/copter/docs/configuring-hardware.html

Hi @kd0aij,

thanks for your reply. Yeah at first i tested the drone if all is working and ready to arm.

But i only want to drive a single esc motor from ardupilot firmware. Cause of this i read at developer side that i could use RCOutput class to send pwm singals, so i tried these examples but could not get a signal out.

What is your use case? Do you need any of the other Ardupilot functionality?
I’m not familiar with the AP_Motors example but maybe @iampete could provide more info on how to use it.

I want to do this like described in the developer documentation:
https://ardupilot.org/dev/docs/learning-ardupilot-rc-input-output.html

Go and have a look at the libraries/AP_HAL/examples/RCOutput/RCOutput.cpp example sketch. You’ll see that it just sets up all the channels to wave the servos from minimum to maximum over a few second period. Hook up some servos to your board and then test to make sure it works for you.

And this is not working for me. I measured all of my 14 output channels with an oszilloscope, but didnt get any value.

I suspect you are not getting many replies because we’re not sure what you are trying to achieve and why it seems you are using a non-standard method.

If you just want to test an ESC and motor, and potentially go onto using it in some permanent arrangement, you only need standard firmware installed, USB to MissionPlanner and go into the motor test section.
You would need to configure the frame details too, or nothing related to motors will work. So set it as a QuadX for simplicity and familiarity.

Thanks for your replys,

sorry i have to explain a bit more.

I want to customize the ardupilot firmware. Therefore i need to drive a seperate esc motor for my purpose.

So my workflow is something like this: Read sensor → run custom logic → drive esc motor based on this logic. The esc motor i want to drive has nothing to do with the four motors used for flying.
So first i wanted to test if i could drive a separate motor without firmware to include this knowledge to build custom firmware.

I hope it is a bit clearer now.

You may even be able to run the standard firmware and use a PWM output to run the other motor via some input conditions such as LUA scripting, companion computer, Mavlink (telemetry commands) or just plain RC channel passthrough.
There’s almost never a need to modify the firmware - if you can think of 10 crazy things to do with a flight controller, chances are someone has done 12 of them :slight_smile:
In this case lots of people hang all sorts of things off their flight controllers.

Notice how both these are by the same person :laughing:

Looks nice,

can you give me a starting point with lua scripting and ardupilot firmware?

It really depends what this additional motor is for and what conditions you expect to drive it.
Someone here may be able to help with suggested LUA script samples if we know more details.
But LUA scripting capability has been expanding constantly:

https://ardupilot.org/copter/docs/common-lua-scripts.html

https://ardupilot.org/copter/docs/common-scripting-applets.html#common-scripting-applets

Thank you,

how can i access one of the 14 outputs of my CubeOrange in lua script?
One example is something like this:

local K_AILERON = 4
local aileron_channel = SRV_Channels:find_channel(K_AILERON)

And setting pwm output is done as follows:

SRV_Channels:set_output_pwm_chan_timeout(aileron_channel, 1700, 1000)

A command says that this will set MAIN1 servo. How is the mapping from channels to outputs?
Why is channel four MAIN OUT 1?

Thanks for your feedback

Hi Guys,

i have successfully run the RCOutput example. I can now drive a servo motor with it.
The only thing i had to do was adding the following method call in the setup function:

hal.rcout->force_safty_off();

Now everything works as expected.

Thanks for your help and have a good one!

2 Likes