Undo a Motor "reverse"

General discussion of the MCP motion controller product line
bgantner
Posts: 4
Joined: Fri Oct 27, 2017 11:36 am

Undo a Motor "reverse"

Postby bgantner » Thu Nov 16, 2017 1:35 pm

I'm trying to create a motorized guide that lays rope onto a rotating drum, moving left/right so that the rope goes on cleanly without getting tangled. I've got two limit switches, one at each end of the range of motion. It seems pretty straightforward to set one of the switches to 'reverse' the motor direction and that works great. However, I can't figure out a way to 'undo' that reverse with the other switch without bringing the motor to a stop and then re-commanding the motion. Is there a easy way to undo that reverse without stopping?
Thanks.

User avatar
Basicmicro Support
Posts: 1135
Joined: Thu Feb 26, 2015 9:45 pm

Re: Undo a Motor "reverse"

Postby Basicmicro Support » Fri Nov 17, 2017 9:49 am

Please describe how oyu have it settup in Ion Studio pin settings and how you have your limit switches setup electrically/physically.

What exactly do you want to do(in total) with this? I have a feeling this will be easier using a simple script.

What model MCP are you using?

bgantner
Posts: 4
Joined: Fri Oct 27, 2017 11:36 am

Re: Undo a Motor "reverse"

Postby bgantner » Fri Nov 17, 2017 1:12 pm

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:

SIGNALMAX(0)=1500
SIGNALMAX(1)=1500
SIGNALMAXACTION(0)=0x0010 ;M1 Reverse
SIGNALMAXACTION(1)=0x0004 ;M1 RLimit

rough_sketch.jpg
rough_sketch.jpg (164.17 KiB) Viewed 2385 times


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.

Current status:
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:
Easiest solution:
there is a 'reverse' 'undo' command that I can assign to the DIN pin (can't find, pretty sure it doesn't exist)

Next easiest:
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:

main
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
goto main

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!

bgantner
Posts: 4
Joined: Fri Oct 27, 2017 11:36 am

Re: Undo a Motor "reverse"

Postby bgantner » Mon Nov 27, 2017 12:31 pm

So I found a solution. It is basically the third option from my previous list. I'll post it in case it helps someone in the future.

SIGNALMAX(0)=1500
SIGNALMAX(1)=1500

main

if MOTORPWM >= 0 then
if MOTORFLAGS(0) & 0x0002 then
;moving forward, but reversed, so command is 'backward'
SIGNALMAXACTION(0)=0x0004
SIGNALMAXACTION(1)=0x0008
puts 0,["Pos/Rev:", sdec MOTORPWM(0),13]
else
;moving forward and not reversed so command is 'forward'
SIGNALMAXACTION(0)=0x0010
SIGNALMAXACTION(1)=0x0004
puts 0,["Pos/Norm:", sdec MOTORPWM(0),13]
endif
else
if MOTORFLAGS(0) & 0x0002 then
;moving backward, but reversed, so command is 'forward'
SIGNALMAXACTION(0)=0x0010
SIGNALMAXACTION(1)=0x0004
puts 0,["Neg/Rev:", sdec MOTORPWM(0),13]
else
;moving backward and not reversed so command is 'backward'
SIGNALMAXACTION(0)=0x0004
SIGNALMAXACTION(1)=0x0008
puts 0,["Neg/Norm:", sdec MOTORPWM(0),13]
endif
endif
pause 1000
goto main


So it turns out that MOTORSPEED doesn't work in this case (not sure why exactly). But MOTORPWM gives the direction of motion and then when checked against the 'reverse' state, we can tell which way it was actually commanded and, thus, set the limits correctly.


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest

cron