Page 1 of 1

Home routine

Posted: Mon Feb 10, 2020 10:41 am
by Juanjo-Lasing
Hello,

I am doing a home routine for various axis following this code for all them:

Code: Select all

ch4->Dest=104.5;
    	Jog(4,-1);          				// start moving 
	while (ReadBit(1032)) ; 		    // wait for switch (input #16) to change
	Jog(4,1);          				// start moving
	while (!ReadBit(1032)) ;
	Zero(4);  
	MoveAtVel(4,100,10);
	while (!CheckDone(4));
	Zero(4);
As you can see, the axis moves until the bit 1032 is 0, when a sensor detectes the axis. Then, I do a new Jog to the other direction until the sensor stops to be detected, and makes Zero after moving to 100.
The problem we detected is that, when the axis is close to the sensor (but the sensor is not active yet) and I call the home routine, the second Jog is ignored and the first Jog continues the movement until the axis hits its phisical limit. This never occurs when the position of the axis is far enough from the sensor, only when the position is near the limit.

We have found a solution using the next code:

Code: Select all

	ch4->Dest=104.5;
    	Jog(4,-1);
	while (ReadBit(1032)) ; 		// wait for switch (input #16) to change
	printf("valor %d\n");			//print to control the code 	
	if (ReadBit(1032)== 0) 
	{
	 DisableAxis(4);			//Disable and enable the axis to stop the movement
	 EnableAxis(4);
	 Jog(4,1);
	 printf("valor %d\n",ReadBit(1032)); //print to control the code 	
	}
	printf("valor %d\n");
	while (!ReadBit(1032))
	{
	 printf("valor %d\n",ReadBit(1032)); //print to control the code 	
	 //Delay_sec(0.3);
	}
	Zero(4);
	MoveAtVel(4,100,10);
	while (!CheckDone(4));
	Zero(4);
I tried with

Code: Select all

Jog(4,0)
to stop the movement before

Code: Select all

Jog(4,1)
but it was ignored. The only way we found to solve this is using disable and enable.

I still not sure if this is the best way to solve this, so I post this here to ask for opinions and othe points of view.

Thank you!

Re: Home routine

Posted: Mon Feb 10, 2020 6:34 pm
by TomKerekes
Hi Juanjo-Lasing,

The original code should work except you have the first line:

ch4->Dest=104.5;

What is the purpose of that? Try removing it.

It isn't normally proper to change the commanded Destination. This can effectively cause a near infinite speed jump from the old Destination to the new Destination. Normally you should Move() to the new Destination to perform a motion. Or Disable the Axis while changing the Destination. Or use the EnableAxisDest(axis, dest); to enable the axis at the specified dest.

printf("valor %d\n"); //print to control the code
This line is incorrect as the %d specifies it should print an integer value but no integer parameter is passed. Note if you compile with the TI Compiler it will provide warnings about such things. The TI Compiler can be easily invoked by right clicking in the C Code. See here.

I tried with

Code: Select all

Jog(4,0)

to stop the movement before

Code: Select all

Jog(4,1)

but it was ignored.
I'm not sure exactly what you tried. But Jog(4,0) only begins to stop. If you command other motion immediately afterward without waiting to stop with while (!CheckDone(4)); then it will be effectively ignored.


Please indent your code properly so it is easier to read. Code can be automatically formatted by right clicking in the C Code and selecting Auto Indent.


HTH

Re: Home routine

Posted: Thu Feb 20, 2020 12:03 pm
by Juanjo-Lasing
Sorry I couldn't reply until now.

I was able to solve it with your indications and now it works perfectly.
Thank you as always Tom.

Re: Home routine

Posted: Thu Feb 20, 2020 5:31 pm
by TomKerekes
Great. Thanks for taking the time to post back.