limit switch not responding

Supporting Visual Studio on Windows
meister
Phidgetsian
Posts: 10
Joined: Wed Jan 23, 2013 2:22 pm
Contact:

limit switch not responding

Postby meister » Wed Jan 23, 2013 2:33 pm

i am trying to write a homing script for a 3308 stepper on a 1063 driver board, plus 1018 IO board.

i have limit switches at each end of the travel, and i'm trying to drive to each end and record the position. Does anyone have any suggestions for an algorithm, because as soon as i start a loop to keep driving the motor on, iteratively, both the IO board and digital inputs on the driver board, stop responding to changes in the switch value. :cry:

User avatar
burley
Human-Cyborg Relations
Posts: 441
Joined: Tue Sep 27, 2011 2:37 pm
Location: Calgary
Contact:

Re: limit switch not responding

Postby burley » Thu Jan 24, 2013 8:49 am

Why do you need to move the motor in a loop? Just set the position to some arbitrarily large number and forget about it. The motor will move and you can worry about other things in the mean time.
Brian Burley
403-282-7335 ext. 6003
support@phidgets.com

meister
Phidgetsian
Posts: 10
Joined: Wed Jan 23, 2013 2:22 pm
Contact:

Re: limit switch not responding

Postby meister » Thu Jan 24, 2013 9:41 am

Fair point. I can do that, but the digital inputs arent triggering the change event. So i send the motor off and it reaches the end stop and grinds away until it reaches the .targetposition value.

private void btHome_Click(object sender, EventArgs e)
{
// stepperShort.steppers[0].CurrentPosition = 0;
//stepperLong.steppers[0].CurrentPosition = 0;

stepperShort.steppers[0].TargetPosition = SHORTMIN;
while (stepperShort.steppers[0].CurrentPosition != SHORTMIN)
{
tbShortPosAct.Text = Convert.ToString(stepperShort.steppers[0].CurrentPosition);
}
}

void stepperShort_InputChange(object sender, InputChangeEventArgs e)
{
((CheckBox)shortInputsGrp.Controls["shortInput" + e.Index.ToString() + "Chk"]).Checked = e.Value;

stepperShort.steppers[0].Engaged = false;
//'if it's the near limit that closed, stop the motor and set position at 0
if (e.Index == LSWFRONTCLOSED && e.Value == true)
{
//stepperShort.steppers[0].Engaged = false;
stepperShort.steppers[0].CurrentPosition = 0;
tbShortPosTar.Text = "0";
tbShortPosAct.Text = "0";
stepperShort.steppers[0].TargetPosition = 0;
tbShortFront.Text = "0";
}
//if it's far limit that closed, stop the motor and set the farLimit global variable
if (e.Index == LSWBACKCLOSED && e.Value == true)
{
// stepperShort.steppers[0].Engaged = false;
stepperShort.steppers[0].TargetPosition = stepperShort.steppers[0].CurrentPosition;
tbShortPosTar.Text = Convert.ToString(stepperShort.steppers[0].CurrentPosition);
tbShortPosAct.Text = Convert.ToString(stepperShort.steppers[0].CurrentPosition);
tbShortBack.Text = Convert.ToString(stepperShort.steppers[0].CurrentPosition);
}
stepperShort.steppers[0].Engaged = true;
}

User avatar
Patrick
Lead Developer
Posts: 3119
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: limit switch not responding

Postby Patrick » Thu Jan 24, 2013 9:53 am

You shouldn't block in a button handler like that - that could be blocking the other events from firing.

Can you confirm that the end stops produce events when the motor isn't moving? Is everything wired properly?

-Patrick

meister
Phidgetsian
Posts: 10
Joined: Wed Jan 23, 2013 2:22 pm
Contact:

Re: limit switch not responding

Postby meister » Thu Jan 24, 2013 10:12 am

Hi Patrick,

digitalinput event handler works fine in standalone, but when i try to reference the input value ie:

If (input2Chk.Checked = True) ...

or use the input event handler to kill the stepper, nothing happens.

Not sure i follow your button blocking comment?

Cheers

User avatar
burley
Human-Cyborg Relations
Posts: 441
Joined: Tue Sep 27, 2011 2:37 pm
Location: Calgary
Contact:

Re: limit switch not responding

Postby burley » Thu Jan 24, 2013 10:17 am

What he means is that the while loop in your button click handler could potentially run for a long time. Since the event handler is active for as long as the loop is running the rest of your program will be blocked from executing while the processor is stuck in the event handler. New events will fail to be handled etc...

It is good practice to call a separate function or thread in the event handler to deal with the actual code while minimizing the runtime in the handler.
Brian Burley
403-282-7335 ext. 6003
support@phidgets.com

User avatar
Patrick
Lead Developer
Posts: 3119
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: limit switch not responding

Postby Patrick » Thu Jan 24, 2013 1:14 pm

Rather then polling the state of a checkbox on your GUI, you should poll the actual input state of the digital input from the phidget object.

Blocking your GUI thread like that is always a bad idea. Like Brian said, you should just set the position to a high value and then exit from the button change event. If you need to do something long-running, start a separate thread to handle it.

-Patrick


Return to “C#.NET”

Who is online

Users browsing this forum: No registered users and 0 guests