Using a MCP260A, using pin3 (+5V) through two NO switches (left/right) and back to Pins 6/13 (DIN1 & 2). DIN 1 and 2 are set to Analog. Using the script, I've set the max signal limit appropriately to trigger as needed on switch contact. Current script is simply:
SIGNALMAXACTION(0)=0x0010 ;M1 Reverse
SIGNALMAXACTION(1)=0x0004 ;M1 RLimit
The goal: (see sketch) To have the rope guide move left/right along a worm screw across the front of the drum to lay down the rope cleanly. This will be started/stopped by an external python script that will command the turning speed of both the drum motor and the guide motor. For the python script, commanding 'Forward' will take the rope 'off' the drum, commanding 'Backward' will lay the rope 'onto' the drum. Thus, when the guide (as in the sketch) is laying rope onto the drum (in python 'Backward' command state) and moving left and hits the left limit switch, it will immediately start moving right at the same speed without having to communicate with the python script. As it finishes the second layer and hits the right limit switch, it will immediately switch back to leftward motion. At any point the python script may stop the motion and command 'Forward'. In this case, the motor should start moving in the opposite direction it just was (regardless of whether that is left/right).
Also, the MCP script can't talk back to the python program (it might not always be there). Thus, if I have to 'stop' the motor to reset the 'reverse' status, the speed it was traveling at will be lost (so to speak). These basically have to work independently of each other, software-wise.
It ALMOST works. All switches, motors, everything physical works and tests great. By setting the right limit switch to "M1Reverse" and setting the left limit switch to "M1ReverseLimit" (this has different names in different places in the manual by the way, may want to fix that), the "Forward" python command works. Default is Forward = right motion, hits the right switch, flips to 'reverse', moves left, hits the left switch (ReverseLimit) and trips back into normal forward motion (i.e. rightward). However, it doesn't fully work with "Backward" python commands. In this case, the 'reverse' switch still works, but now the ReverseLimit doesn't apply the correct limit (which makes total sense). If I then change the pin from ReverseLimit to ForwardLimit, the "Backward" motion works totally and the "Forward" motion is broken in the same way (again, totally makes sense).
What I'm trying:
there is a 'reverse' 'undo' command that I can assign to the DIN pin (can't find, pretty sure it doesn't exist)
There is a 'reverse' flag/variable I can tie to a signal input in the script and have it flip as needed. So far I can't find this if it exists. I can tie a reverse to a SIGNALMAXACTION, but there is no corresponding 'undo' or other command other than the Forward/Backward Limit that undoes the reverse. There also doesn't seem to be any system variable that holds the 'reverse' state that I can write to. I can query the current state with MOTORFLAGS, but it's read only.
Likely solution (given my current knowledge):
Script the pins such that they change their SIGNALMAXACTION depending on whether we're in "Forward" motion or "Backward" motion. I assume I can get the "Forward/Backward" state off of MOTORSPEED and then just flip the switch actions as needed. I'm thinking the script would look something like:
if motorspeed(0) = positive ;i.e. "Forward"
set right switch to M1Reverse
set left switch to M1ReverseLimit
else ;i.e. 'Backward'
set right switch to M1ForwardLimit
set left switch to M1Reverse
pause 10 ;maybe more if needed, but something pretty short
Anyway, long explanation for what I hope is a simple answer. In short, is there a system variable that can WRITE the Motor 1 reverse state? If not, is my 'likely solution' a good path or do you have another recommendation?
Thanks for the help!