using of ringbuffers in servo-thread #475
Because of lag behaviour of an extruder, I'd like to see if putting motion commands in a buffer will buy time to influence the extruder output. So instead of a motion look-ahead (something difficult) i'd like to put a delay between motion pins and the stepgen pins without losing the values. Resulting in delayed joints motion, and an non-delayed extruder motor.
I got this idea from PCW mentioning making a simple HAL component which delays motion for a period of time, like so:
Suppose that this works, to delay with max 0.5 seconds on a servo-thread of 70000 ns I need an array per joint with a size of (0.5s / 70000 ns) = 7143 values. That's not a simple HAL component anymore.
Seeing that there is already a ring buffer component in machinetalk I would be bonkers if I do not try to use something that's almost all I need.
I would initiate/enable it in the following way:
Would you see above way of working with the ringbuffer and its size possible? Or is it better to define an array inside the to-be-written component?
The text was updated successfully, but these errors were encountered:
yeah, why not.
I guess you'd need edge detection on the enable in, then starting a counter on each cycle which clocks in samples
if enable goes negative, you'd continue clocking out samples until the ring is empty
In your case the ring would be internal to the comp I guess
what you want is a 'record mode' ring - the ringbuffer has supports records and carries a size field for each record
for edge detection, see the enable pin and the last_enable tracking variable use in http://git.mah.priv.at/gitweb?p=emc2-dev.git;a=blob;f=src/hal/components/mvjun.comp;h=bf9b6106fbd679abe46a18b4b4e6e3238ce292be;hb=bd873dc4cb3bc4b021a0225aace0d976a23db9e7#l88
note that you can iterate over a buffer's contents even while records are written (the iterator works from a ring snapshot, aka 'generation'), see hal_iter.c/.h - this might be relevant when inspecting the delay line contents
Bas and me have been conspiring for a while on a delayline component which can delay an arbitrary number of float pins for an arbitrary number of periods
it's the first usable "user" application of a HAL ringbuffer, and written such that:
this might evolve into an eventual successor to halsampler/halstreamer
first glimpse of delay in action: http://static.mah.priv.at/public/delayline.jpg
branch https://github.com/mhaberler/machinekit/commits/delayline-cleaned - with educational-level commenting
for an inspector setup you would have something like:
loadrt delayline names=foo delay=500,2500 samples=2 # creates the foo.samples ringbuffer
addf foo.sample servo