Vesc constant speed control in code?

General topics and discussions about the VESC and its development.
Posts: 1
Joined: 01 Jun 2018, 04:58
Location: New York

Vesc constant speed control in code?

Postby John23 » 01 Jun 2018, 05:07

Hi, I'm new a little new to the Vesc and was wondering where the speed command is in the code. I'd like to go into the source code and command the motor to run my motor at a certain speed. Basically I want to flash the Vesc and connect it to a motor and have it run at a specific speed. Change a number in the code that represents speed, reflash the Vesc, and power it back on and have the motor run at a new speed. Any suggestions on how this might be done or where the speed commands come in for the code that I could set to a specific number that represents speed? Or am I better off trying to write a new function? Thanks, I hope this makes sense :)

Posts: 294
Joined: 28 Mar 2016, 14:37
Location: FR Valence

Re: Vesc constant speed control in code?

Postby pf26 » 01 Jun 2018, 08:26

You don't need to change the code. You can add a little application to the firmware. You can create a file like this:

Code: Select all

// Settings
 #define SpeedReference   3000

#include "ch.h" // ChibiOS
#include "hal.h" // ChibiOS HAL
#include "mc_interface.h" // Motor control functions
#include "utils.h"

// Example thread
static THD_FUNCTION(reso_thread, arg);
static THD_WORKING_AREA(reso_thread_wa, 1024); // 2kb stack for this thread

void app_reso_init(void) {
   // Start the example thread
   chThdCreateStatic(reso_thread_wa, sizeof(reso_thread_wa),
      NORMALPRIO, reso_thread, NULL);

// Regul du duty cycle
static THD_FUNCTION(reso_thread, arg) {

   for(;;) {

      // Reset timeout

      // Run this loop
      chThdSleepMilliseconds(10);  // 100Hz

There are more info about apps on the vedder website.

Return to “General”

Who is online

Users browsing this forum: No registered users and 1 guest