Dynomotion

Group: DynoMotion Message: 1470 From: bradodarb Date: 7/8/2011
Subject: Coordinated Motion Callbacks
Hello,

I am having some difficulty receiving callbacks from the CCoorMotion:


I do not recieve any callbacks, but for brevity I will just discuss the
STRAIGHT_TRAVERSE_CALLBACK

In my export dll, I am trying to use the same pattern as I have done successfully with the KMotion ConsoleCallback to recieve messages back from the card such as compile errors or if I run a C program with a printf.


I am setting the objects up in the DLL like so:


STRAIGHT_TRAVERSE_CALLBACK *StraightTransverseHandler=NULL;
void LocalStraightTransverseHandler(double x, double y, double z, int sequence_number)
{
return StraightTransverseHandler(x, y, z, sequence_number);
}


Then I have an exported method to wire things up:


SetStraightTraverseCallback(long *handle, STRAIGHT_TRAVERSE_CALLBACK *p)
{
CCoordMotion *CM_dll=(CCoordMotion *)handle;
StraightTransverseHandler = p;
CM_dll->SetStraightTraverseCallback(LocalStraightTransverseHandler);
}


That I call from the c# side and pass in a delegate with the right function argument signature.



It all runs with no errors, I just do not get any callbacks when I call a straighttraverse.

**
If I open the KMotion Axis dialog and run my test app, I do see the axis dest. change there as expected.




Thanks,

Brad Murry
Group: DynoMotion Message: 1471 From: bradodarb Date: 7/8/2011
Subject: Re: Coordinated Motion Callbacks
Tom,


I was not getting a callback, because I forgot to set the Coordinate system(axis map) (again).... durr



Ok, so now I am getting the callbacks but......

I am getting too many callbacks, enough to overflow the stack.


I have not changed the code I provided earlier.


Thank you for your time.

-Brad Murry

--- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@...> wrote:
>
> Hello,
>
> I am having some difficulty receiving callbacks from the CCoorMotion:
>
>
> I do not recieve any callbacks, but for brevity I will just discuss the
> STRAIGHT_TRAVERSE_CALLBACK
>
> In my export dll, I am trying to use the same pattern as I have done successfully with the KMotion ConsoleCallback to recieve messages back from the card such as compile errors or if I run a C program with a printf.
>
>
> I am setting the objects up in the DLL like so:
>
>
> STRAIGHT_TRAVERSE_CALLBACK *StraightTransverseHandler=NULL;
> void LocalStraightTransverseHandler(double x, double y, double z, int sequence_number)
> {
> return StraightTransverseHandler(x, y, z, sequence_number);
> }
>
>
> Then I have an exported method to wire things up:
>
>
> SetStraightTraverseCallback(long *handle, STRAIGHT_TRAVERSE_CALLBACK *p)
> {
> CCoordMotion *CM_dll=(CCoordMotion *)handle;
> StraightTransverseHandler = p;
> CM_dll->SetStraightTraverseCallback(LocalStraightTransverseHandler);
> }
>
>
> That I call from the c# side and pass in a delegate with the right function argument signature.
>
>
>
> It all runs with no errors, I just do not get any callbacks when I call a straighttraverse.
>
> **
> If I open the KMotion Axis dialog and run my test app, I do see the axis dest. change there as expected.
>
>
>
>
> Thanks,
>
> Brad Murry
>
Group: DynoMotion Message: 1472 From: Tom Kerekes Date: 7/9/2011
Subject: Re: Coordinated Motion Callbacks
Hi Brad,
 
Sorry I don't see any problem.  I added the Callbacks to the SimpleCoordMotion example and it seems to work fine.  See attached.
 
An obvious bug would be a mistake with a function name that resulted in a infinite recursive call to itself somewhere.
 
In your example I don't understand the purpose of the "local" call.  It seems like that would be unnecessary, but then shouldn't hurt anything.
 
Regards
TK
 


--- On Fri, 7/8/11, bradodarb <bradodarb@...> wrote:

From: bradodarb <bradodarb@...>
Subject: [DynoMotion] Re: Coordinated Motion Callbacks
To: DynoMotion@yahoogroups.com
Date: Friday, July 8, 2011, 7:41 PM

 

Tom,

I was not getting a callback, because I forgot to set the Coordinate system(axis map) (again).... durr

Ok, so now I am getting the callbacks but......

I am getting too many callbacks, enough to overflow the stack.

I have not changed the code I provided earlier.

Thank you for your time.

-Brad Murry

--- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@...> wrote:
>
> Hello,
>
> I am having some difficulty receiving callbacks from the CCoorMotion:
>
>
> I do not recieve any callbacks, but for brevity I will just discuss the
> STRAIGHT_TRAVERSE_CALLBACK
>
> In my export dll, I am trying to use the same pattern as I have done successfully with the KMotion ConsoleCallback to recieve messages back from the card such as compile errors or if I run a C program with a printf.
>
>
> I am setting the objects up in the DLL like so:
>
>
> STRAIGHT_TRAVERSE_CALLBACK *StraightTransverseHandler=NULL;
> void LocalStraightTransverseHandler(double x, double y, double z, int sequence_number)
> {
> return StraightTransverseHandler(x, y, z, sequence_number);
> }
>
>
> Then I have an exported method to wire things up:
>
>
> SetStraightTraverseCallback(long *handle, STRAIGHT_TRAVERSE_CALLBACK *p)
> {
> CCoordMotion *CM_dll=(CCoordMotion *)handle;
> StraightTransverseHandler = p;
> CM_dll->SetStraightTraverseCallback(LocalStraightTransverseHandler);
> }
>
>
> That I call from the c# side and pass in a delegate with the right function argument signature.
>
>
>
> It all runs with no errors, I just do not get any callbacks when I call a straighttraverse.
>
> **
> If I open the KMotion Axis dialog and run my test app, I do see the axis dest. change there as expected.
>
>
>
>
> Thanks,
>
> Brad Murry
>

  @@attachment@@
Group: DynoMotion Message: 1473 From: brad murry Date: 7/9/2011
Subject: Re: Coordinated Motion Callbacks [1 Attachment]
I will check again for a recursion issue.
The local was put in there to test it on c++ side(which works fine) ot will just point to p in production.


I'll have another look on c# side

Thanks ,
Brad Murry

Sent from my vastly superior Windows Phone 7

From: Tom Kerekes
Sent: Saturday, July 09, 2011 10:43 AM
To: DynoMotion@yahoogroups.com
Subject: Re: [DynoMotion] Re: Coordinated Motion Callbacks [1 Attachment]

 
[Attachment(s) from Tom Kerekes included below]

Hi Brad,
 
Sorry I don't see any problem.  I added the Callbacks to the SimpleCoordMotion example and it seems to work fine.  See attached.
 
An obvious bug would be a mistake with a function name that resulted in a infinite recursive call to itself somewhere.
 
In your example I don't understand the purpose of the "local" call.  It seems like that would be unnecessary, but then shouldn't hurt anything.
 
Regards
TK
 


--- On Fri, 7/8/11, bradodarb <bradodarb@...> wrote:

From: bradodarb <bradodarb@...>
Subject: [DynoMotion] Re: Coordinated Motion Callbacks
To: DynoMotion@yahoogroups.com
Date: Friday, July 8, 2011, 7:41 PM

 

Tom,

I was not getting a callback, because I forgot to set the Coordinate system(axis map) (again).... durr

Ok, so now I am getting the callbacks but......

I am getting too many callbacks, enough to overflow the stack.

I have not changed the code I provided earlier.

Thank you for your time.

-Brad Murry

--- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@...> wrote:
>
> Hello,
>
> I am having some difficulty receiving callbacks from the CCoorMotion:
>
>
> I do not recieve any callbacks, but for brevity I will just discuss the
> STRAIGHT_TRAVERSE_CALLBACK
>
> In my export dll, I am trying to use the same pattern as I have done successfully with the KMotion ConsoleCallback to recieve messages back from the card such as compile errors or if I run a C program with a printf.
>
>
> I am setting the objects up in the DLL like so:
>
>
> STRAIGHT_TRAVERSE_CALLBACK *StraightTransverseHandler=NULL;
> void LocalStraightTransverseHandler(double x, double y, double z, int sequence_number)
> {
> return StraightTransverseHandler(x, y, z, sequence_number);
> }
>
>
> Then I have an exported method to wire things up:
>
>
> SetStraightTraverseCallback(long *handle, STRAIGHT_TRAVERSE_CALLBACK *p)
> {
> CCoordMotion *CM_dll=(CCoordMotion *)handle;
> StraightTransverseHandler = p;
> CM_dll->SetStraightTraverseCallback(LocalStraightTransverseHandler);
> }
>
>
> That I call from the c# side and pass in a delegate with the right function argument signature.
>
>
>
> It all runs with no errors, I just do not get any callbacks when I call a straighttraverse.
>
> **
> If I open the KMotion Axis dialog and run my test app, I do see the axis dest. change there as expected.
>
>
>
>
> Thanks,
>
> Brad Murry
>

Group: DynoMotion Message: 1477 From: brad murry Date: 7/9/2011
Subject: Re: Coordinated Motion Callbacks [1 Attachment]
Tom,
 
Some funny things happening with the call backs.
 
 
For each callback type (ArcFeed,StraightFeed and StraightTraverse) I was using a delegate in c# to point to a function that matched the argument list for the given function pointer.
 
 
I changed this to just passing the actual function instead of the delegate and this remedied the stack overflow.
 
I use the delegate method on the KMotionDLL console callback with no problems, BTW.
 
Not sure why it can not work the same with the CoordMotionDLL callbacks, but I am ok with not using the delegates, the delegates just may have provided addtional functionality down the road is all(was thinking of ways to handle multiple cards, etc...).
 
 
So at any rate, I do receive callbacks, but there is still some odd behavior in both my implementation and the updated example you just sent.
 
 
 
So, if I comment out all but the ArcFeed moves; I do get arc callbacks. However if I run all the moves in the example I only get Straight Traverse.
 
In fact the pattern I am seeing is that only the first type of move recieves the callback.
 
 
Please confirm and advise.
 
Thanks,
 
Brad Murry
Group: DynoMotion Message: 1479 From: Tom Kerekes Date: 7/9/2011
Subject: Re: Coordinated Motion Callbacks
Hi Brad,
 
Sorry I'm very weak in C#, delegates, and managed code.
 
But are you saying the C++ SimpleCoordMotion example isn't woking either?  I tested it and it seems to work correctly.  Also the KMotionCNC program uses these callbacks to do the back plotting.
 
Maybe it has something to do with you only having one axis defined??  Even if you only have one motor wired you might configure the other axes to be open loop Step/Dir. 
 
Regards
TK  

 
 
 

--- On Sat, 7/9/11, brad murry <bradodarb@...> wrote:

From: brad murry <bradodarb@...>
Subject: RE: [DynoMotion] Re: Coordinated Motion Callbacks
To: dynomotion@yahoogroups.com
Date: Saturday, July 9, 2011, 2:04 PM

 
Tom,
 
Some funny things happening with the call backs.
 
 
For each callback type (ArcFeed,StraightFeed and StraightTraverse) I was using a delegate in c# to point to a function that matched the argument list for the given function pointer.
 
 
I changed this to just passing the actual function instead of the delegate and this remedied the stack overflow.
 
I use the delegate method on the KMotionDLL console callback with no problems, BTW.
 
Not sure why it can not work the same with the CoordMotionDLL callbacks, but I am ok with not using the delegates, the delegates just may have provided addtional functionality down the road is all(was thinking of ways to handle multiple cards, etc...).
 
 
So at any rate, I do receive callbacks, but there is still some odd behavior in both my implementation and the updated example you just sent.
 
 
 
So, if I comment out all but the ArcFeed moves; I do get arc callbacks. However if I run all the moves in the example I only get Straight Traverse.
 
In fact the pattern I am seeing is that only the first type of move recieves the callback.
 
 
Please confirm and advise.
 
Thanks,
 
Brad Murry
Group: DynoMotion Message: 1481 From: brad murry Date: 7/9/2011
Subject: Re: Coordinated Motion Callbacks
Tom,
 
I'm sure I am doing something iffy on my end, as it does infact work well on the Kmotion software.
 
I will try to mapp the axes as you described and see if that brings any joy.
 
Thanks,
-Brad Murry
 
Group: DynoMotion Message: 1482 From: brad murry Date: 7/9/2011
Subject: Re: Coordinated Motion Callbacks
Tom,
 
I have callbacks!
 
  The mapping was important, as was enabling all axes.  I am thinking a lot of issues I am running into have to do with my ignorance of operating with DynoMotion hardware.  Nothing like learning by doing...
 
In case anyone else travels down this road and want to avoid 'fixed' and/or 'unsafe' code blocks, this is what happened:
 
  I still occasionally recieved access violations when commanding a series of feed moves, so I pointed the CCoordMotion callbacks to local functions inside my export DLL, created new function pointers inside the export dll that get set to my c# delegates(which among other things are the .net equivalent of function pointers).  This way the CCoordMotion callbacks could reside in their own fixed memory and my .net callbacks could be associated as needed
 
  So now when the CoordMotion instance fires a callback, it reaches a function handler inside the export dll which dispatches the delegate call inside the c# wrapper as an event.  You can just subscribe to this public event and recieve the callbacks wherever you wish.
 
 
 
 I think I have Coordmotion buttoned up and ready for deployment.  I am going to add some code commenting for intellisense support and move on to the interpreter.
 
After that, I can incorporate it into my machine framework and see what happens.
 
 Thanks for the great support to help make this happen.
 
-Brad Murry