You are here

Using a VESC V4.12 for a machining lathe

20 posts / 0 new
Last post
Krampas
Offline
Last seen: 4 years 9 months ago
Joined: 2019-05-17 17:38
Posts: 3
Using a VESC V4.12 for a machining lathe

Hey there,

I'm currently trying to replace my old brushed dc motor with a sensored 6374 motor.

So far so good. I'm learning a lot. Now a have some questions:

  1. Which mode would be best for constant rpm?
    1. > right now I'm using FOC mode. Works pretty well, but is there any better?
  2. Is there a difference between 24V and 30V in torque?
    1. I'm using a really nice Siemens 24V/40A power supply, which could als operate at about 30V
  3. How do I realize a reverse button?
    1. Using a potentiometer on ADC, Ground and 3.3V which works great. Where would I wire the reverse button in?
  4. If I want constant RPM which mode for ADC would I choose? Current, duty cycle, PID? (I have a sensored motor, if that makes a difference)

I hope you can help me with some of these questions.

 

Additional information:

  • VESC V4.12 with current Firmware (can't acces the ESC right now)
  • Siemens 24V/40A power supply 
  • sensored 6374 motor
     

Greetings,

Stefan

district9prawn
Offline
Last seen: 2 years 2 weeks ago
Joined: 2018-04-26 12:18
Posts: 123

1. Your choice of commutation mode is either bldc (trapezoidal) or foc. Both will work, foc is a bit quieter under load. 

2. At higher voltage you will be able to make useful torque over a wider rpm range. At very low speeds the torque will be limited by your configured motor current limits. 

3. Rx and tx can be used for cruise control and reverse. If these are already in use the servo pin can be used. Some firmware changes might be needed though. 

4. Duty cycle or pid speed will work. In current mode the speed will vary wildly depending on load so not ideal for machining. In duty cycle mode the vesc will try to use regenerative braking to slow the motor down if the commanded duty is lower than current duty. Since you are on a psu I would set braking current to zero. And to be on the safe side I would also set max voltage limits so that the vesc will shut off all the gates if it does somehow try to rectify pulses to the power supply. 

TechAUmNu
Offline
Last seen: 3 months 1 week ago
Joined: 2017-09-22 01:27
Posts: 575

As a side note on using a power supply. I would never set the braking current to 0 as this can cause runaway motors. I have had it happen a few times with very heavy spinning things and you don't want it to happen that's for sure. I normally keep the max brake and regen currents around -2A if I am using a power supply. 

Krampas
Offline
Last seen: 4 years 9 months ago
Joined: 2019-05-17 17:38
Posts: 3

1. Will there be a problem with foc in this use case? I've read some confusing stuff about foc.

3. How do I connect it? RX /TX to ground or to 3.3v? And where do I configure it? 

4. I have to be honest, I don't understand the brake and regen currents right now. Wouldn't a regen current  of -2A mean, that there is power fed back into the power supply? (because the VESC wanted to charge the battery?) Could this damage the power supply?

 

district9prawn
Offline
Last seen: 2 years 2 weeks ago
Joined: 2018-04-26 12:18
Posts: 123

FOC should be fine since you are on 24-30v and absolute max is 60v. 

You want the button shorting rx or tx to ground since the pin has a pullup. To configure I think you need to select a control mode with no uart. So for your case you want to set control mode to adc, not adc and uart. Another option for configuring reverse is to set 0 rpm to the centre of the pot with 0 and 3.3v giving full speed in opposite directions. 

Yes regen is energy from motor to supply. Regen is like a boost converter so potentially your supply could see voltages above what it can provide. Remember neither the vesc nor the supply can store the energy of your rotating motor and lathe.

 

Krampas
Offline
Last seen: 4 years 9 months ago
Joined: 2019-05-17 17:38
Posts: 3

Regen is like a boost converter so potentially your supply could see voltages above what it can provide. Remember neither the vesc nor the supply can store the energy of your rotating motor and lathe

Would this normally damage the vesc or power supply? There are buffer modules for these kind of power supply, but I think they compensate for short power loss. 

So -2A brake and regen current is wrong when using a power supply? My inital though was to just limit everything going back in the direction to the power supply at 0V, 0A, 0 Everything.

district9prawn
Offline
Last seen: 2 years 2 weeks ago
Joined: 2018-04-26 12:18
Posts: 123

Nothing wrong with setting -2A brake current provided you select a control mode that does not allow for braking in the first place. Speed PID is a good choice since there an option under pid speed to disable regen braking.

In any case, a controller fault can still cause a bit of unexpected regen. The output capacitance on the supply should be enough to prevent damage to the supply in the time it takes the vesc to detect the over voltage conditon and switch off the gates.

stiganielsen
Offline
Last seen: 2 years 2 months ago
Joined: 2017-12-27 23:38
Posts: 5

I have used the Vesc with the internal motor (250W) from a bike hub motor to drive my lathe for a few years. I have programmed an arduino Nano to send the PWM signal to the VESC. The arduino is interfaced using a rotary encoder that also has push-button in-build. The rotary-encoder thus controls the setrpm for the motor, while the push-button instantly sets the setrpm to zero, stopping the lathe rather quickly, for safety and quick operation. 

Addition: I run the motor in 'PID Speed Control' mode which means the current will be controlled actively to achieve the rpm-setpoint, (that means both to forward reverse and stop). The arduino generates a PWM signal which is read by the VESC. This is set up in the APP control, and the PWM limits are detected by the tool, or through the Setup Input Wizard. -real quick, dirty and easy ;) -if you need, I can send the arduino code generating PWM signal in accordance with the input from the rotary encoder button..

hackish
Offline
Last seen: 5 years 2 weeks ago
Joined: 2017-11-05 17:10
Posts: 7

This is an interesting project. I'm not sure what size lathe you have, but I would be concerned about getting enough power to run the spindle. Braking will be important too. I think it might be a bit of a chore to tune the PID, as you may go from heavy load while making a heavy cut to no load as soon as your toolbit runs off the material. I have been working with industrial servos to accomplish this sort of task.

Sparks
Offline
Last seen: 4 years 3 months ago
Joined: 2020-08-22 01:16
Posts: 5

My ShopFox mini-lathe is in the process of being converted from a 190W brushed DC motor to a 6374 190kV brushless 3 phase skateboard motor. At first I did not know FOC about this newfangled motor control having come from RC models, servos and BLDC motors. Then, thanks to a bit of education from Wikipedia and this forum, I was able to extend my experience in the electronics of motor control circuits to understand the basics of field oriented control. I'm no expert, however here's what I have learned from research and observed from bench testing: 

1. For a lathe or milling machine, you want the lowest kV available so as to get the most torque. Most RC hobby motors spin too fast for your basic mini-machine.

2. Testing the 6374 motor with a hobby ESC showed me how loud the screech from the motor could be in comparison. When using a VESC FOC controller, the motor was nearly silent.

3. The torque from the 6374 motor on FOC is astonishing; even at low RPM's it is very difficult to slow the motor under load. 

4. Just for clarity, a 3-phase motor can be reversed simply by interchanging any two of its phases.

Some theory (I think I got this right): the traditional pulse-width-modulation motor power is a scalar voltage applied periodically over time; the FOC provides a vector of voltage (speed) and current (torque) kept in step with the desired RPM. It is quiet because it is not being turned on and off by pulses. 

Now I could use some help with the human interface, please. The skateboard implementation uses regenerative braking (not on my little lathe, please) and speed is controlled by the user's hand as needed (a lathe needs constant speed and my hands a busy elsewhere).

Thus far I have used an RC TX to control the motor as if it were the throttle on an airplane with the VESC getting input from the 'servo' wiring. This will not work on a lathe. Fortunately, there are cheap servo-testers that I can hack to translate the lathe's 'speed' potentiometer into a signal the the VESC understands. Is there a way that a potentiometer might control the VESC directly?

Also the skateboard uses a hand control to slow down or brake (maybe even reverse?) and this is not desired in my case. How does one configure the VESC to be 0 to 100% like a throttle on an airplane?

I plan to use the present 'forward null reverse' switch on the lathe to both change rotation and open the circuit for safety. Having 'reverse' on the same control is not an option.

Any help from this forum would be much appreciated.

Thanks,

Donal

sinned6915
Offline
Last seen: 3 years 11 months ago
Joined: 2020-08-19 00:12
Posts: 3

Donal - 

I am currently trying to implement similar controls to another device. i have pretty much decided to use an arduino and LCD-keypad shield. Its less than $20 in hardware.  it seems like a lot or overkill to add an arduino, but its that or use some other microcontroller. 

stignielson was helpful in answering some questions. i know that he is using an arduino to control the vesc an uses a endless rotary encoder (switch type, not posistion sensing type).  I hope that he will chime in adn explain- I dont want to steal this thunder. 

i am working on gathering my bits bobs, but i think its going to work out and marry properly.  

you can use the rotary encoder to start/stop the motor. you can use the built in push button switch to do something like reverse or jog the spindle X degrees. 

to do all of it 'analog' with discrete devices, i would think that you would need to add a double pole -double throw switch to reverse 2 of the leads to reverse the motor. speed control could be a voltage divider circuit with a potentiemeter to vary the control voltage.

i too am stil trying to understand the braking settings and options. regen braking would not be good with a fixed psu.   

sinneD

Sparks
Offline
Last seen: 4 years 3 months ago
Joined: 2020-08-22 01:16
Posts: 5

Hi! Thanks for the response. My lathe came with a Fwd Off Rev rotary switch that I had planned to use to swap the leads on the 3-phase to the motor. Sad to say, the switch couldn't do the job. So I found a 30A pre-wired DPDT reversing switch for under $20 to replace it. Good suggestion, thanks.

I found the datasheet for the main STS32F401 ARM Cortex m4 on Mouser and it certainly has enough I/O ports to handle the input from the potentiometer--if one wre inclined to play with the firmware, which I'm not qualified to do. Arduino seems like a good choice and the programming is easy. Plus, it won't put the VESC at risk.

Everything I know about lathes tells me that a little braking is a good idea, particularly if the chuck is massive enough to want to coast when the power is turned off (not a problem with my 80mm chuck) Resist the temptation to stop it 'by hand' if I can. Maybe a -2A brake would be good.

I have a 24V 50A marine battery charger that I rescued from a dumpster (true, and it works fine) to run the lathe. It should be able to handle applied voltage on the output (by design) as that is normal for a charger. A standard PSU, probably not, unless it is designed to sink current as well as source.

My next project is to replace the brushed 775 DC motor on my CNC router (just a little one) with a brushless 3-phase from Amazon. Very high RPM possible, however time will tell if that is a good idea. I'll see how it goes with the lathe conversion before deciding between PWM and FOC for speed control. I don't imagine that an entry-level CNC router will handle feed like a milling machine no matter how much torque the spindle motor offers. So most likely high RPM's and small bites will be the mode.

Cheers,

Donal

Sparks
Offline
Last seen: 4 years 3 months ago
Joined: 2020-08-22 01:16
Posts: 5

UPDATE 

Speed control is possible with ADC using a potentiometer rather than a servo 'tester' as discussed above. 

Sparks
Offline
Last seen: 4 years 3 months ago
Joined: 2020-08-22 01:16
Posts: 5

I had a longer post about the ADC and speed control--it was lost due to 'blacklist'--but the short answer is that the ADC pin, along with its neighbors '- ground' and +3.3V, can be connected to a 10k ohm potentiometer for PID speed control. This is available in the APP wizard as 'E-bike throttle'. Today I'm working on the 'Reverse Button'. 

Cheers,

Donal

Sparks
Offline
Last seen: 4 years 3 months ago
Joined: 2020-08-22 01:16
Posts: 5

In addition to the speed control using a potentiometer (10k ohm) wired to the ADC1, the reverse button is implemented on the black, red, white (BRW) servo wires by shorting B to W for reverse. I use a small (no current flow) DPDT switch to provide FWD, OFF, REV control of the spindle motor.

NB: the "switch the wires" on the motor does NOT work with the DPDT switch described in an earlier post. The VESC does not want to share control and monitors the three phase wires all the time. The control via ADC works very well.

Also, braking is a good idea on a lathe, so I allowed it on the VESC.

I use a 24VDC 'marine battery charger' as a power supply. At low speed (up to about 500RPM on the spindle) the motor runs on about 5A; over that, the VESC control efficiency kicks in and the amps drop to about 2.5A. Both are under no load. Considering the size of the lathe, I doubt that it would be able to draw more than 10A under the kind or work I am doing. The hardest task so far would be threading M10 with a die-holder on the tailstock which I do by hand. 

Cheers,

Donal

Luke264
Offline
Last seen: 1 month 1 week ago
VESC Free
Joined: 2020-09-30 19:46
Posts: 10

I'm really confused. I'm trying to do exactly the same as here!

I want to run somewhere between 5A to 15A, with PID speed control, from 42erpm to 5250erpm, in one direction, no braking.

I have a cheap 5010 360kv motor. 12 stator / 14 magnet poles. I assume 14 is the number I put in the motor poles settings?

The terminal commands "foc_openloop 7 42" through to "foc_openloop 7 5250" seems to have the intended effect for a second, then it stops.

I think the motor wizard works fine. My settings are 7A, 0.1 duty, 150rpm, and I get the same results ~2.4mWb if I do the wizard at lower currents or higher rpms.

The lambda config test starts smoothly. If I add a little resistance, the calculated lambda goes up from 2 to as much as 5 mWb, but then the observer gain just goes to crazy values, from normally 230 to 10000.

However, setting the motor current limits differently seems to effect the duty cycle and rpms considerably, and prevent it from being able to do the low speeds at all.

After the wizard, the motor hardly works at all using the duty cycle button, the current button or the omega/rpm button. It just stutters. I assume my bare motor having little inertia isn't helping.

Using the FOC > Sensorless tab, the Openloop ERPM setting seems to work opposite to how the help suggests - it forces it to run at a limited speed, below the threshold. I can't seem to make it be in openloop mode for 0 to 5250erpm and still respond to the on screen controls.

I'm going through every page of the settings and app settings. It's so fragile, I feel like I'm missing something. I guess the use case of openloop foc mode at a fixed current isn't something many people would want!

Luke264
Offline
Last seen: 1 month 1 week ago
VESC Free
Joined: 2020-09-30 19:46
Posts: 10

I've found a workaround to do a single speed, until I figure out how to get the vesc to do what I need!

I used a serial port sniffer to see that the terminal commands had some extra stuff:

foc_openloop 7 420

is sent as "...foc_openloop 7 420<eol>" or something which in hex is:

02 13 14 66 6F 63 5F 6F 70 65 6E 6C 6F 6F 70 20 37 20 34 32 30 AB 45 03

then using Realterm you can send this on COM port 6 (for me), if you escape the characters and send as ascii:

\x02\x13\x14\x66\x6F\x63\x5F\x6F\x70\x65\x6E\x6C\x6F\x6F\x70\x20\x37\x20\x34\x32\x30\xAB\x45\x03

it works fine in realterm but not in arduino serial monitor.

To send it repeatedly using realterm so that the motor spins continuously, I converted the hex to a binary file, because there's an option to send the binary file every X milliseconds. Google 'hex to binary file' and the first result will help you if you want to recreate this backward method.

I think I'll probably end up writing my own app, but I'm not quite there yet!

Luke264
Offline
Last seen: 1 month 1 week ago
VESC Free
Joined: 2020-09-30 19:46
Posts: 10

I finally found the bug causing all the problems,  The Current Kp and Current KI and Observer Gain in the FOC after detection were just complete garbage.

I've switched to a different motor now, but it's not that different. The values that worked for me were Kp 0.03 and KI 1.0 and observer gain 0.  These are very different to the detected suggested values of Kp 0.09 and KI 358.7 and observer gain 168, which made stuttering and overshoot was enormous, speed and position control did not work at low speed at all. I've fixed that and now speed and position control work from the tool. Awesome!

Just wanted to say thanks for the great tool and project. I'll be upgrading my support and buying directly now I'm confident it works as intended!

MrShocko
Offline
Last seen: 1 year 10 months ago
Joined: 2020-11-25 07:41
Posts: 4

"it works fine in realterm but not in arduino serial monitor."

I have recently worked through this.

You need to assemble a message packet for the UART comms.  

The command you send  is COMM_TERMINAL_CMD = 20  followed by the text  "foc_openloop 7 420" as bytes followed up with checksum and end of message 03.

The UART library for Arduino does the packaging  https://github.com/SolidGeek/VescUart

 

Luke264
Offline
Last seen: 1 month 1 week ago
VESC Free
Joined: 2020-09-30 19:46
Posts: 10

I just updated to VESC Tool 3.0 and Firmware 5.2, re-ran all detection and re-calibrated. It now works much more out of the box with speed and position PID control, and a small hall sensor motor. Well done Ben, and whoever else contributed!