Paciente8159 / uCNC

µCNC - Universal CNC firmware for microcontrollers
https://github.com/Paciente8159/uCNC/wiki
GNU General Public License v3.0
265 stars 60 forks source link

[FR] Default servo position #667

Closed ademenev closed 5 months ago

ademenev commented 5 months ago

Is it possible to set the default position for a servo (ideally, separately for each configured servo)?

I have a pen plotter where zero servo position corresponds to lowered pen, so the pen is dropped each time the machine is powered on. In my particular case, I can redesign and rebuild the pen drive unit so that the servo turns in opposite direction, but that is not always possible, and I feel like the start position should be configurable.

Paciente8159 commented 5 months ago

Hum... I see.

No currently there is not a way to configure that. That is one to add to the bucket list for sure. Currently the best place for you to place that is to place it after cnc_init() call in the ino file.

But if you need to re-run that code at every main loop reset then adding a listener to the cnc_reset event is the best bet. There are some examples on how to do that in the modules git.

Paciente8159 commented 5 months ago

I was starting to implement something for this but I just realized that there maybe a better solution already at hand.

If this is to control a servo that is part of a tool you could add this to the tool startup code. Each tool as a startup and a shutdown function that runs on every tool loading/changing.

This might be the best place for you to place the code.

Never the less I'm adding a custom code entry point to set IO state on reset. I'm thinking of implementing tools loading and unloading macros soon.. so stay tuned

Paciente8159 commented 5 months ago

669 should allow you to customize the IO values at power up easily. just need to declare the mcu_io_reset anywhere function with your custom pin states.

void mcu_io_reset(){
  // set to SERVO0 to the opposite position
  mcu_set_pwm(SERVO0, 255);
}

mcu_io_reset can also be declared as a macro in your boardmap override file like this.

#define mcu_io_reset() ({mcu_set_pwm(SERVO0, 255);})
ademenev commented 5 months ago

Thank you!

Ironically, my local store is selling defective servos, and after 3 of them burnt, literally, with red glow and smoke, I redesigned my machine to use a stepper instead of servo :)