C# API - AddLinearMoveRel Blocking Implementation

If you have a question about the software please ask it here.

C# API - AddLinearMoveRel Blocking Implementation

Postby jdg26 » Mon May 06, 2024 2:37 pm

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
jdg26
 
Posts: 12
Joined: Wed Oct 25, 2023 1:58 pm
Location: USA

Re: C# API - AddLinearMoveRel Blocking Implementation

Postby cncdrive » Tue May 07, 2024 6:08 am

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.
cncdrive
Site Admin
 
Posts: 4901
Joined: Tue Aug 12, 2014 11:17 pm


Return to Ask a question from support here

Who is online

Users browsing this forum: Bing [Bot] and 8 guests