Page 1 of 1

C# API - AddLinearMoveRel Blocking Implementation

PostPosted: Mon May 06, 2024 2:37 pm
by jdg26
Hi All,

I am working on upgrading our custom manufacturing control systems to use the UC100 controller.
So far, the API has been great and we've been able to upgrade all of our systems to use the UC100.

A typical work-flow looks like this:
Code: Select all
       
/*
   Move the X table in inches
*/
int ret = AddLinearMoveRel(0, steps, 1, speed, dir);
if (ret != (int)ReturnVal.UC100_OK)
{
     MessageBox.Show(SomeHelpStr);
     return;
}

// more machine code, drive a blade down, etc..


It seems the AddLinearMoveRel functions does not block and will return control to the callee.
This work great for most of our use cases, but other times I need to know when the movement is complete.

I have used this method below to wait for the desired movement to complete:

Code: Select all

private bool IsMotorRunning()
{
   Stat s = new Stat {  };
   int ret = GetStatus(ref s);
   return s.Idle == false;
}

private void ExampleMove(double steps, double speed, bool dir)
{
   int ret = AddLinearMoveRel(0, steps, 1, speed, dir);
   if (ret != (int)ReturnVal.UC100_OK)
   {
       MessageBox.Show(SomeHelpStr);
       return;
   }
   while (IsMotorRunning());
}


Is there a better implementation for this?
I'm not sure if polling the controller is the right way to go about this.

I could be missing something completely, so any tips are appreciated.

Cheers,
JG

Re: C# API - AddLinearMoveRel Blocking Implementation

PostPosted: Tue May 07, 2024 6:08 am
by cncdrive
Polling the idle/running state of the controller is the proper method.
You can't really do other way, because when you call a motion function it puts the movement into the motion buffer and it gives back the control to the caller function.
This is nessessary, because you can put more than one movement into the buffer and then if the constant velocity profiling is enabled then the software will optimise the movement path. If the control was not given back to the caller immediately then path optimalisation was not possible.