Arduino-FOC icon indicating copy to clipboard operation
Arduino-FOC copied to clipboard

[BUG] When SimpleFOCStudio get motion_downsample, this value will become very large

Open HareGun opened this issue 3 years ago • 0 comments

Hi SimpleFOCproject’s friends,

Describe the bug I using SimpleFOCStudio to debug my device. And I found that when I click Connect, the value of motion downsample will change to 11111.0. I don't know if there was such a problem before.

To reproduce this problem, you can manually send the command "ACD" to simulate the situation where SimpleFOCStudio get motion_downsample value.

I am currently using the following repository node:

  • [Arduino-FOC] Commit ID: 1acfda1d22aac484ab231fafd729f480603fd854
  • [SimpleFOCStudio] Commit ID: 85b5277f273c4c8efbbf298ef4420cf9cd11d1e1

Problem analysis: In file: src\communication\Commander.cpp, line: 334

void Commander::motion(FOCMotor* motor, char* user_cmd, char* separator){
  char cmd = user_cmd[0];
  char sub_cmd = user_cmd[1];
  bool GET  = isSentinel(user_cmd[1]);
  float value = atof(&user_cmd[(sub_cmd >= 'A'  && sub_cmd <= 'Z') ?  2 :  1]);

  switch(cmd){
    case CMD_MOTION_TYPE:
      printVerbose(F("Motion:"));
      switch(sub_cmd){
        case SCMD_DOWNSAMPLE:
            printVerbose(F(" downsample: "));
            if(!GET) motor->motion_downsample = value;
            println((int)motor->motion_downsample);
          break;
        default:
          ......
          break;
      }
      ......
  }
}

From here, get the value of motion_downsample will receive a three character instruction. However, the GET judgment here directly specifies the user_cmd[1]. This will change the get command to set and assign the wrong value to the motion_downsample. I think this should be changed to the following, similar to the previous Commander::motor() function.

  int value_index = (sub_cmd >= 'A'  && sub_cmd <= 'Z') ?  2 :  1;
  bool GET  = isSentinel(user_cmd[value_index]);
  float value = atof(&user_cmd[value_index]);

Describe the hardware setup This question should have nothing to do with motor, driver, microcontroller, position sensor, Current sensing, IDE...

HareGun avatar Aug 08 '22 13:08 HareGun