Servo motor control error

Hello,

I'm brand new to the world of Arduino. I have robotics project where I need to send a signal from the robot controller's digital i/o to a Teknic servo motor. The motor requires a short pulse on the enable input to rotate, which I'm trying to set up at the moment. The current code I wrote continually pulses the motor, bypassing the digital read command on the input which should trigger the pulse. At this point I'm completely lost as to how to make it work. Any advice would be greatly appreciated.

Code and wiring diagram below

Thanks!
Mike

const int Enable = 6; // ClearPath ~enable input; +enable = BLU wire; -enable = ORN wire
const int InputA = 8; // ClearPath Input A; +InputA = WHT wire; -InputA is BRN wire
const int InputB = 9; // ClearPath Input B; +InputB = BLK wire; -InputB = YEL wire
const int triggerInput = 12;





void setup()
{ // put your setup code here, to run once:

  pinMode(Enable, OUTPUT);
  pinMode(InputA, OUTPUT);
  pinMode(InputB, OUTPUT);
  pinMode(triggerInput, INPUT);
  // start off by ensuring thet the motor is disabled before proceeding
  digitalWrite(Enable, LOW);
  delay(10);

  // set the two outputs to their initial states
  digitalWrite(InputA, LOW);
  digitalWrite(InputB, LOW);
  delay(10);

  digitalWrite(Enable, HIGH);
  delay(15);


}
// end of setup code

// put your main code here, to loops indefinitely:
void loop() {

  if (digitalRead(triggerInput) == HIGH) {
    digitalWrite(Enable, LOW);
    delay(15);
    digitalWrite(Enable, HIGH);
    delay(5000);
    digitalWrite(Enable, LOW);



  }

}
// end of main code, will loop indefinitely

We need more information on the hardware.

We really need a proper schematic (hand drawn is fine).

How is the servo powered ?

Do you know how to use Serial.print for debugging? Code does not bypass things it runs things exactly as coded. Stick a serial print after your if to print the digitalread. Is your logic inverted? Maybe you should change the HIGH to LOW?

I would use serial in any event and maybe put one before the if to see if you get any low readings

there are several types of motors

  • a DC motor where with a driver card can be controlled in speed using a PWM signal and direction
  • a stepper motor which commonly has 4 or 6 pins with a polarity applied across pairs of wires in a sequence which steps the motor in either direction
  • an RC servo motor which has 3 pin: power, ground and signal. the signal is a 1-2 msec pulse that causes the motor to rotate to a position dictated by the width of the pulse

your drawing is unclear.

there are only 2 leads from your controller. may make sense if it is simply a single switch

your motor has just 2 leads. but if it's a DC motor, it's unlikely it can be driven by just a digital output which can only provide ~40 ma

could you provide part/model #s for your motor and controller?

gcjr

here's the link:
motor info

The motor is powered by it own 24v supply. its connects with an 8pin molex connector, but I'm only using the enable pins at the moment as that is sufficient for testing, hence the 2 leads from the robot controller. The motor itself has a built in controller that is set to to rotate in precise increments based base on which input is triggered and is configured to accept a pulse between 10-20 ms.

I'm not familiar with serial.print for debugging but I'll look into that now.

momentary switches are typically connected between the pin and ground, and the pin configured for INPUT_PULLUP to use an internal pullup resistor that pulls the pin HIGH. pressing the switch grounds the pin, pulling it low

instead of of doing

if (digitalRead(triggerInput) == HIGH)

try

if (digitalRead(triggerInput) == LOW)

and configure the pin as

  pinMode(triggerInput, INPUT_PULLUP);

when the switch is press, you code generates a active HIGH pulse for 15 msec and then waits 5 sec. may be better to just wait 500 msec

but i'm still a confused about the motor. how far, angle, is it configured to rotate with each pulse?

I can definitely provide a more detailed schematic. I just need to know what additional info you require in that regard.

All of it

I'm not using a switch to trigger the motor, its a signal coming from the the digital output of the robot controller. Would the above code still apply? When the enable pin is pulsed the motor is set to rotate a turntable 10 degrees, which equates just of 4000 counts in the motor.

+1.

@mikeydubs642 what is the nature of the signal from the grey box robot controller? What is the robot controller able to say about what the motor should do?

Why is the Arduino the middle?

It would be nice to read what I assume is the copious and thorough user manual for your motors, but I'm not going to become a potential customer of Yeknik in order to take a peak.

For all I know, that spendy motor is controlled by a serial protocol, or each of the wires invokes or receives commands from the alleged four ways to make it do something…

Oh wait,

Now there's something I can waste spend some time on.

But waddabout the robot controller?

a7

looks like your code is conditionally generating a pulse when it sees the triggerInput is HIGH

i assumed this is an input from your controller

@mikeydubs642 OK, you needa say exactly how you have configured the motor for stand-alone operation using the three inputs.

And what you expect to be able to tell the motor to do.

a7

The robot controller is simply passing a 5V signal to the arduino from one of it's digital outputs. The robot program is running via roboDK which controls both a UR10 and UR5 robot. The native output of the digital i/o on the robot controller is 24V but has been stepped down with a buck converter and the lower voltage has been confirmed with a multimeter. For whatever reason I couldn't get RoboDK to pulse the motor consistently so it only works 90ish percent of the time which brings us to the Arduino. The motor itself has 3 inputs and 1 output. the inputs are Enable, InputA and InputB. The output is called an HLFB, or high-level-feeback, which can send a signal back indicating that the motor has completed its rotation. Currently, the motor is configured to rotate a turntable 10 degrees, when the enable input is pulsed and inputA and B read 0, absent an A & B signal produces the same result. Combinations of A&B on/off tell the motor to rotate in smaller or bigger increments, but the pulsed enable input is always required.

Thats what I'm trying to make it do. but as it is right now it, it rotates regardless if the triggerInput reads high or not with the code I provided.

What does serial debug say?

That's something right out of the "I never would have thought of that" book.

There are many ways get from 24 volt logic signals to 5 volt logic signals.

Try a voltage divider or an opto-isolator.

Your loop() creates a 15 ms low going pulse every 5015 ms.

Or is that a 5000 ms high going pulse every 5015 ms?

Is that what you want?

    digitalWrite(Enable, HIGH);
    delay(5000);

    digitalWrite(Enable, LOW);
    delay(15);

    digitalWrite(Enable, HIGH);
    delay(5000);

    digitalWrite(Enable, LOW);
    delay(15);

    digitalWrite(Enable, HIGH);
    delay(5000);

a7

as i explained, the pin needs to be configured with a pullup and check for LOW not HIGH

It should be configured for the low signal to pulse off for 15ms. Once the motor sees the signal is cut and engages in the set time, it begins to rotate.

Damnit Jim, I'm a photographer, not an electronics wiz! or even someone remotely close to that :laughing:

I'll try that config when I have a chance. I appreciate your help.