Timing pulses (0 1) over time

R_Gol's icon

I'm working on a piece that including 6 motors that will have certain sequence:
it could be view as a 3 parts sequence:
sequence 1:
motor 1:
start at min 00: random pulse(ON time of 35 ms) every 7 - 10 sec
motor2:
start at min 01: random pulse(ON time of 35 ms) every 5 - 11 sec
motor3:
start at min 04: random pulse(ON time of 35 ms) every 3 - 13 sec
motor4:
start at min 06: random pulse(ON time of 35 ms) every 7 - 10 sec
motor5:
start at min 08: random pulse(ON time of 35 ms) every 5 - 12 sec
motor6:
start at min 10: random pulse(ON time of 35 ms) every 4 - 10 sec

all motors run for another 10 min

after 10 minutes elapsed of all motors running :

sequence 2:

motor 1:
continue random pulse(ON time of 35 ms) every 5 - 10 sec
stop after 01 min
motor 2: continue random pulse(ON time of 35 ms) every 3 - 12 sec
stop after 04 min
motor 3: continue random pulse(ON time of 35 ms) every 7 - 12 sec
stop after 10 min
motor 4: continue random pulse(ON time of 35 ms) every 3 - 8 sec
stop after 16 min
motor 5: continue random pulse(ON time of 35 ms) every 5 - 16 sec
stop after 18 min
motor 6: continue random pulse(ON time of 35 ms) every 7 - 10 sec

-- now only motor 6 is running >> button pressed>> last motor that running(motor 6) is stops.

sequence 3:

all motors pulsing together every 7 seconds for 2 minutes

after 2 minutes elapsed all motor stops.

how can I implements the above in Max?

Thanks

R_Gol's icon

I was thinking maybe to orgenize sequence data into Coll ?

Max Patch
Copy patch and select New From Clipboard in Max.


edit:
another option I thought is this:

The problem is that is seems to be not so "modular" meaning there is no 1 place I could change all the parameters. also this is only work for sequence 1

Max Patch
Copy patch and select New From Clipboard in Max.

R_Gol's icon

This is were I got so far:
main patch:

How can I pass the data from the Coll object to each associate motor abstraction?
str1 min1 max1 will be pass to my.motor 1 abstraction
str2 min2 max2will be pass to my.motor 2 abstraction
etc etc

Max Patch
Copy patch and select New From Clipboard in Max.


my.motor abstraction:

Max Patch
Copy patch and select New From Clipboard in Max.


Source Audio's icon

you are better off unpacking list in subpatchers.
and remove send and receive objects.
you can also consider using grab ...
or place coll in each abstraction, etc etc
ther are many ways to do this, but that --- #0 etc
is only complicting things.
------
back to orignal question.
I woud write timeline script that contains data for each motor in a sequence, using smallest needed time grain.
for example, you only mention secons, means smallest grain is 1 sec.
write time as index in coll and strings telling each motor what to do at given time
coll line
index = time, motor ID / data it needs;

R_Gol's icon

I woud write timeline script that contains data for each motor in a sequence, using smallest needed time grain.

What do you mean by time line script?

this is where I got so far and things get complicated..

main:

Max Patch
Copy patch and select New From Clipboard in Max.

my.motor:

Max Patch
Copy patch and select New From Clipboard in Max.

Source Audio's icon

time line is simply counter that recalls coll indexes at set time.
if you run it at 1 sec interval,
you can output data at set time, for example:
0, 1 35 7 12;
60, 2 35 5 11;
...
...

at time zero motor 1 starts pulsing 35 ms using random interval betwen 7 and 12 seconds.
at time 60 motor 2 starts pulsing 35 ms using random interval betwen 5 and 11 seconds

and so on.

Source Audio's icon

take a look at this example

Max Patch
Copy patch and select New From Clipboard in Max.

write coll line as described in my last post,
now that you set pulse time gobaly to 35 ms, only motor id
and 2 time values neeed to be in each coll line.

360, 2 3 11; motor 2 starts at time 360 wih time ange 3 to 11

motor id + stop, stops the motor, stops alone stops all motors.

150, 3 stop; stops motor 3 at time 150

200, stop; stops al motors at time 200

R_Gol's icon

thanks! I wonder, how is possible to write the time in minutes and not in seconds? (assuming the patch will timing event in 45 min time frame)
is it possible to write minutes in float? for example: 17.5, 2 5 11; (motor 2 starts at minute 17.5 )

R_Gol's icon

another problem I'm facing is when jumping to difference time in the sequence:

Max Patch
Copy patch and select New From Clipboard in Max.


if I jump to minute 03:30 but I have motors that their timing is at 02:00 minutes - they won't work.

how can it fixed?

another bug I'm facing:
when arriving to time 40 (40 seconds) motor 1 is constantly output 1 and all other motors stop to work

Max Patch
Copy patch and select New From Clipboard in Max.

Source Audio's icon

coll index can only be int or symbol.
minute fraction is not decimal.
17.5 would mean 17 and a half minutes
or 17*60 + 30 seconds , total 1050 seconds.
you have to use that, or use form 00:00:00
as coll index, and also as jump-to location.

example:

00:02:30, 1 5 11;
00:04:00, 1 stop;

if you don't need hours, 00:00 MM:SS is enough.

02:30, 1 5 11;
04:00, 1 stop;
--------


R_Gol's icon

I wrote the Coll like in your example but motor has not start to pulse:

Max Patch
Copy patch and select New From Clipboard in Max.

double_UG's icon

I would use seq~

Max Patch
Copy patch and select New From Clipboard in Max.

Source Audio's icon

oh boy ...
writing to coll makes no sense if counter isn't producing indexes.

Max Patch
Copy patch and select New From Clipboard in Max.


R_Gol's icon

Thanks. but sequence is still stuck after 40 seconds:

only m6 is pulsing. the rest are stuck either at ON or OFF

Max Patch
Copy patch and select New From Clipboard in Max.

edit: I might need updating my Max as I'm not using the last release. maybe it causes bugs .

edit 2: did not help. it still freeze

R_Gol's icon

ok so I deleted the objects inside p 6motors subpatch and put them again and now it seems to run just fine.

the problem is that if I run the sequence to lets say min 2 and all my motors are already needed to be running it won't happen . I think that if I want to jump to different time in sequence I should send into Coll all the elapsed time so it will call the motors.

using uzi make the prgram crash. any other idea?

Max Patch
Copy patch and select New From Clipboard in Max.

Source Audio's icon

the patch you posted had corrupt parts,
which caused max to freeze, because delay time was set to nan.

Something might be wrong in your instalation.

The concept you need to rethink.
What you asked for is now running ok.

I knew that you can't simply rewind.
that is caled event chasing in DAWs, where last valid
automation value is recalled when one jumps, just as if seq was
running all the time.

you can uze uzi,
but only to collect last 6 values till set point, without sending that to motors.
then send the list.


R_Gol's icon

you can uze uzi,
but only to collect last 6 values till set point, without sending that to motors.
then send the list.

How I can implement that? what dos it mean only to collect last 6 values?

R_Gol's icon

I have added a sequence inside Coll that looks like this:

all motors start at once and stops at different time.
why is not working?
is it not possible to have same time for more then 1 motor?

00:00, 1 1 2;
00:00, 2 2 2;
00:00, 3 3 3;
00:00, 4 2 3;
00:00, 5 4 4;
00:00, 6 2 5;
00:05, 1 stop;
00:10, 2 stop;
00:15, 3 stop;
00:20, 4 stop;
00:25, 5 stop;
00:28, 6 stop;

Source Audio's icon

here is all that, I hope that you don't want more changes.
hitting jump number stops motors, runs coll till set time,
and creates list of last motor values.
general stop wipes them of course.

delay time is now clipped to min 100 ms.
it is up t you to fill coll with correct syntax and values.

Max Patch
Copy patch and select New From Clipboard in Max.

R_Gol's icon

thanks for your help!
I'm still have the problem that is not possible to generate more then 1 event at the same time:

this won't work:

00:00, 1 1 2;
00:00, 2 2 2;
00:00, 3 3 3;
00:00, 4 2 3;
00:00, 5 4 4;
00:00, 6 2 5;
00:05, 1 stop;
00:10, 2 stop;
00:15, 3 stop;
00:20, 4 stop;
00:25, 5 stop;
00:28, 6 stop;

Source Audio's icon

you should now that coll allows only one unique index.
P.S:
next time post proper request, you initial 3 sequnce script is
having no trace of more motors per same time, except stop all.
Now you want somthing else ....

simpet fix as is now is to write l motors in same index ine.
That works as long you use 3 values
motor id and 2 values
one can then zl.iter 3 to route motor correctly.
but somthing like
00:56, 1 stop 2 1 15 3 5 11, NOT

other option is to use different moftor ID
like A B C etc

R_Gol's icon

I see.. so I started different approach:

indexes are symbols (m1 m2 m3 etc)

edit:
updated approach:

Max Patch
Copy patch and select New From Clipboard in Max.

Source Audio's icon

I don't undersand what that should bring ?

take this one,
motor index are new A B C D E F

embeded exampe shows it all.

Max Patch
Copy patch and select New From Clipboard in Max.

One thing was not clear, should activation of motor pulses
trigger pulse immediatey, or after 1st delay ?
Look int 6motors patcher, green patch cords do 1st trigger.
but they also trigger after jump....

R_Gol's icon

I don't undersand what that should bring ?

The possibility to trigger more then 1 motor at the same time.
for the moment it seems not possible to pulse few motors at the same time with the same time interval

One thing was not clear, should activation of motor pulses
trigger pulse immediatey, or after 1st delay ?

it should activate immediately

R_Gol's icon

routing is not happening in this scenario

Source Audio's icon

true, I forgot to add splitter at main coll

here is updated one :
values for jump location should execute on next cock

Max Patch
Copy patch and select New From Clipboard in Max.

please downlod this last one

R_Gol's icon

Thank you very much!

Assuming this Coll:
00:00, A 1 1 B 1 1 C 1 1;
00:10, B 1 2;
00:14, C 2 3;
00:16, D 1 4;
00:10, F 1 6;
00:16, A 11 22 B stop C 33 14 D 12 86 E stop F 0 2;
00:22, C stop;
00:48, stop;

when motors pulsing together between 00:00 to 00:10 there is very small delay between the three. Is this can be avoided?

Source Audio's icon

delay could happen only on very first pulse,
because allredy 2nd pulse is randomised delay.
how much delay do you measure ?

P. S. I see hey are all fixed at 1000 ms

I wil check it, maybe it is rndom object tht triggers output and delay time

R_Gol's icon

how much delay do you measure ?

I'm not sure how to measure but I could see it with my eyes so it might be too much for its application needed

Source Audio's icon

The problem is : construction is wrong.
I made this exampes following your initial requst,
1 motor per line, all the time random intervals etc.
this is not working well.

You should list now all that this patch needs to do.
Otherwise I see no sense to continue with this.

R_Gol's icon

You should list now all that this patch needs to do.

I think I described it in my first post in this topic

Source Audio's icon

this is last one for today

Max Patch
Copy patch and select New From Clipboard in Max.

R_Gol's icon

this is just great!! thanks for your time and effort

R_Gol's icon

I have noticed one bug that happens.
with this Coll:

00:00, A 1 1 B 1 1 C 1 1 D 1 1 E 1 1 F 1 1;
00:12, B 1 2;
00:14, C 2 3;
00:16, D 1 4;
00:18, E 1 5 A stop;
00:20, F 1 6 A 0 1;
00:26, A 11 22 B stop C 33 14 D 12 86 E stop F 0 2;
00:32, C stop;
00:48, stop;
00:52, A 0 1 B 0 1 C 0 1 D 1 1 E 2 2 F 2 2;

when time 00:52 is arriving motor F is stuck on ON position although it should pulse in 2 sec intervals

any idea why?

see video attached in link

R_Gol's icon

Ok, I think it happens because the ON time was higher then the minimum pulse interval..

Source Audio's icon

You will probably discover one or the other bug while testing...
This patch was done a bit in a hurry.

here is updated version that handles jumping a bit better

Max Patch
Copy patch and select New From Clipboard in Max.


Source Audio's icon

I finally found a bit time to test this....
This new patch has many changes.
time is limited to 100ms to 60 seconds !
Setting longer pulse sets minimum generated time 20ms longer
than pulse.
Random generator is better, jumping is much more efficient.

Max Patch
Copy patch and select New From Clipboard in Max.

R_Gol's icon

Thanks for your time!!
It is working very good!


time is limited to 100ms to 60 seconds !

What does it means limited to 100ms to 60 seconds?

Source Audio's icon

random generated timer is limited to 100ms - 60 seconds.
means max value you can enter is for example A 1 60.

if pulse length is set to 100ms or more, minimum
generated length will get adjusted to be 20 ms longer than pulse time.

R_Gol's icon
Max Patch
Copy patch and select New From Clipboard in Max.

How can change the above code to control numbers that are less then 1 sec interval.

right now if I'm writing A 1.25 1.25 B 2.35 2.35;

the output pulse of A will be at 1 sec interval while the B pulse will be at 2 sec intervals.

The code don't have resolution of less then 1 sec. milliseconds are ignored.

is this possible to fix?

Thanks

Source Audio's icon

follow where that floats travel, and make sure you don't convert them to ints

ShelLuser's icon

For the record: I only glossed over the whole thing, some things seem a bit trivial to me (no offense), just covering my butt if I missed something ;)

BUT.... if you need more speedy control then I'd say [gen].

So many people talk about gen~ (and rightfully so!) but the thing is... there's also a non-MSP burried counterpart: gen.

And I say burried because if you try to search for Gen on the Max documentation site then you'll get everything but this critter. ... i should report that.

Anyway...

Gen works on samples, not ms. I think that's your solution here.

R_Gol's icon

follow where that floats travel, and make sure you don't convert them to ints

Thanks! I fixed it

R_Gol's icon

I wonder if it possible also to control 4 mini vibration motors that expecting numbers between 0 - 255 in the same coll I use to control the 9 solenoids.

vibration motor one is U

vibration motor two is V

three is W

four is X

is it possible to add multiple data to the coll that will control the vibration motors?

for example:

00:50, U 0 255 5000 255 3000 0 5000, V 255 0 5000 0 3000 255 5000;

motor U start at 0 then go to 255 in 5 sec, stay there for another 5 sec and then go to 0 in 5 sec.

motor V start at 255 then go 0 in 5 sec, stay there for a another 5 sec and then go to 255 in 5 sec.

how this change is possible to make?

Max Patch
Copy patch and select New From Clipboard in Max.

Thanks

R_Gol's icon

is this a valid solution?

Max Patch
Copy patch and select New From Clipboard in Max.

coll inside:

R_Gol's icon

seems fine, but the stop message is not working..

edit:

here is the updated patch to control the mini vibration motors.

how does it looks?

I wonder what will happen if instead of giving 7 variables for the lines object such as this:

0 255 5000 255 3000 0 3000

I will give only 5 variables like this:

0 255 5000 0 3000

how can I adapt the patch to work with unknown numbers of variables?

Max Patch
Copy patch and select New From Clipboard in Max.

R_Gol's icon

updated 2: varibale list

Max Patch
Copy patch and select New From Clipboard in Max.

R_Gol's icon

last update:

I try to add another system for the mini vibration motors called "rand" with 5 variables. total time work in sec min and max metro time to toggle between and min max time for values for the motors.

it looks like this:

U rand 10 500 1500 50 255;

metro should work for total time of 10 sec, bang evry 500 - 1500 ms and output new value on each bang between 50 and 255.

it is working but the stop function got messed up. Any idea how I should fix it?

Max Patch
Copy patch and select New From Clipboard in Max.

Main:

Max Patch
Copy patch and select New From Clipboard in Max.

Source Audio's icon

that subpatch is chaotic. stop message ???

how should it work ?

when you create such constructs,

first define ALL messages that need to be passed to control

ALL metros, gates, lines etc.

What do you use routepass stop rand for ?

is there "stop gently" message in use ?

or "random a bit" ?

.........

You added stuff to probably working rest, but messed all up,

because the rest now also does not receive values correctly.

Compare that subpatcher UnlisterX.

Upper one is your last patch

lower one is your patch posted on May 12 2024

What changed in routing of coll lines in the meantime ?

R_Gol's icon

[//deleted post//]

R_Gol's icon

[//deleted post//]

R_Gol's icon

[//deleted post//]

Source Audio's icon

what should that patch mean ?

What do you input into it, from where and in what form ?

sprintf is totally wrong, router is nothing

R_Gol's icon

[patch in post deleted]

I will try to explain again in detailed as possible.

Here is the main patch:

inside this main patch I made sub patch called: p MiniVibrationMotors - (marked in green):

and inside this sub patch there is another subpatch called: p mini vibration motors control -

the last subpatch should have two different type of control:

1) regular control in which I enter different value to control line object. for example:

00:20, U 0 255 5000 255 5000 0 4000;

meaning -control line object as follow: start from 0, go to 255 in 5 sec, stay at255 for another 5 sec then go to 0 in 4 sec.

2) random-ish control that should pass 5 arrguments:

a) total time of action in sec

b) min value of metro in ms

c) max value of metro in ms

d) min value of random number

E) max value of random number

is should looks like that:

00:30, U rand 10 500 1500 50 255;

so at sequence time 00:30 a new bang should be output between 500 to 1500 ms to produce random value between 50 to 255. when those 10 sec elapsed this should stop.

the message stop should effect the above as well - meaning to stop any action that is running.

also - if control system 1 is working then control system 2 should not and the other way around.

I hope this make sense.

I will be happy to explain further if needed

Source Audio's icon

I need to know if you are going to place all sorts of messages into same coll line.

for example :

00:30, A 2 5 B stop C 1 11 U rand 10 500 1500 50 255 W 0 255 5000 255 5000 0 4000 ;

and how do you want to do this :

"also - if control system 1 is working then control system 2 should not and the other way around."

Source Audio's icon

Please delete all that wrong patches from the posts now.

I will use ONLY one uploaded Jul 22 2024 | 9:53 am

and try to fix it

R_Gol's icon

I need to know if you are going to place all sorts of messages into same coll line.

for example :

00:30, A 2 5 B stop C 1 11 U rand 10 500 1500 50 255 W 0 255 5000 255 5000 0 4000 ;

Yes

and how do you want to do this :

"also - if control system 1 is working then control system 2 should not and the other way around."

maybe a gate that will block any data from system 2 if system 1 is working ( for the same motor - U V W etc) ? and vice versa

Please delete all that wrong patches from the posts now.

I will use ONLY one uploaded Jul 22 2024 | 9:53 am

and try to fix it

Will do it now

Source Audio's icon

I am sorry , maybe I misunderstood this

and how do you want to do this :

"also - if control system 1 is working then control system 2 should not and the other way around."

I though that you want either motors A B C D ... or UVW at same time.

I think you want to use either random or line based for U V W.

That is anyway a must.

if either kind receives a message it will stop and init the other.

Parameter

a) total time of action in sec

is absolute length to run random kind.

if it is set to 10 seconds, it will STOP no matter what other values are set to.

I have only one last question:

do stop messages allways set output to zero ?

end of line and random output stays at last value.

R_Gol's icon

I think you want to use either random or line based for U V W.

True.

if it is set to 10 seconds, it will STOP no matter what other values are set to.

ok, make sense

do stop messages allways set output to zero ?

Yes.

Source Audio's icon

here is a patch for you to test

Max Patch
Copy patch and select New From Clipboard in Max.

I have replaced many objects, including that random range patcher.

expr does it much simpler.

R_Gol's icon

here is a patch for you to test

looks great!

I just wonder if it possible to reset the rand control system to 0 when finished if a specific message is apply. for example:

U rand rst 5 500 1500 50 255;

will reset the above to 0 when finished the 5 second frame.

and this won't:

U rand 5 500 1500 50 255;

Edit:

regardless to my above wish addition - your patch is working just great!!

Source Audio's icon

Ok I could add that.

I looked elswhere in your main patch.

there are soooo many things that could be more efficient, for example what is this good for :

P.S

now that your lines in coll could get quite long,

one should make that unlister patcher a bit snappier.

Max Patch
Copy patch and select New From Clipboard in Max.

you can replace old one with this new one.

R_Gol's icon

is those error message should be look into or I can ignore them?

there are soooo many things that could be more efficient, for example what is this good for :

the right hand side is to avoid first bang. the left hand side probably some old system that is not in use.

Source Audio's icon

I have no errors at all.

which objects are producing them?

you doubleclick at one error line, it will show the object-

What is that unused matrix 9 doing in there ?

and why this :

maybe that is why you have to "avoid first bang " ???

R_Gol's icon

What is that unused matrix 9 doing in there ?

probably I forgot to delete it. It was used in previous versions.

here is my main patch without the unused matrix updated to your last patch:

Max Patch
Copy patch and select New From Clipboard in Max.

Source Audio's icon

I see now that you can scroll in time and get all previous values for motors A B ...

ready to execute on next metro start.

But how is that going to work with new motors which have line and random timers

and ramps ?

they can not mimick as if they were running for nn time ???

R_Gol's icon

But how is that going to work with new motors which have line and random timers

and ramps ?

they can not mimick as if they were running for nn time ???

This is true. Is there a way to make it work? In anyway this is not a big of a deal if not possible..

R_Gol's icon

how this is possible to make from couple of posts above:

"I just wonder if it possible to reset the rand control system to 0 when finished if a specific message is apply. for example:

U rand rst 5 500 1500 50 255;

will reset the above to 0 when finished the 5 second frame.

and this won't:

U rand 5 500 1500 50 255;"

Source Audio's icon

in patcher multiline you have only 6 of 9 motors getting into temp coll ?

Fogot to update that ?

R_Gol's icon

mine looks fine:

Max Patch
Copy patch and select New From Clipboard in Max.

Source Audio's icon

I will post fixes soon.

You can forget that with jump location and new little motors.

They have no timeline but run ramps or random ramps

when executed.

For that reason one should exclude them from

jumper , or execute their last vlue, just as for other motors.

It is your decision.

In the mean time I have that rst thing done.

But I won't send anything till this patch gets cleaned completely.

Also that seq stuff needs to go, unless you explain what you are after

Source Audio's icon

I have to see about that jump from location problem with 9 motors.

When you set time to start, all values per motor get played back very fast

into temp buffer which keeps last received values for each motor.

If next line does not have anything for a motor, there are no double triggers,

but if it does , then there is a conflict.

I must see how to override temp values for motors that do have something in next line from jump location.

Source Audio's icon

here is last patch today.

*** removed ***

Problem with jump and repeated values is solved.

First values allways come from temp buffer.

4 additional motors execute last temp values just as other motors do.

You have to live with that for the time being.

Do you need to send linefeed to arduino ?

R_Gol's icon

Thank you very much!!!

Do you need to send linefeed to arduino ?

I'm not sure what is linefeed?

Source Audio's icon

ASCII 10 to set new line.

Some data parsing needs that in arduino code, some not ...

R_Gol's icon

The way it is set as now is just perfect! thank you for all the time!

Source Audio's icon

here is patch with fixed vib-motors.

There were leftovers from your patch inside which I simpy overlooked.

Max Patch
Copy patch and select New From Clipboard in Max.

I removed previous patch.

I will have another look at it all when I get time.

It was done in a short time and there could be other issues left to fix.