Get fault code over CAN

Support for creating custom user applications on the VESC.
h.ehlers
Posts: 2
Joined: 12 Apr 2017, 07:49

Get fault code over CAN

Postby h.ehlers » 12 Apr 2017, 08:14

Hello,
First of all, thank you benjamin for this great open source project. It helps me a lot for my graduation work. I'm a student of mechanical engineering, so forgive my poor skills in c...
I've got two VESC's for controlling two direct driven wheels. One of them is running my custom application which reads the two external ADCs and calculates setpoints for PID-speedcontrol of both VESCs. Then it sets the setpoint for itself by using the "mc_interface_set_pid_speed()" and the other via CAN by using "comm_can_set_rpm()". The second VESC isn't running a any application, and is only controlled by CAN. That's running well ...
So far so good, now I want to catch errors. For the VESC thats running the application, I would use something like "if(mc_interface_get_fault()== FAULT_CODE_NONE)", but I've got no Idea how to get the fault code of the other VESC.
Maybe someone can give me an example how to "ask" the other VESC for it's fault code and to receive the fault code to use it in my application.

Looking forward to your answers, thank you!

h.ehlers
Posts: 2
Joined: 12 Apr 2017, 07:49

Re: Get fault code over CAN

Postby h.ehlers » 13 Apr 2017, 07:33

Hello again,
I had an Idea for a quick and dirty solution for my problem. I change the firmware of the second VESC in the following way:
In "comm_can.c" I change this...

Code: Select all

static THD_FUNCTION(cancom_status_thread, arg) {
   (void)arg;
   chRegSetThreadName("CAN status");

   for(;;) {
      if (app_get_configuration()->send_can_status) {
         // Send status message
         int32_t send_index = 0;
         uint8_t buffer[8];
         buffer_append_int32(buffer, (int32_t)mc_interface_get_rpm(), &send_index);
         buffer_append_int16(buffer, (int16_t)(mc_interface_get_tot_current() * 10.0), &send_index);
         
         //my changes:
         //buffer_append_int16(buffer, (int16_t)(mc_interface_get_duty_cycle_now() * 1000.0), &send_index);
         buffer_append_int16(buffer, (int16_t)mc_interface_get_fault()), &send_index);//I do not need duty cycle, so it is now used for fault
         //end of my changes
         
         comm_can_transmit(app_get_configuration()->controller_id | ((uint32_t)CAN_PACKET_STATUS << 8), buffer, send_index);
      }

      systime_t sleep_time = CH_CFG_ST_FREQUENCY / app_get_configuration()->send_can_status_rate_hz;
      if (sleep_time == 0) {
         sleep_time = 1;
      }

      chThdSleep(sleep_time);
   }
}

And in my custom application I use

Code: Select all

if(mc_interface_get_fault()== FAULT_CODE_NONE && (uint8_t)comm_can_get_status_msg_id(1).duty == FAULT_CODE_NONE)

Would that work?

Best regards and happy Easter!

PS.: thought hard about hide some Easter eggs, but my creativity goes to zero today...


Return to “Custom Applications”

Who is online

Users browsing this forum: No registered users and 4 guests