(re)Set Position

Hi I am using a T825 controlled by an Arduino Uno. I am using the setup to drive an auxiliary axis on a CNC machine so I need the motor to drive exactly 1000 steps when signaled from the arduino, wait for another signal, advance 1000 steps, and again and again and again (18 times).

I am trying to use the following:

tic.setTargetPosition(1000); //drive the motor 1000 steps
waitForPosition(1000); //wait for the position
tic.haltAndSetPosition(0); //reset the current position to 0 steps so that I can tell the tic to move to the target position of 1000 steps the next time the controller is signaled to do so.

My problem is that the haltAndSetPosition(0) is not resetting the tic position.I can watch the tic via USB and the current position never resets.

Anybody know what I am doing wrong?

Hello.

I tried reproducing the bug you are describing, but I was unable to do so. Can you post the simplest complete Arduino sketch that demonstrates the problem? Also, could you post your Tic settings file? You can save your settings file by selecting the “Save settings file…” option within the “File” drop-down menu of the Tic Control Center software while the Tic is connected.

Brandon

1 Like

Hi Brandon thank for the reply! My code is below.

#include <Tic.h>
#ifdef SERIAL_PORT_HARDWARE_OPEN
#define ticSerial SERIAL_PORT_HARDWARE_OPEN
#endif

TicSerial tic(Serial);

// constants won't change. They're used here to set pin numbers:
const int PulsePin = 7;     // the number of the Pulse pin

// variables will change:
int PulseState = 0;         // variable for reading the Pulse status

void setup() {
  Serial.begin(9600);
  delay(20);
  tic.exitSafeStart();
  pinMode(PulsePin, INPUT);
}
void resetCommandTimeout()
{
  tic.resetCommandTimeout();
}
void delayWhileResettingCommandTimeout(uint32_t ms)
{
  uint32_t start = millis();
  do
  {
    resetCommandTimeout();
  } while ((uint32_t)(millis() - start) <= ms);

}
void waitForPosition(int32_t targetPosition)
{
  do
  {
    resetCommandTimeout();
  } while (tic.getCurrentPosition() != targetPosition);
}

void loop() {
  tic.haltAndSetPosition(0);

  PulseState = digitalRead(PulsePin);

  if (PulseState == HIGH) {
    tic.setTargetPosition(1000);
    waitForPosition(1000);
    tic.haltAndSetPosition(0);
  }
}

I am not at the machine shop where the tic is right now so I do not have the tic file for you at the moment.

I just thought that I did not have the Tic’s TX line connected to my Arduino’s RX line. Is the Tic not resetting my 1000 steps because the Arduino is never getting the information that it has reached 1000 steps? Therefor not proceeding to the “tic.haltAndSetPosition(0);”

Thanks again!

A missing connection from the Tic’s TX line back to the Arduino’s RX line could certainly cause that problem. Your program might be hanging at the waitForPosition(1000); command if you do not have that connection.

Brandon

It was absolutely hanging on the waitForPosition(1000); command. Worked perfectly after getting that added. Thank you Brandon for the help!

1 Like