Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VESC Spindle via UART #531

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

LukasGossmann
Copy link
Contributor

This PR adds support for connecting a VESC to FluidNC via UART and using it as a spindle.
It also checks for any faults occuring in the motor controller and stops gcode execution + sets an alarm.
VESC can be controlled with 3 modes:

  • Speed: Set the ERPM and VESC will keep it constant with its PID controller
  • Duty: Sets to motor duty cycle. Rough speed control. Speed drops under load.
  • Current: Sets the current through the motor. No speed control! Needs a constant load on the motor otherwise the motor will "run away". More or less constant torque.

https://vesc-project.com/node/1796
https://electric-skateboard.builders/t/vesc-faq-duty-cycle-vs-current-control-ppm-settings/1218

Can be configured as follows (speed mode):

VESC:
  uart:
    txd_pin: gpio.17
    rxd_pin: gpio.4
    rts_pin: gpio.16
    baud: 115200
    mode: 8N1
  tool_num: 0
  spinup_ms: 1000
  spindown_ms: 1000
  speed_map: 0=0% 0=20% 10000=20% 50000=100%
  control_type: Speed

Modes are called like this:

control_type: Speed
control_type: Duty
control_type: Current

@@ -50,35 +51,6 @@ static void _outbytes(uint8_t* buf, size_t len) {
serialPort->write(buf, len);
}

/* CRC16 implementation acording to CCITT standards */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case anyone wonders why i decided to extract this to its own file:
I didn't want to add a redundant implementation for CRC16 if there is already a perfectly working copy available.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of just calling it "crc.cpp", how about identifying the variant, i.e. "crc16_ccitt.cpp"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@bdring
Copy link
Owner

bdring commented Jul 19, 2022

  • You will need to provide an update to the wiki page. You can attach a file(s) in a reply.
  • You need to provide author information per the pull request guidelines.

@@ -129,13 +101,13 @@ static void flushinput(void) {
static bool held = false;
static uint8_t held_packet[1024];
static void flush_packet(size_t packet_len, size_t& total_len) {
if (held) {
// Remove trailing ctrl-z's on the final packet
if (held) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please undo the formatting breakage. Run clang-format on everything that you touch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed now. For some reason the autoformat did that... Had to disable it to be able to save the file without it changing that :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe your autoformat is not using clang-format? If it is using clang-format, then the .clang-format rules in the repo should, in principle, govern the styling.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's what I'm using as visual studio code should pick up on that automatically as far as i can tell. All i did was open the project in visual studio code with platformio and some other add-ons installed. As far as i know i haven't done any other formatting configurations. Maybe one of the add-ons is interfering with that somehow... I need to check that next time.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this will help https://code.visualstudio.com/docs/cpp/cpp-ide . In principle, if you have the C++ extensions enabled, you get clang-format, but maybe you have some other extensions that use a different formatter, or there is some other setting override. Vscode is pretty much infinitely customizable, which means that no two people have a similar experience.

@LukasGossmann
Copy link
Contributor Author

vesc_spindle.md
Here is the documentation for how to use the VESC spindle.
Btw. some of the links in the spindle wiki page to the sections down below aren't working properly.

@bdring
Copy link
Owner

bdring commented Jul 19, 2022

Would it be better to add a poles parameter to the config file, so the firmware and speed_map can use real RPM?

@LukasGossmann
Copy link
Contributor Author

LukasGossmann commented Jul 19, 2022

That would certainly be a possibility however the vesc_tool only shows ERPM too so it would add a point of confusion there instead. Even though their use of ERPM and RPM is a bit inconsistent...
Would renaming the RPM mode to ERPM be an acceptable solution ?

@bdring
Copy link
Owner

bdring commented Jul 19, 2022

Would M3S10000 be referring to ERPM in your case? That seems like a bad idea, especially for use with CAM software that uses real RPM.

@LukasGossmann
Copy link
Contributor Author

Yes that would be ERPM. So i think you are right. Adding that parameter would be safer.
Ill add that tomorrow :)

@bdring
Copy link
Owner

bdring commented Jul 19, 2022

Poles is similar to flutes on a bit. You tell the CAM software about the flutes and it then can work in RPM.

@LukasGossmann
Copy link
Contributor Author

No not really as the number of flutes does not actually affect the rpms of the spindle for the same drive waveform of the motor whereas the number of poles of the brushless motor does.
What you are talking about is the relationship between the chipload, the number of flutes, rpm and feedrate.

@bdring
Copy link
Owner

bdring commented Jul 19, 2022

OK, I guess the rough analogy is lost on you, but we agree on the required changes to the code.

@LukasGossmann
Copy link
Contributor Author

LukasGossmann commented Jul 19, 2022 via email

@LukasGossmann
Copy link
Contributor Author

LukasGossmann commented Jul 20, 2022

Updated documentation:
vesc_spindle.md

@LukasGossmann LukasGossmann marked this pull request as draft July 25, 2022 11:23
@LukasGossmann
Copy link
Contributor Author

Noticed some issues with the queue filling up due to repeated calls to setSpeedfromISR

@LukasGossmann
Copy link
Contributor Author

Added a workaround similar to what is done in VFDSpindle.
Please have a look at this thread on discord as this workaround seems like its the wrong way to do it.
https://discord.com/channels/780079161460916227/1001091533333856357

@LukasGossmann LukasGossmann marked this pull request as ready for review July 30, 2022 09:04
@MitchBradley MitchBradley changed the base branch from Devt to main March 21, 2024 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants