You are here

Can't spin both motors over CAN-bus

4 posts / 0 new
Last post
Kokonenen
Offline
Last seen: 1 year 1 day ago
Joined: 2023-02-16 08:41
Posts: 12
Can't spin both motors over CAN-bus

Edit: I managed to solve this as you can see in my updates below. Hope it will be of help to anyone else attempting this :) I'm still trying to get the integrated traction control and rpm synchronization between the two motors to work (as I believe the vesc is able to do this? A bit misleading that the option is under VESC Remote settings but seems to be for any control method). Anyhow if anyone has any advice on how to achieve this when using arduino and the VescUart library it would be greatly appreciated, currently I'm simply giving the same command to both VESC's, but if I slow down one motor with my hand the other one is unaffected and keeps spinning at set speed, ideally it would slow down or add more current to the impaired motor to sync them.

 

Hey, seems like several people have had this issue over the years. But I can't manage to spin both motors with vesc tool using CAN forwarding. When I run the setup FOC the Vesc tool detects both motors, one through USB and one through can, and the setup runs them simultaneously. But when I try to rev on my own I can only spin the selected CAN under can devices (meaning I can spin both motors individually, but not together).

My master vesc has UART as app to use and Multiple vescs over can is TRUE, while slave has no app and multiple vescs set as FALSE.

The vesc ID on my master is 2 and 4 on my slave. Both have CAN messages rate 1 enabled at 50hz and status 1-4 selected. 

Since both motors are detected and I can rev them without issue, and especially since VESC-TOOL can spin them simultaneously during setup, I really can't figure out why I cant.

Am I simply unable to spin them both with the built in vesc tool rev function? My next step is to connect a joystick through arduino and the COMM (uart) port and just hope that it works)

The CAN mode is vesc on both of them and I have flashed the same firmware first individually and then together through CAN. It's on vesc 6.0 and I am using two identical VESC 6 MKVI with two identical BLDC motors (running FOC mode)

Any tips?

Kokonenen
Offline
Last seen: 1 year 1 day ago
Joined: 2023-02-16 08:41
Posts: 12

The only thing I can't test is the connection tab under CAN, since when I try to scan it simply says: CAN bus support is not enabled in this version of the VESC tool

I've set it manually to the slave vesc though and the slave vesc also has the "CAN forwarding" enabled and is identified by vesc tool as a CAN bus motor/vesc.

Kokonenen
Offline
Last seen: 1 year 1 day ago
Joined: 2023-02-16 08:41
Posts: 12

Update: Connected it with arduino and a joystick through the UART (Comm) port. Still not working, only the master vescs motor is spinning. I am currently unsure how to proceed

Kokonenen
Offline
Last seen: 1 year 1 day ago
Joined: 2023-02-16 08:41
Posts: 12

Update! It works perfectly with arduino and a potentiometer!! All I had to do was write two commands, one to control the first motor with the arduino, and one that sends the information forward through the can bus to the ID of the vesc. I am unsure if traction control or the vesc can regulate these two motors together when writing it like this. But I hope it does. I'll post the code below, but here  is the code that actually sends it to the motors: 

      VESCUART.setCurrent(map(analogRead(PotentiometerPin), 0, 1023, -21, 21)); //Send command to master vesc
      VESCUART.setCurrent(map(analogRead(PotentiometerPin), 0, 1023, -21, 21),4); //Send command to slave vesc with Can_ID 4

 

------------- Here is the code --I used SolidGeeks VescUart library-The switchstate is simply a switch that changes direction. I hope this can help someone else :)---------------

// #include <LiquidCrystal.h>
#include <buffer.h>
#include <crc.h>
#include <datatypes.h>
#include <VescUart.h>

VescUart VESCUART;
#define Slave 4

const int DirectionSwitch = 2; // Pin connected to one of the switch poles
const uint8_t PotentiometerPin = A1; //Analog Pin connected to the Potentiometer

uint32_t LastTime = 0; 

void setup() {

  pinMode(DirectionSwitch, INPUT_PULLUP);
  Serial1.begin(115200);
  Serial.begin(115200);

  VESCUART.setSerialPort(&Serial1);

}

void loop() {
  
  int switchState = digitalRead(DirectionSwitch); //Read the state of the switch pin
  

  if((millis() - LastTime) > 10){

      if (switchState == LOW){
   
      VESCUART.setCurrent(map(analogRead(PotentiometerPin), 0, 1023, -21, 21));
      VESCUART.setCurrent(map(analogRead(PotentiometerPin), 0, 1023, -21, 21),4);

      }

      else if (switchState == HIGH) {

      VESCUART.setCurrent(map(analogRead(PotentiometerPin), 0, 1023, 21, -21));     
      VESCUART.setCurrent(map(analogRead(PotentiometerPin), 0, 1023, 21, -21),4);

        
      }

  
    
    //Serial.println(analogRead(PotentiometerPin));
    Serial.println(digitalRead(DirectionSwitch));

    //Serial.println(PotentiometerPin);
    
    LastTime = millis();
    

  }  

 }