Hello - I have the TIC 36v4 stepper drivers. I really like the interface, but I’m having some issues:
- The stepper seems to default moving in the NEGATIVE direction, see below… why?
- How do I get the stepper to move to a position, and stop?
- When I explicitly set a negative/positive velocity, does this instigate the “Invert Motor Direction” in the EEPROM, or no? (If the latter, that is excellent, since I can move the motor back and forth without burning out the EEPROM with write/rewrite cycles!)
First, my code, I’m using Python
import time
from datetime import datetime
import subprocess
import yaml #needed for tic
from pprint import pprint #for pretty printing of dictionaries
#NOTE: The following addresses can be found using the Tic software
#from Pololu
periPumpAddress = "00413599"
def interpreter(command):
total_command = "ticcmd -d " + periPumpAddress + " " + command
proc = subprocess.Popen(total_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
out, err = proc.communicate()
return out, err #might need to just "return" with nothing here
def resetTIC():
currCommand = "--reset"
returnedVal = interpreter(currCommand)
print("resetTIC Returned val is: {}".format(returnedVal))
print("resetTIC Type of returned Val is: {}".format(type(returnedVal)))
return
def getCurrTICPosition():
#status = yaml.safe_load(ticcmd('-s', '--full'))
currCommand = "-s --full"
returnedVal = interpreter(currCommand)
status = yaml.safe_load(returnedVal[0])
currentPosition = status['Current position']
return currentPosition
def moveTICToPreDefinedPosition(targetPosition = 2000):
#reset to position = 0
resetTIC()
currPosition = getCurrTICPosition()
print("After reset, position is: {}".format(currPosition))
targetPositionAsStr = str(targetPosition)
currCommand = "--resume --position" + " " + targetPositionAsStr
dummy = input("current position desired is: {} ... hit enter to proceed".format(targetPositionAsStr))
interpreter("--energize")
currPos = int(getCurrTICPosition())
time.sleep(0.1)
interpreter(currCommand)
while currPosition < targetPosition:
time.sleep(0.5) #just to avoid spamming the USB port
currPosition = getCurrTICPosition()
print("Current position is now: {}".format(currPosition))
interpreter("--deenergize")
return
############################################################################################
#
# Testing code
#
#
############################################################################################
moveTICToPreDefinedPosition()
The output I get here is:
resetTIC Returned val is: (b’', None)
resetTIC Type of returned Val is: <class ‘tuple’>
After reset, position is: 0
current position desired is: 2000 … hit enter to proceed
Current position is now: -63
Current position is now: -131
Current position is now: -200
Current position is now: -267
Current position is now: -332
Current position is now: -398
Current position is now: -465
Current position is now: -534
Current position is now: -601
Current position is now: -671
Current position is now: -738
Current position is now: -804
Current position is now: -873
So question 1) Why is it going in the negative direction, by default?
I can, of course, enforce the direction - let’s say I modify the above code changing this:
currCommand = "--resume --position" + " " + targetPositionAsStr
To this:
currCommand = "--resume --velocity 3000000 --position" + " " + targetPositionAsStr
Now I get the output:
resetTIC Type of returned Val is: <class ‘tuple’>
After reset, position is: 0
current position desired is: 2000 … hit enter to proceed
Current position is now: 188
Current position is now: 396
Current position is now: 598
Current position is now: 820
Current position is now: 1032
Current position is now: 1238
Current position is now: 1440
Current position is now: 1648
Current position is now: 1856
Current position is now: 2056
As you can see, I go past the setpoint! Only because of my Python code (while loop) does the pump stop - otherwise it keeps running! For example, if I set the sleep time to like 2 seconds, I will go wildly past the position setpoint. So, question 2 - why?
[I’ll note - while this *works* it’s not good for my application, where I can’t necessarily rely on my Python code to precisely move a stepper to a setpoint - I want to set it and let the TIC software go to where it needs to go.]
One more note - I can use the TIC Control Center software to set a position, but again, it will not stop once it reaches this position.
Finally, question 3), as we saw above, I can set a negative or positive velocity. Is this doing the “invert motor direction” in the EEPROM, or does it avoid the write/rewrite?