You are here

Set RPM - reverse direction over CAN-Bus

5 posts / 0 new
Last post
65273
Offline
Last seen: 1 year 2 months ago
Joined: 2022-02-16 12:33
Posts: 2
Set RPM - reverse direction over CAN-Bus

Hi everyone,

I am currently developing an omnidirectional model vehicle with 4 Vescs. Using a STM microcontroller we communicate with the VESCs over CAN bus. I have already managed to make all motors spin independently. The Hex Value in the CAN bus is in ERPM right?
I have now spent many hours writing hex values to the CAN bus. I have not been able to figure out how to reverse the motor direction so that we can drive forward and backward. Is there a bit to invert it or is there a point where the motor direction changes? What is the CAN message (SET RPM) for reverse direction.

Thanks for your help!

 

 

a.dahhak
Offline
Last seen: 8 months 1 week ago
Joined: 2020-02-27 12:04
Posts: 17

Hello,

You can go to code and see how it is coded (can_comm.c), but I think in default code you cannot do it. I needed the same thing for an application so I proceeded this way.

I rescaled this in the code (mc_interface.h, using duty mode because I use duty and not speed mode). Adding this line of code (mcpwm_set_duty(DIR_MULT * ((2.0 * dutyCycle) - 1.0));), I was able to set the 0%  real duty cycle with a CANbus message of 50%, -100% with a message of 0% and +100% with a message of 100%.

void mc_interface_set_duty(float dutyCycle) {
  if (fabsf(dutyCycle) > 0.001) {
  SHUTDOWN_RESET();
  }
   
  if (mc_interface_try_input()) {
  return;
  }
   
  switch (motor_now()->m_conf.motor_type) {
  case MOTOR_TYPE_BLDC:
  case MOTOR_TYPE_DC:
  mcpwm_set_duty(DIR_MULT * ((2.0 * dutyCycle) - 1.0));
  break;
   
  case MOTOR_TYPE_FOC:
  mcpwm_foc_set_duty(DIR_MULT * dutyCycle);
  break;
   
  default:
  break;
  }
  }

 

 

Abdelilah

a.dahhak
Offline
Last seen: 8 months 1 week ago
Joined: 2020-02-27 12:04
Posts: 17

You can bring your changes on like below on (void mc_interface_set_pid_speed(float rpm)) as you are in speed mode.

Once you changes the code, you run a compilation using "make" on linux platform. The steps to do it are given on README file on VESC github.

Make sure that you choose the right hardware version that you use on "conf_general.h) !!

 

Abdelilah

frank
Offline
Last seen: 3 days 1 hour ago
VESC BronzeVESC FreeVESC GoldVESC OriginalVESC PlatinumVESC Silver
Joined: 2016-12-27 20:19
Posts: 847

You can also script this in QML or LISP, using the beta VESC-Tools scripting interface. The script is then loaded onto the unit.

65273
Offline
Last seen: 1 year 2 months ago
Joined: 2022-02-16 12:33
Posts: 2

Thank you very much for the answers, that actually gave me an idea.

it's too simple to be true. Everything is already implemented in the default code! The key is two's complement to represent the negative values in hex.

Example values with the SetRPM command:
+1000 ERPM => 0x00000E38
- 1000 ERPM => 0xFFFFFC18
This makes it very easy to send the corresponding CAN messages directly from the microcontroller. Now I'm able to spin the motors independently in any direction. NICE!

 

65273