Speed controller macro
-
Hello,
for the application described in this other topic I am trying to implement a simple speed controlled extruder using a Duet3.What I tried to do, is to use a trigger (Extruder On command) to start a macro, and an analog input to set the desired extruder speed (as 0..100% of the G0/1 speed)
; config.g ... ... M308 S3 P"io3.in" Y"linear-analog" ; in3 is the speed ref M950 J1 C"!io2.in" ; in1 is the start command M581 T2 P1 S1 R0 ; trigger 2 on in1-> trigger2.g M571 P"io4.out" S1 ; out4 is feedback "On"
The macro would continuosly execute small steps as long as the On Command is there, and between each step recalculate the speed and distance;
;trigger2.g var REFSPEED=60 ;reference speed in mm/min var iterTime=1 ;iteration time in s var actSpeed=0 ;calculated speed for this move in mm/min var actDist=0 ;calculated distance for this move inmm while sensors.gpIn[1].value = 1 echo "speed scaling in % =", sensors.analog[3].lastReading set var.actSpeed = var.REFSPEED * sensors.analog[3].lastReading /100 echo "speed in mm/min =", var.actSpeed ;TODO: check the min-max limits set var.actDist = var.iterTime * var.actSpeed / 60 echo "distance in mm =", var.actDist G1 F{var.actSpeed} E{var.actDist} ;end loop
It works for 5-6 rounds, but then the system hangs with the status "busy" and I have to reset the board.
Thanks for your help!
-
@giuliano
At the very least I think you need an M400 after each of your G1 calls.
Otherwise, the commands will be queuing at whatever the cycle time of the while loop is.
You might also want to add a global variable to ensure that the trigger can't activate again whilst it's already running.Both these scenarios could lead to the system locking up I imagine.
-
@owend Thanks for your reply. I tried the M400 and also a G4 1000. But the result is the same, somehow the G1 instruction hangs up..
When it hangs up, the extruder motor is still energized, but it doesn't move anymore. The system status is "busy", and no other G-Codes are accepted.
Any idea what could be the reason?
-
Here is the report using M122 while the system is stuck..
8/16/2022, 9:50:35 PM M122 === Diagnostics === RepRapFirmware for Duet 3 MB6HC version 3.4.2rc1+ (2022-08-14 11:05:55) running on Duet 3 MB6HC v1.01 or later (standalone mode) Board ID: 08DJM-956BA-NA3TJ-6JKDL-3S86K-9T92T Used output buffers: 4 of 40 (20 max) === RTOS === Static ram: 151000 Dynamic ram: 96152 of which 0 recycled Never used RAM 100520, free system stack 192 words Tasks: NETWORK(ready,26.8%,209) ETHERNET(notifyWait,0.1%,173) HEAT(notifyWait,0.0%,321) Move(notifyWait,0.0%,265) CanReceiv(notifyWait,0.0%,943) CanSender(notifyWait,0.0%,335) CanClock(delaying,0.0%,334) TMC(notifyWait,7.6%,92) MAIN(running,65.4%,1083) IDLE(ready,0.1%,30), total 100.0% Owned mutexes: === Platform === Last reset 00:03:24 ago, cause: reset button Last software reset at 2022-08-16 21:24, reason: User, GCodes spinning, available RAM 100592, slot 2 Software reset code 0x0003 HFSR 0x00000000 CFSR 0x00000000 ICSR 0x0044a000 BFAR 0x00000000 SP 0x00000000 Task MAIN Freestk 0 n/a Error status: 0x00 Aux0 errors 0,0,0 Step timer max interval 130 MCU temperature: min 38.5, current 41.3, max 41.4 Supply voltage: min 15.2, current 15.3, max 15.3, under voltage events: 0, over voltage events: 0, power good: yes 12V rail voltage: min 12.2, current 12.3, max 12.3, under voltage events: 0 Heap OK, handles allocated/used 99/4, heap memory allocated/used/recyclable 2048/142/96, gc cycles 0 Events: 0 queued, 0 completed Driver 0: standstill, SG min 0, mspos 88, reads 30169, writes 17 timeouts 0 Driver 1: standstill, SG min 0, mspos 88, reads 30169, writes 17 timeouts 0 Driver 2: standstill, SG min 0, mspos 8, reads 30173, writes 14 timeouts 0 Driver 3: standstill, SG min 0, mspos 8, reads 30176, writes 11 timeouts 0 Driver 4: standstill, SG min 0, mspos 8, reads 30176, writes 11 timeouts 0 Driver 5: standstill, SG min 0, mspos 872, reads 30170, writes 17 timeouts 0 Date/time: 2022-08-16 21:50:35 Slowest loop: 9.24ms; fastest: 0.05ms === Storage === Free file entries: 9 SD card 0 detected, interface speed: 25.0MBytes/sec SD card longest read time 3.2ms, write time 0.0ms, max retries 0 === Move === DMs created 125, segments created 6, maxWait 199371ms, bed compensation in use: none, comp offset 0.000 === MainDDARing === Scheduled moves 2, completed 0, hiccups 0, stepErrors 0, LaErrors 0, Underruns [0, 0, 0], CDDA state 4 === AuxDDARing === Scheduled moves 0, completed 0, hiccups 0, stepErrors 0, LaErrors 0, Underruns [0, 0, 0], CDDA state -1 === Heat === Bed heaters 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1, chamber heaters -1 -1 -1 -1, ordering errs 0 Heater 0 is on, I-accum = 0.0 === GCodes === Segments left: 0 Movement lock held by Trigger HTTP is idle in state(s) 0 Telnet is idle in state(s) 0 File is idle in state(s) 0 USB is idle in state(s) 0 Aux is idle in state(s) 0 Trigger is doing "M400" in state(s) 0 0, running macro Queue is idle in state(s) 0 LCD is idle in state(s) 0 SBC is idle in state(s) 0 Daemon is idle in state(s) 0 Aux2 is idle in state(s) 0 Autopause is idle in state(s) 0 Code queue is empty === CAN === Messages queued 1839, received 0, lost 0, boc 0 Longest wait 0ms for reply type 0, peak Tx sync delay 0, free buffers 50 (min 50), ts 1023/0/0 Tx timeouts 0,0,1022,0,0,815 last cancelled message type 30 dest 127 === Network === Slowest loop: 16.75ms; fastest: 0.02ms Responder states: HTTP(0) HTTP(0) HTTP(0) HTTP(0) HTTP(0) HTTP(0) FTP(0) Telnet(0), 0 sessions Telnet(0), 0 sessions HTTP sessions: 1 of 8 - Ethernet - State: active Error counts: 0 0 1 0 0 Socket states: 5 2 2 2 2 0 0 2
-
@giuliano
I don't really know how to interpret that report except it shows the trigger is activeMy guess is that the trigger is being activated multiple times by switch bouncing or similar.
You might need some denouncing code at the start like
G4 P20 ; short delay if sensors.gpIn[1].value = 0 ; bouncing M99 ; exit macro
You might also create a global variable in config.g like
global macroRunning= false
At the start of your trigger file put
if global.macroRunning = true M99 set global.macroRunning = true ; do your other stuff set global.macroRunning = false ; last line