Hello,
I have a new kind of problem which i could not understand.
i have written a stand alone app to rotate motor at a fix speed.
but it only works when i connect VESC tool to it with USB.
otherwise the motor starts to cog and the motor vibrates very badly.
The code is shown below.
// FixSpeed thread
static THD_FUNCTION(FixSpeed_thread, arg);
static THD_WORKING_AREA(FixSpeed_thread_wa, 2048); // 2kb stack for this thread
void app_FixSpeed_init(void) {
// Start the example thread
chThdCreateStatic(FixSpeed_thread_wa, sizeof(FixSpeed_thread_wa),
NORMALPRIO, FixSpeed_thread, NULL);
}
static THD_FUNCTION(FixSpeed_thread, arg) {
(void)arg;
chRegSetThreadName("APP_FixSpeed");
//Set initial RPM
static float pid_rpm = 2000;
static float final_rpm = 6000;
chThdSleepMilliseconds(500);
timeout_reset();
for(int i=0;i<final_rpm;i++)
{
mc_interface_set_pid_speed(i);
chThdSleepMilliseconds(5);
timeout_reset();
}
for(;;) {
mc_interface_set_pid_speed(6000);
// Run this loop at 500Hz
chThdSleepMilliseconds(2);
// Reset the timeout
timeout_reset();
}
}