[Grbl_Esp32 Issue#353] Servo – how to set it up

未分类 bolang 4个月前 (10-14) 51次浏览

Issue #353 | 状态: 已关闭 | 作者: dronecz | 创建时间: 2020-03-21


Hi,

I´m playing with servos (normal and continuous ) and I have bit problem with all what I tested. All off them start to move just after I disable alarm so I can move my axis. I followed information in servo part of the wiki, but there is not enough information to solve my issue. Does anybody know how to solve this?

Thanks for your help.


评论 (6)

#1 – bdring 于 2020-03-21

Continuous servos are not supported. Please describe exactly what you want the servos to do and we can help you.

Which axes use servos?
What range do you want to map the servo to?
What do you want it to do when the machine is homed?
how should it behave during an alarm?
How should it behave when the steppers are disabled?


#2 – dronecz 于 2020-03-21

Yes, I thought that, but I was hoping that it will act as normal servo but without min and max position. Maybe I´m wrong, but if can not detect exact position, it can be spin in one direction endlessly. One limitation can be defined map value, but if I will make this value big, I could work in large “area” and it could work. I was hoping that I will test that, but my normal servo behave same as continuous.

> Which axes use servos?

I want use them for A, B and C asix

> What range do you want to map the servo to?

I do not know for now. I want to test some values and see what is possible.

> What do you want it to do when the machine is homed?

It should do nothing. It should work when other axis are at work.

> how should it behave during an alarm?

It should stop.

> How should it behave when the steppers are disabled?

It should be disabled as well.


#3 – bdring 于 2020-03-22

What controller are you using and what hobby servo type?


#4 – dronecz 于 2020-03-22

If you mean what board I´m using than I designed my own board (picture at showcase channel in Slack). U use 5g (HXT500) and 9g (HXT900) servos. Here is my board definiton:


#define CPUMAPNAME "CPUMAPSHAPELIKEMEGA"

// Be sure to change to NAXIS 6 in nutsbolts.h
#ifdef N_AXIS
#undef N_AXIS
#endif
#define N_AXIS 5

// stepper motors
#define USERMTSTEPS

#define XSTEPPIN GPIONUM12
#define XDIRECTIONPIN GPIONUM26

#define YSTEPPIN GPIONUM2
#define YDIRECTIONPIN GPIONUM4

#define ASTEPPIN GPIONUM27
#define ADIRECTIONPIN GPIONUM33

#define ZSTEPPIN GPIONUM14
#define ZDIRECTIONPIN GPIONUM25

//#define BSTEPPIN GPIONUM15
//#define BDIRECTIONPIN GPIONUM32

// C is a servo

// servos
#define USESERVOAXES
// #define SERVOZPIN GPIONUM22
// #define SERVOZCHANNEL_NUM 6
// #define SERVOZRANGE_MIN 0.0
// #define SERVOZRANGE_MAX 10.0
// #define SERVOZHOMINGTYPE SERVOHOMING_TARGET // during homing it will instantly move to a target value
// #define SERVOZHOMEPOS SERVOZRANGEMAX // move to max during homing
// #define SERVOZMPOS false // will not use mpos, uses work coordinates

#define SERVOBPIN GPIONUM15
#define SERVOBCHANNEL_NUM 4
#define SERVOBRANGE_MIN 0.0
#define SERVOBRANGE_MAX 10.0
//#define SERVOBHOMINGTYPE SERVOHOMING_TARGET // during homing it will instantly move to a target value
//#define SERVOBHOMEPOS SERVOBRANGEMAX // move to max during homing
//#define SERVOBMPOS false // will not use mpos, uses work coordinates

// limit switches
#define XLIMITPIN GPIONUM34
#define YLIMITPIN GPIONUM35
#define ZLIMITPIN GPIONUM36
#define ALIMITPIN GPIONUM39
//#define BLIMITPIN GPIONUM
#define LIMIT_MASK B1111

// OK to comment out to use pin for other features
#define STEPPERSDISABLEPIN GPIONUM13

#ifdef HOMINGCYCLE0 // undefine from config.h
#undef HOMINGCYCLE0
#endif
//#define HOMINGCYCLE0 (1<CYCLE0 ((1<AXIS)|(1<AXIS))
//#define HOMINGCYCLE0 ((1<AXIS)|(1<AXIS) |(1<AXIS)|(1<AXIS))

#ifdef HOMINGCYCLE1 // undefine from config.h
#undef HOMINGCYCLE1
#endif
//#define HOMINGCYCLE1 (1<CYCLE1 ((1<AXIS)|(1<AXIS))

#ifdef HOMINGCYCLE2 // undefine from config.h
#undef HOMINGCYCLE2
#endif

#define HOMINGCYCLE2 (1<CYCLE3 // undefine from config.h
#undef HOMINGCYCLE3
#endif
#define HOMINGCYCLE3 (1<STEPPULSE_MICROSECONDS 3
#define DEFAULTSTEPPERIDLELOCKTIME 200 // 200ms

#define DEFAULTSTEPPINGINVERTMASK 0 // uint8t
#define DEFAULTDIRECTIONINVERTMASK 2 // uint8t
#define DEFAULTINVERTST_ENABLE 0 // boolean
#define DEFAULTINVERTLIMIT_PINS 1 // boolean
#define DEFAULTINVERTPROBE_PIN 0 // boolean

#define DEFAULTSTATUSREPORT_MASK 1

#define DEFAULTJUNCTIONDEVIATION 0.01 // mm
#define DEFAULTARCTOLERANCE 0.002 // mm
#define DEFAULTREPORTINCHES 0 // false

#define DEFAULTSOFTLIMIT_ENABLE 0 // false
#define DEFAULTHARDLIMIT_ENABLE 0 // false

#define DEFAULTHOMINGENABLE 1
#define DEFAULTHOMINGDIR_MASK 17
#define DEFAULTHOMINGFEED_RATE 200.0 // mm/min
#define DEFAULTHOMINGSEEK_RATE 2000.0 // mm/min
#define DEFAULTHOMINGDEBOUNCE_DELAY 250 // msec (0-65k)
#define DEFAULTHOMINGPULLOFF 3.0 // mm

#define DEFAULTSPINDLERPM_MAX 1000.0 // rpm
#define DEFAULTSPINDLERPM_MIN 0.0 // rpm

#define DEFAULTLASERMODE 0 // false

#define DEFAULTXSTEPSPERMM 400.0
#define DEFAULTYSTEPSPERMM 400.0
#define DEFAULTZSTEPSPERMM 100.0 // This is percent in servo mode
#define DEFAULTASTEPSPERMM 400.0
#define DEFAULTBSTEPSPERMM 400.0
#define DEFAULTCSTEPSPERMM 100.0 // This is percent in servo mode

#define DEFAULTXMAX_RATE 30000.0 // mm/min
#define DEFAULTYMAX_RATE 30000.0 // mm/min
#define DEFAULTZMAX_RATE 8000.0 // mm/min
#define DEFAULTAMAX_RATE 30000.0 // mm/min
#define DEFAULTBMAX_RATE 30000.0 // mm/min
#define DEFAULTCMAX_RATE 8000.0 // mm/min

#define DEFAULTXACCELERATION (1500.06060) // 106060 mm/min^2 = 10 mm/sec^2
#define DEFAULTYACCELERATION (1500.06060) // 106060 mm/min^2 = 10 mm/sec^2
#define DEFAULTZACCELERATION (100.06060)
#define DEFAULTAACCELERATION (1500.06060) // 106060 mm/min^2 = 10 mm/sec^2
#define DEFAULTBACCELERATION (1500.06060) // 106060 mm/min^2 = 10 mm/sec^2
#define DEFAULTCACCELERATION (100.06060)

#define DEFAULTXMAX_TRAVEL 250.0 // mm NOTE: Must be a positive value.
#define DEFAULTYMAX_TRAVEL 250.0 // mm NOTE: Must be a positive value.
#define DEFAULTZMAX_TRAVEL 100.0 // This is percent in servo mode
#define DEFAULTAMAX_TRAVEL 250.0 // mm NOTE: Must be a positive value.
#define DEFAULTBMAX_TRAVEL 250.0 // mm NOTE: Must be a positive value.
#define DEFAULTCMAX_TRAVEL 100.0 // This is percent in servo mode

#endif

I copied and edited pinout for 6-axis machine (CPUMAPFOO6X). Axis X to Z work OK. I need to mention that I setup my board with dual functionality. This mean that I have some I/O pins acting like A-DIR for example and if this axis is not used, I thought that I could use this pin for servo. Is this OK? I mean, if I do not define it in cpumap.h it should be OK to use I/O pin for something else, right? If I setup my pins for stepper motors, A and B axis works normaly.


#5 – bdring 于 2020-03-22

You should be able to swap between stepper motor and servo features on an I/O pin. It is best to comment out both step and direction when using that axis as a servo.

You might want to use #ifdef’s to define the each mode of the dual modes to prevent mistakes when switching.

We did some major changes today. We no longer use cpumaps and use machine definitions instead. This was done to clean up the code and require less editing by the user. You should create your own megashaped.h file and reference that in machine.h and recompile and upload.

I would start with a definition like this for the servo


#define SERVOBPIN GPIONUM15
#define SERVOBCHANNEL_NUM 4
#define SERVOBRANGE_MIN 0.0
#define SERVOBRANGE_MAX 10.0
#define SERVOBHOMINGTYPE SERVOHOMING_TARGET
#define SERVOBHOMEPOS SERVOBRANGEMAX // move to max during homing
#define SERVOBMPOS false // will not use mpos, uses work coordinates

#define DEFAULTBSTEPSPERMM 100.0 // this is used as a calibration for servos
#define DEFAULTBMAX_TRAVEL 100.0 // this is used as a calibration for servos

for testing….

Turn homing off with $22=0
Disable stepper idle with $1=255
Send $rst=# to remove any work offsets
Restart grbl_esp32 with [ESP444]RESTART

Servo should move to one end of travel.
It should resist manual turning
Send G0B10 It should move to the other end of travel
Send G0B5 It should move to the middle of travel.


#6 – bdring 于 2020-03-24

I made some updates to the firmware and wiki to help with this.

Closing Issue


原始Issue: https://github.com/bdring/Grbl_Esp32/issues/353

喜欢 (0)