Motor start immediately function

Are there any features that you would like to add to the VESC?
jetigm
Posts: 7
Joined: 15 Dec 2016, 15:34
Location: Ukraine

Motor start immediately function

Postby jetigm » 15 Dec 2016, 15:41

Hi,
I am playing with the VESC and I have a question about it functional modification. I want to use it in specific configuration, basically I need to start the motor immediately after the power on.
Can VESC be configured to start up the motor immediately after power on and stop after 2 seconds and all, so to start motor again - reconnect the power. And be able to configure parameters via BLDC Tool (I need current mode)?
The global question - is it hard to modify the firmware, or better don't touch it at all? I am asking about overall complexity as junior-mid level programmer.
May such feature be added in future in the config tool? It can be like a checkbox "Power on status - start immediately".

rew
Posts: 943
Joined: 25 Mar 2016, 12:29
Location: Delft, Netherlands.

Re: Motor start immediately function

Postby rew » 15 Dec 2016, 23:28

You should write an "application" for this. The "main body" will do something like:

Code: Select all

  mc_interface_set_current (XXYY);
  chThdSleepmilliseconds (2000);
  mc_interface_set_current (0);

It takes extra work if you want to be able to set the parameters through blcd-tool.

I am not sure how quickly the actual motor controller is able to actually drive a motor. It is quite possible that it wants to calibrate the "zero-value" of the current sensors by sampling the current for a few seconds after startup without the motor running....

jetigm
Posts: 7
Joined: 15 Dec 2016, 15:34
Location: Ukraine

Re: Motor start immediately function

Postby jetigm » 16 Dec 2016, 13:56

Got it, will try, thanks.

pf26
Posts: 309
Joined: 28 Mar 2016, 14:37
Location: FR Valence

Re: Motor start immediately function

Postby pf26 » 17 Dec 2016, 10:19

To be able to change the ON time, the easiest way is to reuse a BLDC-tools application parameter that you don't need for your system. For instance BAUD rate in UART setting of App configuration Menu.. (in the structure called "app_configuration" in datatypes.h, it is called "app_uart_baudrate").
Then in the function app_init (in app.c), you can call your own init function and send it the conf.app_uart_baudrate (Uint32) parameter, so as to set your local delay variable (instead of a fixed 2000 ms).

jetigm
Posts: 7
Joined: 15 Dec 2016, 15:34
Location: Ukraine

Re: Motor start immediately function

Postby jetigm » 17 Dec 2016, 17:49

Finally I am able to build the source code in the EmBitz but not sure about versions. I got the 4.12 PCB so I should use this one?
https://github.com/vedderb/bldc

pf26 - thanks for direction.

pf26
Posts: 309
Joined: 28 Mar 2016, 14:37
Location: FR Valence

Re: Motor start immediately function

Postby pf26 » 17 Dec 2016, 18:38

Yes, this is the one you need: it will show Firmware version 2.18

jetigm
Posts: 7
Joined: 15 Dec 2016, 15:34
Location: Ukraine

Re: Motor start immediately function

Postby jetigm » 10 Jan 2017, 19:06

pf26 wrote:To be able to change the ON time, the easiest way is to reuse a BLDC-tools application parameter that you don't need for your system. For instance BAUD rate in UART setting of App configuration Menu.. (in the structure called "app_configuration" in datatypes.h, it is called "app_uart_baudrate").
Then in the function app_init (in app.c), you can call your own init function and send it the conf.app_uart_baudrate (Uint32) parameter, so as to set your local delay variable (instead of a fixed 2000 ms).


I am not a professional programmer, can you kindly point me what to change in the source code.

Is the UART tweak is the only way to decrease startup delay, what else can be done?

I am played a little bit with Custom application, in some way it works but I can't understand and do some things.

For example this is works (when my "actions" in code placed after "for {}"), motor starts and stops and so on

Code: Select all

#include "ch.h" // ChibiOS
#include "hal.h" // ChibiOS HAL
#include "mc_interface.h" // Motor control functions
#include "hw.h" // Pin mapping on this hardware
#include "timeout.h" // To reset the timeout
 
// Example thread
static THD_FUNCTION(example_thread, arg);
static THD_WORKING_AREA(example_thread_wa, 2048); // 2kb stack for this thread
 
void app_example_init(void) {
   // Set the UART TX pin as an input with pulldown
   palSetPadMode(HW_UART_TX_PORT, HW_UART_TX_PIN, PAL_MODE_INPUT_PULLDOWN);
 
   // Start the example thread
   chThdCreateStatic(example_thread_wa, sizeof(example_thread_wa),
      NORMALPRIO, example_thread, NULL);
}
 
static THD_FUNCTION(example_thread, arg) {
   (void)arg;
 
   chRegSetThreadName("APP_EXAMPLE");
 
   for(;;) {

      mc_interface_set_current(20);
      chThdSleepMilliseconds(500);
      mc_interface_release_motor();
      chThdSleepMilliseconds(2000);
       
      timeout_reset();
   }
}

And this is not (when my "actions" in code placed before "for {}"), motor even don't starts

Code: Select all

   mc_interface_set_current(20);
   chThdSleepMilliseconds(500);
   mc_interface_release_motor();
   chThdSleepMilliseconds(2000);
   
   for(;;) {      
      chThdSleepMilliseconds(2);
      timeout_reset();
   }
}

Say I want to start the motor once at all so I typed like this, and it does not work, motor don't starts again

Code: Select all

   char a=0;
   
   for(;;) {   
      if (a==0) {
         mc_interface_set_current(20);
         chThdSleepMilliseconds(500);
         mc_interface_release_motor();
         a=1;
      }
      timeout_reset();
   }
}

Does the Custom Application body is restarted every time or it runs cycled in the "for {}" body?

What is timeout_reset();?

Can the chThdSleepMilliseconds(1000); in the main.c be removed? I have tried it, and it is decreases a startup delay but I am not sure is this a critical delay or not.

Code: Select all

int main(void) {
   halInit();
   chSysInit();

   chThdSleepMilliseconds(1000);

   hw_init_gpio();
   LED_RED_OFF();
   LED_GREEN_OFF();

arvidb
Posts: 234
Joined: 26 Dec 2015, 14:38
Location: Sweden, Stockholm

Re: Motor start immediately function

Postby arvidb » 10 Jan 2017, 19:50

Calling mc_interface_release_motor() is equivalent to calling mc_interface_set_current(0). So if that call is the last thing you do before the for loop, then naturally the motor won't move. Edit: But of course the motor should start once, for 500 ms, in your "motor even don't starts" example. But you might need to call timeout_reset() once before your first call to mc_interface_set_current(). This might also reduce your startup time by 2.5 seconds. :)

If timeout_reset() is not called at least once every second, the motor is braked. Look in timeout.c. (At least it looks like that's how it's supposed to work in the code.)

arvidb
Posts: 234
Joined: 26 Dec 2015, 14:38
Location: Sweden, Stockholm

Re: Motor start immediately function

Postby arvidb » 10 Jan 2017, 20:01

That is, try something like this:

Code: Select all

   timeout_reset();
   mc_interface_set_current(20);
   chThdSleepMilliseconds(500);
   timeout_reset();
   chThdSleepMilliseconds(500);
   timeout_reset();
   chThdSleepMilliseconds(500);
   timeout_reset();
   chThdSleepMilliseconds(500);
   mc_interface_set_current(0);
   for(;;) {     
      timeout_reset();
      chThdSleepMilliseconds(500);
   }
}

rew
Posts: 943
Joined: 25 Mar 2016, 12:29
Location: Delft, Netherlands.

Re: Motor start immediately function

Postby rew » 10 Jan 2017, 20:03

jetigm wrote:Can the chThdSleepMilliseconds(1000); in the main.c be removed? I have tried it, and it is decreases a startup delay but I am not sure is this a critical delay or not.

In my experience a delay like that helps get the virtualcomport detected. Because there is nothing VESC-specific before that point, I don't see why it would interfere with the normal operation.

On the other hand, what I mentioned before, the calibration of the current sensors, should not happen too close to "poweron" things might still be a bit shaky. A powersupply rails might still be moving a bit, causing the reference point for the current sense to change. But if your system works fine without it, I would say you can remove it.

As to the autostart, I'd try getting the motor to run and NOT stop before adding the "and now stop" code....


Return to “Feature Requests”

Who is online

Users browsing this forum: No registered users and 2 guests