Implement your own motor control logic directly in firmware using the custom application template.
The custom application (APP_CUSTOM) lets you run arbitrary C code inside the VESC firmware. You get full access to the motor control interface, CAN bus, ADC inputs, timers, and every other peripheral — with no overhead from an external protocol.
stop_now and is_running are the two flags that safely shut down the thread. app_custom_stop sets stop_now = true and then busy-waits until is_running becomes false. The thread must check stop_now on every iteration and return when it is set.
Call timeout_reset() inside your main loop on every iteration where the system is operating normally. If timeout_reset is not called within the configured timeout window (APPCONF_TIMEOUT_MSEC, default 1000 ms), the firmware applies the brake current defined by APPCONF_TIMEOUT_BRAKE_CURRENT and stops motor output.
Forgetting timeout_reset() in your loop will cause the motor to stop after one second of running your custom application.
pwm_callback is invoked every control iteration at the PWM switching frequency (typically tens of kHz). Keep it very short. Do not call blocking functions or allocate memory inside it.
Register custom commands with terminal_register_command_callback. They appear in the VESC Tool Terminal tab and can be used for debugging and calibration during development.
These three functions are called by the main application dispatcher whenever the configuration changes or the application is started or stopped. You must implement all three.