Control VESC Spindle Over CAN Bus
-
So VESC brushless motor controllers support CAN BUS. How hard would it be to get the Duet 3 talking to one? The CAN BUS commands are defined here:
-
I'd start by checking if the VESC controller is okay with CAN-FD or not, quick google didn't bear fruits.
-
@CthulhuLabs said in Control VESC Spindle Over CAN Bus:
VESC brushless motor controller
If the hardware in https://vesc-project.com/node/311 documentation VESC_6_plus.pdf page 2 is used, it uses a STM32F40x MCU, which is CAN based, not CAN-FD. So this would be not sufficient IMHO. An overview which STM32 support CAN-FD is available in https://www.st.com/resource/en/application_note/dm00625700-fdcan-peripheral-on-stm32-devices-stmicroelectronics.pdf
i.e. STM32G0, G4, H7 and L5 series. -
It would have to be connected to the secondary CAN bus on the motherboard, because the primary one uses CAN-FD. Then the UAVCAN stack would have to be ported to RepRapFirmware, and finally code to send the required commands for the VESC. Quite a lot of work.
-
Sounds like less work to rig an esp32 (with CAN controller) and a transceiver in between the UART of the Duet and the VESC? (or one of the forementioned STMs - but the ESPs are more widely used with respect to community support methinks)
The firmware would probably benefit from supporting that to facilitate modbus towards highend VDFs as well.
-
Sounds like it would be easier to use the UART control:
http://vedder.se/2015/10/communicating-with-the-vesc-using-uart/
-
@dc42 At this point I am looking for a way to implement precise speed control of the VESC with existing code in RRF (version 2 or 3). I would rather not reinvent the wheel if something already exists to make this happen. I am thinking of building a conversion board that can take whatever command / data the Duet can send to it and converts it to a UART command to the VESC. The only way I have thought about doing this at this point is to setup this board to pole the Duet via M408 commands over the PanelDue's UART port and look for the spindles active RPM in the return. The obvious issue with this is that it is not a realtime option. If it is not poling the Duet at a high enough refresh rate it could potentially run the tool into the work at the wrong RPM (most likely 0). I do not know how likely this is to happen though.
-
Here's another possibility. We have an implementation of Duet 3 expansion board firmware for the SammyC21 development board (https://www.chip45.com/products/sammy-c21-1.0_atmel_smart_arm_sam_module_board_samc21_usb_dual_two_can.php). You could take that firmware and add the UAVCAN stack to it using the second CAN port. So the module would be a bridge between RRF CAN-FD protocol and VESC over UAVCAN. With luck you may even find an existing port of UAVCAN for the SAMC21.
Another possibility might be to use a polling approach and UART, but instead of polling the Duet, use the daemon.g task to watch for changes to the spindle speed in the object model, and send UART messages to the VESC.
Yet another possibility is to use an Arduino Pro Micro or similar as a PWM-to-UART converter; i.e. monitor the spindle PWM output of the Duet and convert it to VESC commands. This is probably the simplest solution.
-
What I currently have setup is taking a PWM output from the controller (have not converted to the Duet yet), passing that through a RC circuit, and passing the resulting voltage to the VESC's ADC input. This works, but the speed is never right where I want it to be and it does not react that fast to RPM changes (probably need to better tune the RC circuit for the application).
The idea of using a PWM-to-UART has crossed my mind, and I suppose I could make an editable map of specific PWM duty cycles to specific RPMs. This would provide accurate speed control and work across multiple different. I could also have other pins on the board that output things like motor temp and controller temp using a DAC to emulate a thermistor as well as a fault pin that could be hooked up to an endstop to emulate an E-Stop. Could also output a tach pulse to provide RPM feed back that could be read with one of the 4 pin fan headers I suppose.
I did check the code and it looks like currentRPM and configuredRPM are always kept the same. Is there plans to add feed back on this and possibly auto adjust?
-
@CthulhuLabs said in Control VESC Spindle Over CAN Bus:
What I currently have setup is taking a PWM output from the controller (have not converted to the Duet yet), passing that through a RC circuit, and passing the resulting voltage to the VESC's ADC input. This works, but the speed is never right where I want it to be and it does not react that fast to RPM changes (probably need to better tune the RC circuit for the application).
With RRF you can set the PWM frequency up to 65535Hz, allowing you to use a small RC time constant for fast response. Even better, use an op amp to implement a 2nd (or higher) order filter.
The usual way to drive a VFD from a Duet or other electronics seems to be to use a converter such as this https://www.amazon.co.uk/1-3KHZ-Voltage-Module-Digital-Converter/dp/B0789738RC.
-
I recently put together a workbee CNC with a duet and a brushless spindle paired with a vesc ESC. This thread came up when I searched for vesc and duet spindle control.
I found the vesc "servo" input is really a regular pwm input. It is not particularly picky about pwm frequency either. So hooking up a duet pwm output to the vesc servo input works fine.It works pretty well and the vesc has its own PID loop to hold speed steady.
-
@district9prawn said in Control VESC Spindle Over CAN Bus:
It works pretty well and the vesc has its own PID loop to hold speed steady.
thats awesome! what kind of granuarilty / linearity do you get from the 0-100% on the duet mapped to rpm (if you know)?
edit: gotcha, shows I've never tried
M453
. So it takes care of mapping PWM duty cycle to RPM and as you indicate below VESC tracks is pretty well. Cool, thanks! -
The control is quite fine. Increasing or decreasing rpm by 10 with M3 shows the change. In practice there is much more error than that during cutting. More like +- 50 rpm. The torque/phase current control is nice. I can physically jam the spindle and the current through the windings will simply be whatever I set as maximum motor current. I imagine that abuse would fry the included ESC in seconds.