Dual control

General topics and discussions about the VESC and its development.
parasole
Posts: 19
Joined: 29 Mar 2017, 05:18

Dual control

Postby parasole » 12 Sep 2017, 18:52

Hi experts,

would you please highlight me on the following... question regarding VESC being controlled from two different inputs, i.e. throthle connected to analog and commands via serial? While there is no problem with throttle, the motor won't start from another controller (ForumsController) processing PAS sensor. Serial connection should be OK, at list data from VESC is coming and displayed, however no any reaction while pedaling... Any way to check from VESC side if communication is OK and commands are coming?

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

Re: Dual control

Postby rew » 13 Sep 2017, 09:25

This is "expected".

The ADC app has a refresh rate of 500Hz. Through serial you are sending: set current to 20A, and then within 1/500th of a second, the ADC app will set it back to 0A if you don't apply that throttle.

It seems that more people fall for this trap. Maybe someone should modify the ADC app to not repeatedly set the current to zero once the "off" level has been reached. Then you can control the motor through serial or USB once when the throttle is at idle.

parasole
Posts: 19
Joined: 29 Mar 2017, 05:18

Re: Dual control

Postby parasole » 13 Sep 2017, 15:49

Thanks rew, now I remember I saw some where this explanation before, it makes sense... I will try to look in to the ADC app, altough not that proficient in programing, will try to engage my son... Do you know the place to start looking into? I am not yet familiar with VESC software structure...

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

Re: Dual control

Postby rew » 13 Sep 2017, 17:34

There is a subdirectory called "applications" or something like that. Then there is a file called app_adc.c or something like that.

The whole thing should be pretty readable even for someone not expert in "C".

parasole
Posts: 19
Joined: 29 Mar 2017, 05:18

Re: Dual control

Postby parasole » 13 Sep 2017, 18:03

Yes I know this, the question is about the code itself... I think I found it, now the question is to find out the mening for all used variables and then to introduce one more check and not to send any duty value in case throtle is less then treshould level...

case ADC_CTRL_TYPE_DUTY:
case ADC_CTRL_TYPE_DUTY_REV_CENTER:
case ADC_CTRL_TYPE_DUTY_REV_BUTTON:
if (fabsf(pwr) < 0.001) {
ms_without_power += (1000.0 * (float)sleep_time) / (float)CH_CFG_ST_FREQUENCY;
}

if (!(ms_without_power < MIN_MS_WITHOUT_POWER && config.safe_start)) {
mc_interface_set_duty(utils_map(pwr, -1.0, 1.0, -mcconf->l_max_duty, mcconf->l_max_duty));
send_duty = true;
} else send_duty = false;
break;
Update: any one may evaluate additional else statement? What is MIN_MS_WITHOUT_POWER?

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

Re: Dual control

Postby pf26 » 14 Sep 2017, 06:47

send_duty seem to only be used to allow transmission of the duty cycle to other VECSs via CAN bus.
I think you need to set "current_mode = false" in cases you want this app not to control the VESC output current and leave the UART do it instead.
if (ms_without_power > 1000) {
current_mode = false;
}
( all before the reset timeout line )
Beware it is just a guess. I did not try myself.

parasole
Posts: 19
Joined: 29 Mar 2017, 05:18

Re: Dual control

Postby parasole » 14 Sep 2017, 11:47

In my understanding current_mode is reflecting what it is, i.e. current (not voltage) mode of control, while for trhottle I am using DUTY mode, this switch case which describe DUTY mode actions...

Right now my understanding is as following, on DUTY switch case it will check the conditions and then will calculate mc_interface_set_duty which is actual control value, while send_duty just tells to motor control part that value is good to be used. Then changing first IF statment conditions probable is where we should look for, basically inserting a trigger level for next IF and skeeping it if say measured value is at idle... So I need to find out what is fabs and ms_without_power as first point:

if (fabsf(pwr) < 0.001) {
ms_without_power += (1000.0 * (float)sleep_time) / (float)CH_CFG_ST_FREQUENCY;
}



Than there is a place controlling other VESC via CAN, and it will send out only if send_duty is true, i.e. mc_interface_set_duty contains valid value:

// Optionally send the duty cycles to the other ESCs seen on the CAN-bus
if (send_duty && config.multi_esc) {
float duty = mc_interface_get_duty_cycle_now();

for (int i = 0;i < CAN_STATUS_MSGS_TO_STORE;i++) {
can_status_msg *msg = comm_can_get_status_msg_index(i);

if (msg->id >= 0 && UTILS_AGE_S(msg->rx_time) < MAX_CAN_AGE) {
comm_can_set_duty(msg->id, duty);
}
}
}

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

Re: Dual control

Postby pf26 » 14 Sep 2017, 12:31

Most likely you are right.
mc_interface_set_duty( ) is where the duty is sent to the motor control code, and this should be avoided when you don't want it.

I think fabsf() just takes the absolute value of a float. MIN_MS_WITHOUT_POWER is defined to be 500 :
#define MIN_MS_WITHOUT_POWER 500

When config.safe_start is true, the app will wait until the throttle is set to a null position for at least MIN_MS_WITHOUT_POWER. Otherwise it will not send duty cycle requests to the control.
What you want, is that if pwr is still < 0.01 after MIN_MS_WITHOUT_POWER, then mc_interface_set_duty( is not executed either.

parasole
Posts: 19
Joined: 29 Mar 2017, 05:18

Re: Dual control

Postby parasole » 14 Sep 2017, 15:40

Thanks pf26, indeed fabsf is a function for finding out absolute value of float, that I need to do from the begining, just to ask google if it know about it :-)

so then second IF looks to be the place for changes and looks like one more if-else should do the work?

if (!(ms_without_power < MIN_MS_WITHOUT_POWER && config.safe_start))
if (fabsf(pwr) < 0.001) {send_duty = false;}
else
{
mc_interface_set_duty(utils_map(pwr, -1.0, 1.0, -mcconf->l_max_duty, mcconf->l_max_duty));
send_duty = true;
}

parasole
Posts: 19
Joined: 29 Mar 2017, 05:18

Re: Dual control

Postby parasole » 14 Sep 2017, 18:25

The problem is fixed, the solution turn out to be easy by using nested IF statement... By now VESC could be controlled via analog throttle as well via serial.

Thanks rew and pf26 for useful hints which helps me to understand the code, the rest was easier than I expected :-)

case ADC_CTRL_TYPE_DUTY:
case ADC_CTRL_TYPE_DUTY_REV_CENTER:
case ADC_CTRL_TYPE_DUTY_REV_BUTTON:
if (fabsf(pwr) < 0.001) {
ms_without_power += (1000.0 * (float)sleep_time) / (float)CH_CFG_ST_FREQUENCY;
}

if (!(ms_without_power < MIN_MS_WITHOUT_POWER && config.safe_start))
{
if (fabsf(pwr) > 0.001)
{
mc_interface_set_duty(utils_map(pwr, -1.0, 1.0, -mcconf->l_max_duty, mcconf->l_max_duty));
send_duty = true;
}
} else {send_duty = false;}
break;


Return to “General”

Who is online

Users browsing this forum: Bing [Bot] and 2 guests