How do I make this reset less.. dumb

It works this way but I don’t like it
It’s a master reset button for 52 motors

I imagine there’s a way to not write “0” and “1” exactly 52 times

And holding the button down doesn’t keep them all in the same state until released.
(Not needed but I’d like to know how to make that happen too)

Values1 = [1]*len(Paths)
Values0 = [0]*len(Paths)
5 Likes
Values1 = [1] * len(Paths)
Values0 = [0] * len(Paths)

edit: lost the race!

4 Likes
  1. Hoping you're using some sort of AOI in the PLC, you could've tied them all to one master reset button in the PLC.
  2. It looks like many of your paths are the same, just incrementing a number

This is what I'd do:

resets = [

	('[default]MPH/34CL/34_CL{}/Fan_Motor/Reset',	16	),
	('[default]MPH/FR/FR{}/Fan_Motor/Reset',		8	),
	('[default]MPH/FDC/FDC{}/Fan_Motor/Reset',		3	),
	('[default]MPH/45CL/45_CL{}/Fan_Motor/Reset',	3	),
	('[default]MPH/34RD/34_RD{}/Fan_Motor/Reset',	6	),
	('[default]MPH/55CL/55_CL{}/Fan_Motor/Reset',	6	),
	('[default]MPH/55RD/55_RD{}/Fan_Motor/Reset',	2	),
	('[default]MPH/34SD/34_SD{}/Fan_Motor/Reset',	8	),

]

paths = [

	path.format(x) for (path,count) in resets for x in range(1, count +1)

]

system.tag.writeBlocking(paths, [1 for path in paths])
system.tag.writeBlocking(paths, [0 for path in paths])
6 Likes

Nicely done.

If you need the ranges configuration to be more flexible, you can change the end bound to anything that will produce the right numbers: list, generator, function...
So you can change things easily when one of them needs an offset, or needs to skip some numbers.
ie:

resets = [
	('[default]MPH/34CL/34_CL{}/Fan_Motor/Reset',	xrange(1, 17)),
	('[default]MPH/FR/FR{}/Fan_Motor/Reset',		(1, 3, 6, 7, 8)),
	('[default]MPH/FDC/FDC{}/Fan_Motor/Reset',		get_FDC_indices()),
	('[default]MPH/45CL/45_CL{}/Fan_Motor/Reset',	xrange(2, 8, 2)),
	...
]

paths = [path.format(x) for (path, indices) in resets for x in indices)]

Offers a lot of flexibility. Which may not be required in your case, so don't make it more complicated than it needs to be, but keep in mind it's a possibility,

7 Likes