vedderb / bldc

The VESC motor control firmware
2.09k stars 1.31k forks source link

COMM_SET_MCCONF not receiving acknowledge reply and does not set any values #610

Open bmalbusca opened 1 year ago

bmalbusca commented 1 year ago

Hello,

I'm trying to configure motors using the COMM_SET_MCCONF command with FW 6.0x via UART in VESC. However, I'm not receiving a reply from VESC for the packet id COMM_SET_MCCONF, and the motor configuration is not being changed. Although I am able to read the current configuration using COMM_GET_MCCONF, which indicates that my UART receiving function is working (or if it's not working in this specific case, the configuration should still be set) as well as the function that processes the configuration packet. I'm trying to activate or deactivate Field Weakening, and the only method I've found is using the COMM_SET_MCCONF interface. The routine on vedderb's that processes the commands is here

VescUartSet - Main function


bool VescUartSet(mc_configuration& config, int num) {
 // based on https://github.com/vedderb/bldc/blob/fea2c81e55ab68b8476d6b1514595306691f3375/comm/commands.c#L535

int len =0,ret_pack = 0;
 uint8_t receivedpayloadGlobal[PACKET_MAX_PL_LEN];

  payloadGlobal[0] = COMM_SET_MCCONF; 
  int lenPayload = confgenerator_serialize_mcconf(payloadGlobal + 1, &config); // from vedderb https://github.com/vedderb/bldc/blob/9a436992b7b829b82af9b407288d723341a08d1d/confgenerator.c#L8 

  packet_send(payloadGlobal, lenPayload+1, num);

  len = ReceiveUartMessage(receivedpayloadGlobal, num); // does not received, len =0
  delay(100);

  if (len > 1 || len == 0 || receivedpayloadGlobal[0] != 13) {
    Serial.println("wrong answer from Vesc. should be lenPayload = 1 and payload[0] == 13 (COMM_SET_MCCONF)");

  }
  else
  {
    return true; //setting of mc-config was sucessful
  }
} 

packet_send - Send packet over serial


int packet_send(uint8_t* payload, int lenPay, int num) {
//based on https://vscode.dev/github/basti30/VescUartControl/blob/fdeb5bfca8f9c10acc51ff8ae5fef26bb2c129c2/packet.c#L41

  if (lenPay == 0 || lenPay > PACKET_MAX_PL_LEN) {
        return 0;
    }

  uint16_t crcPayload = crc16(payload, lenPay);
  int count = 0;

  uint8_t messageSend[PACKET_MAX_PL_LEN]; //glob

  if (lenPay <= 256)
  {
    messageSend[count++] = 2;
    messageSend[count++] = lenPay;
  }
  else if ( lenPay <= 65535)
  {
    messageSend[count++] = 3;
    messageSend[count++] = (uint8_t)(lenPay >> 8);
    messageSend[count++] = (uint8_t)(lenPay & 0xFF);
  }
  else{ 
    messageSend[count++] = 4;
        messageSend[count++] = lenPay >> 16;
        messageSend[count++] = (lenPay >> 8) & 0xFF;
        messageSend[count++] = lenPay & 0xFF;

  }
  memcpy(&messageSend[count], payload, lenPay);

  count += lenPay;
  messageSend[count++] = (uint8_t)(crcPayload >> 8);
  messageSend[count++] = (uint8_t)(crcPayload & 0xFF);
  messageSend[count++] = 3;
  messageSend[count] = 0;

 //SerialPrint0(messageSend, count); // DEBUG

  HardwareSerial *serial;

  switch (num) {
    case 0:
      serial=serialPort1;
      break;
    case 1:
      serial=serialPort2;
      break;
    case 2:
      serial=serialPort3;
      break;
    case 3:
      serial=serialPort4;
      break;
    default:
      break;
  }

  //Sending package

  serial->write(messageSend, count);

  //Returns number of send bytes
  return count;
}

Example of 481-length packet sent : [13, 250, 68, 219, 2, 224, 1, 35, 152, 0, 0, 0, 0, 254, 131, 86, 128, 63, 251, 37, 64, 63, 240, 0, 224, 117, 0, 0, 0, 179, 63, 255, 255, 126, 32, 4, 96, 0, 0, 0, 0, 0, 0, 119, 128, 0, 0, 0, 22, 0, 22, 0, 21, 0, 0, 0, 21, 0, 20, 48, 0, 0, 0, 19, 0, 0, 0, 0, 0, 0, 0, 0, 83, 34, 126, 64, 6, 0, 254, 141, 166, 144, 0, 0, 0, 0, 255, 255, 64, 8, 53, 104, 126, 65, 198, 0, 254, 141, 166, 144, 0, 21, 78, 149, 126, 64, 134, 0, 126, 65, 4, 96, 48, 38, 251, 63, 0, 0, 0, 0, 126, 64, 132, 96, 179, 63, 255, 255, 179, 63, 255, 255, 117, 128, 0, 0, 0, 0, 0, 0, 4, 126, 65, 4, 96, 126, 64, 132, 96, 0, 64, 8, 73, 156, 64, 8, 151, 100, 119, 64, 0, 0, 179, 63, 255, 255, 179, 63, 255, 255, 117, 0, 0, 0, 117, 0, 0, 0, 126, 65, 4, 0, 255, 255, 179, 63, 255, 255, 0, 0, 0, 0, 83, 46, 179, 63, 255, 255, 64, 8, 202, 88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35, 4, 6, 0, 255, 7, 81, 104, 63, 251, 38, 64, 0, 0, 0, 0, 255, 255, 152, 8, 80, 48, 0, 0, 76, 165, 1, 255, 0, 0, 0, 21, 0, 21, 0, 0, 0, 0, 63, 251, 39, 0, 0, 1, 0, 0, 0, 0, 255, 85, 63, 251, 38, 144, 63, 251, 218, 204, 126, 64, 196, 96, 76, 165, 73, 62, 0, 0, 0, 0, 0, 0, 76, 165, 240, 0, 126, 65, 4, 0, 16, 0, 0, 0, 0, 83, 94, 0, 0, 0, 0, 240, 0, 0, 0, 0, 0, 0, 63, 251, 38, 224, 63, 252, 67, 28, 120, 118, 0, 0, 0, 179, 63, 255, 255, 117, 0, 0, 0, 0, 0, 254, 214, 6, 64, 32, 117, 0, 0, 0, 63, 252, 211, 176, 63, 252, 211, 176, 63, 252, 64, 84, 0, 0, 0, 0, 0, 0, 254, 214, 6, 64, 0, 19, 119, 192, 0, 0, 0, 0, 63, 251, 39, 68, 63, 251, 39, 58, 0, 0, 0, 0, 0, 4, 0, 0, 63, 251, 39, 128, 0, 0, 0, 16, 0, 0, 0, 0, 7, 178, 8, 81, 7, 170, 0, 0, 96, 176, 176, 180, 63, 251, 39, 156, 119, 0, 0, 0, 63, 251, 39, 60, 254, 211, 125, 48, 128, 255, 63, 252, 54, 140, 0, 0, 0, 19, 180, 8, 115, 63, 251, 39, 208, 0, 0, 0, 0, 140, 0, 63, 251, 39, 152, 63, 251, 90, 160, 0, 16, 0, 196, 0, 0, 7, 178]