You are here

Removing low speed openloop FOC parking brake mode from FW

5 posts / 0 new
Last post
rodread
rodread's picture
Offline
Last seen: 10 months 1 week ago
Joined: 2018-01-12 11:08
Posts: 12
Removing low speed openloop FOC parking brake mode from FW

I'm using the VESC 6.0HW in FOC with brake current control commands from an arduino over UART.

I want the Motor (Generator in this case) to always be allowed to run in FOC regen without locking up at slow speeds. (This locking feature I realise is really useful to boarders in traffic)

I want to be able to set brake current dependent on speed for my first few regen tests.

With more speed I should ask the VESC to apply more brake current. At slow rotor- generator speeds I should ask VESC to stop braking.

With NOOB level arduino skills, I coded a very simple command to write the brake current. (Like 1 command level skills - I know - poor)

When the motor slows, firmware activates the (think it's openloop braking FOC)

I guess addressing this in arduino code is best ... e.g. always reading speed from VESC and requesting appropriate Brake current ...

However Being a NOOB I've tried to wade right in on the Firmware instead. After building the FW, the changes I made don't seem to have had any effect. Here's what I tried...

in mcpwm_foc.h Commented out
//void mcpwm_foc_set_openloop(float current, float rpm);
 

in mcpwm_foc.c Commented out
/**
 * Produce an openloop rotating current.
 *
 * @param current
 * The current to use.
 *
 * @param rpm
 * The RPM to use.
 */
/*void mcpwm_foc_set_openloop(float current, float rpm) {
    if (fabsf(current) < m_conf->cc_min_current) {
        m_control_mode = CONTROL_MODE_NONE;
        m_state = MC_STATE_OFF;
        stop_pwm_hw();
        return;
    }

    utils_truncate_number(&current, -m_conf->l_current_max, m_conf->l_current_max);

    m_control_mode = CONTROL_MODE_OPENLOOP;
    m_iq_set = current;
    m_openloop_speed = rpm * ((2.0 * M_PI) / 60.0);

    if (m_state != MC_STATE_RUNNING) {
        m_state = MC_STATE_RUNNING;
    }
}
*/

in terminal.c commented                 //mcpwm_foc_set_openloop(current, erpm);

So I made and uploaded this firmware, and those changes didn't seem to make any difference. NOOB.

So my question is ... Either How should I go about adjusting the FW to stop the low speed braking?

Or Can you recommend... Which is the easiest to unpick and understand arduino code for UART control?

Could VESC-Tool have an option to remove slow speed handbrake?

 

I'm really grateful for all the work and comments which went in.

Is there an overview description of the purpose of each fw file anywhere? File descriptor comments in each header might stop NOOBS like me being such a pest. Did take me ages to troll through all the fw and arduino code. still unsure what I'm looking at half the time.

Thank you for your patience

rod

rodread
rodread's picture
Offline
Last seen: 10 months 1 week ago
Joined: 2018-01-12 11:08
Posts: 12

Cool!, OK, I sorted my problems in using Arduino. I did a bit more digging in the firmware. but still no change.

So I modified the following by Tobias Sachs. Thanks all!! It works a charm. Can't wait to test it outside.

Must get some data logging done next (and my speed data isn't right I'm sure. but it works) (Already recording speed from a separate torque sensor.)

/*
  Copyright 2016 Tobias Sachs Tobias.Sachs@onlinehome.de

  This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/*
 created by:  Tobias Sachs messed with by ROD READ for kite controller
 Name:      VescUartControlSample.ino  Rodino-readConfig_readMeasurements_1VESC.ino
 Created:   22/09/2016  09/03/2018
 Author:    TS
*/

//rod is trying to get a generator to vary torque with speed. Speed up makes torque go up.
//but dependent on a variable setting.
//also generator has to turn torque off at low end speed.

//You have to configure the VESC to APP "UART" and set the baudrate to 256800 the baud rate is hard coded for now in the VescUartControl.cpp
// Rod didn't he changed VescUartControl.cpp value
//You have to uncommend the line "#define USE_PATCHED_VESC_FW_2_18" in the file VescUartControl.h
// I got rid of the getLimits parts

#include "VescUartControl.h"

VescController Vesc1;

struct bldcMeasure measuredVESC1;

uint16_t counts = 0;

int sensorPin = A0;    // select the input pin for the potentiometer
int sensorValue = 0;  // variable to store the value coming from the sensor
float analogBrakeMultiplier; // mapped float from the pot int

#define DEBUG
unsigned long count;
float turnrate ;
//float current ;
//float voltage;
//int power;
float brakeCurrent;

void setup()
{
  Serial.begin(115200); //begin Serial Console
  delay(600);

  Serial.println("setup begin VESC1");
  Vesc1.begin(&Serial1);
  Vesc1.UartSetCurrent(0.0);
  Vesc1.UartSetCurrentBrake(0.0);
  delay(200);
  Serial.println("setup ready VESC1");

   
  delay(200);
  Serial.println("setup ready");
  delay(400);
}

void loop()
{
   // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  analogBrakeMultiplier = (sensorValue / 20000.0); //analogBrakeMultiplier will be used to set brake current below here
  if (Vesc1.UartGetValue(measuredVESC1))
  {
    turnrate = (measuredVESC1.rpm / 560000); //20khz x 14 pairs
    //Serial.print("tempPcb_VESC1: "); Serial.println(measuredVESC1.tempPcb);
    //Serial.print("avgMotCur_VESC1: "); Serial.println(measuredVESC1.avgMotorCurrent);
    //Serial.print("avgInpCur_VESC1: "); Serial.println(measuredVESC1.avgInputCurrent);
    //Serial.print("dutyCycleNow_VESC1: "); Serial.println(measuredVESC1.dutyCycleNow);
    Serial.print("erpm_VESC1: "); Serial.print(measuredVESC1.rpm);Serial.print("   ");
    Serial.print(sensorValue);Serial.print("V");
    Serial.print("   rpm = ");Serial.print(turnrate);Serial.print("   ");
    Serial.print(brakeCurrent);Serial.println("A braking");
    //Serial.print("inVolt_VESC1: "); Serial.println(measuredVESC1.inpVoltage);
    //Serial.print("ampHour-_VESC1: "); Serial.println(measuredVESC1.ampHours);
    //Serial.print("ampHour+_VESC1: "); Serial.println(measuredVESC1.ampHoursCharged);
    //Serial.print("tacho_VESC1: "); Serial.println(measuredVESC1.tachometer);
    //Serial.print("tachoAbs_VESC1: "); Serial.println(measuredVESC1.tachometerAbs);
  }
  else
  {
    Serial.println("Failed to get data from VESC1!");
  }
  if (turnrate > 100)
  {
    
brakeCurrent = (analogBrakeMultiplier * turnrate);

//VescUartSetCurrentBrake(brakeCurrent);

      Vesc1.UartSetCurrentBrake(brakeCurrent);
  }
  else
  {
      Vesc1.UartSetCurrentBrake(0.0);
      brakeCurrent = 0.0;
  }

  
  /*

Serial.println("end");
while(1);*/
}

 

The kite turbine builder

powerlabor001
Offline
Last seen: 1 month 2 weeks ago
VESC Free
Joined: 2017-09-07 19:56
Posts: 9

interesting,great progress,i also have a project just like this.

rodread
rodread's picture
Offline
Last seen: 10 months 1 week ago
Joined: 2018-01-12 11:08
Posts: 12

Wee update, it works like a charm. Lovin the VESC6. Some vids of it generating via kite turbine on https://www.youtube.com/user/roddyread/videos

The kite turbine builder

arvidb
Offline
Last seen: 3 years 7 months ago
Joined: 2018-01-16 23:09
Posts: 77

Very cool, I've never seen a kite turbine before! Thanks for the link!