Machsupport Forum

Mach Discussion => Mach SDK plugin questions and answers. => Topic started by: jarekk on July 15, 2010, 06:46:10 AM

Title: Motion planner - cubic moves in GMoves
Post by: jarekk on July 15, 2010, 06:46:10 AM
Hi,

I have been developing motion plug in for my hardware.
I have studied documentation and code examples. My hardware is quite close to ncPod, so that was the base for me.
Could you help me with following questions ?

1) According to the doc GMoves can be cubic ( so instead of linear motion  you get circular - with endpoints and circle origin). I have studied ncPod plugin and it seems it ignores the info ( GMoves.type) and treats everything as linear motion. Can I force Mach to get only linear motion - not to process these cubic motions myself ( with linear approximation ) ?

2) Coordinates sync between external hardware and Mach. Is it so that during GCode motion Mach assumes that all vectors send are executed and the coordinate is the final coordinate of last vector ? I have seen some coordinate feedback to Mach only while jog processing ( and in quite strange units - Engine->Axis[..].Index which is integer - means pulses ?? )

Thanks for your help

PS. Link to the doc http://www.machsupport.com/MachCustomizeWiki/index.php?title=The_G100/GREX_plugin_as_a_model_for_device_control
Title: Re: Motion planner - cubic moves in GMoves
Post by: 4z7 on August 27, 2010, 06:45:07 PM
Jarrek,
I'm fairly certain that you don't mean that you don't want to process circular motion.  I think what you are saying is you don't want to process the DDA's. The GMoves structure is supposed to provide position moves and velocity moves and because time is included in the structure you can get velocity from the commanded position move and  position from the commanded velocity.  From what I've seen in the ncpods code it only uses the commanded positions and ignores DDA's.

I'm working on a motion plug in for a NextmoveESB motion controller.  I have I/O, and commanded velocity motion like jogging or home, functional but I am stuck on GCode moves.  The plugin is written in C++/CLR and uses the MachInclude structures built by Ed from Joshua Systems.  I don't know if Ed's MachIncludes are broken or if there is a Mach variable that needs to be turned on but the GMoves structure doesn't return any position data.

 I call into the ring buffer to get the GMove structure (from the Mach plugin wiki):
struct GMoves
{
   int type;    // 0 is linear, 1 is circular
   double cx,cy,cz; // center of move for cubics.
   double ex,ey,ez,ea,eb,ec;
   double sx,sy,sz,sa,sb,sc;
  __int64  DDA1[6];    //DDA1's for cubics                                                                   
   __int64  DDA2[6];
   __int64  DDA3[6];
   double Time;
   bool   Stop;
};
Not all the values are returned.
type,Time,Stop and DDA's all have values but e[axis],s[axis],c[axis] are always 0.  Ex.
MDI "g1 x1 f10" will return type = 0, Time =63(64) ms, DDA[0] = 999999999  (a large int),DDA[1] = 0, but ex = sx = 0- No position data.  When the move has completed, Time returns 34 and DDA[0] returns 8888888 (a different large int) which was the final move in the trajbuffer.

I don't really want to use this GMoves structure anyway because the longest move is only 64 ms.  What I want to get from Mach is the line of G-Code broken down for the line's complete move in a structure like:
"g1 x1 f10" (assuming starting at x0,y0,z0,)
struct GLineMove
{
   int type;    // 0 is linear
   double center[3]; // all zeros because move is linear
   double end[6];//ex = 1.0000 ( or counts),ey = ez...=sy = sz ... = 0
   double start[6];//sx = 0 ( or counts)this is  known
   double Time;//time = 6000 (1 uu * 60 sec/10 uu *  1000ms /sec )
};



Obviously Mach must take a line of G-Code and translate it to axes velocity pulses.  Somewhere during this translation the above variables are probably generated but maybe not exposed in a buffered structure that can be read and incremented.  I suspect that  position move data by gcode line  has something to do with the BACK_BUFFER  but I haven't discovered how to get at a "Back Buffer"or any movement structure other than the velocity pulse based GMoves and GMoves1.

Any ideas would be appreciated.



Thanks,
Kurt

More info on the NextMove controllers:
The controller is a Texas Inst. Microcontroller which runs basic c software called Mint.  There are 3 or 4 servo channels, 4 stepper channels, 20 inputs,  11 outputs and 2 additional analog channels.  I/O, Servos, steppers are setup and tuned with a UI called MintWorkBench and the setup is stored in eprom on the controller.  The program that runs on the controller is just a loop that waits for an  event to happen (like a limit switch hit or estop) then processes the event and when finished returns to the main loop to wait for another event or command from a host which will be Mach if I can ever figure out how to get G code line moves.  The real beauty of this controller is just how simple it is to interface to a host.  All the host controls are AxtiveX and they pretty much duplicate all the functions and methods available in Mint.  For example aX is a pointer to the MintController.lib::ActiveXMintController;
aX->set_Jog(short nAxis, float vel); // jogs the axis at +- vel direction

aX->VectorA(nNumberOfAxes, nAxesArray,  fPosArray);;// coordinated one or more axis moves
Title: Re: Motion planner - cubic moves in GMoves
Post by: jarekk on August 28, 2010, 04:32:59 AM
Hi,

My basic question was - can I setup Mach in a way that I get only linear motion ? According to specs you can get
'int type;    // 0 is linear, 1 is circular'
By testing on live device I actually get value 2. This basically mean that I get absolute end coordinates every GMoves structure.
I would like to know what happens when Mach gets circular motion - whether I can configure Mach trajectory planner to approximate circles with linear motion or I get circular motion anyway and I have to deal with it myself.

There is no specs about it and it is hard to find from milions of useless undocumented variables in Mach structures.
U used wizard to use basic plugin design. And I get some reasonable coordinates. Note that in the beginning trajectory controller sends a lot of empty moves ( with zero coordinates and time equal to zero). If you like, I can send it to you - connect debugger and you will see the results.


Basically - I would like to get same info as you. My device was originally developed for different control software, which prepares whole trajectory offline and sends as big package to the controller ( I do have 64 Mbit SDRAM). I have my own trajectory planner which calculates acceleration/deceleration for the whole path.
I was trying to get info ( on theforum) how to get whole trajectory at once ( even as GMOves - I would process them and combine into my format).
But nobody answered. I have sent private message to Art - also no answer.

For good or bad - we are condemned to experimenting on our own. There were some changes in Mach since the motion plugin examples were created. And nobody updated them. Few people who made it working pay high price for that and as they created commercial projects - they do not want to share the knowledge. And there is not much help from Mach designers.

My feeling is that these motion plugins which work (like SmoothStepper, NcPod , maybe DSPMC ) were created with Art's help (as there were some notes about it on the forum).







Title: Re: Motion planner - cubic moves in GMoves
Post by: 4z7 on August 28, 2010, 08:27:48 PM
I have since discovered a few more details on the back end. First of all I haven't even gotten to circular motion since I'm still trying to figure out linear motion.
I found the following Mach variables that give me the g Code move in  different places.
1.   Engine->LastCommandPos[6] give you 6 axes of the current G-code move in whatever work coordinates selected like G54.

2.  setup->CurrentOrigins[6] give you the fixture offsets so adding the two together you get the machine coordinates for the G-code move.

3.  _setup->feed_rate give you the GCode commanded feed rate in  //uu/sec.

4._setup->sequence_number is a number assigned by mach for each line of continuous GCode being processed.  It increments by 1 with each line of continuous G code and resets if G-code stream is interrupted. Oddly it appears to start and reset at 2 not 1, but maybe I'm just not seeing the first pass.

5.  _setup also has individual axis position moves but it is harder and slower to  process because it isn't in an axis array.

6.  I can also set a value to each line of gcode being run on the Nextmove controller and poll it during update.  The controller also has variables to set it's buffer size and get the buffer's free space.

So, I'm polling or updating at 50ms and every cycle I increment Mach's trajectory buffer
to stay ahead of Mach's 64 ms move.  I am not sure that incrementing Machs trajectory buffer is what triggers Machs Gcode processing but I suspect so.,  If the Nextmove controller is still on the same gcode move i do nothing more until it has finish the move and into the next line and then I call the required Mach variables described above and load another move into the controller.  So far I've been keeping 3 moves in the controllers buffer.

I don't need to worry about accel decel with Mach because that all gets setup in the controller.  Outside of slaving an axis for threading I only need to process vector moves and helical moves.  The controller can be set up for S-curve accel and contourmode which is corner blending like Mach's constant velocity mode.

Does the controller you are working with have servo loop control or does it generate pulses?  Are you aware of the other  Move structure GMoves1?  You get to the structure  GMoves1 rest = MainPlanner->MovementsAdd[Engine->TrajIndex].diffs;.  I am fairly certain that smoothstepper uses the diffs to generate it's pulses.  From what I could tell they are small constant (except at accel/decel so accel is built in )relative position moves but there is no time data except for the frequency delivery which is probably at 10 ms driven by Mach's fast clock.  There is also circular and velocity sweep data in the structure but that doesn't mean you have to use it.



I still hope to here from someone that might know more about the Gcode block and the best way to get it.



Kurt

Oh I wanted to say there are a lot of very generous people on this forum.  Hood and ED are two that come to mind, although Ed's gone he still left a lot.  Part of the problem is C++ is a betch and then putting .net on top of it---Microsoft barely even supports it.  I've found the best way to figure things out in CLR is to see how it is done in C# which translates into clr fairly easy.  .
Title: Re: Motion planner - cubic moves in GMoves
Post by: jarekk on August 29, 2010, 04:57:42 PM
Hi,

Nice that I finally found somebody who wants to share info about it.

My controller is something like ncPod or Smoothstepper. It uses LPC1769 with ethernet (working on proto now, previous production version was on LPC2148 ). Even without FPGA ( like smoothstepper) it is capable of 100kHz pulsing for 4 axis. Good enough for most people, want to target low-end market.Originally designed for other software then Mach, but I wanted bigger audience for it. It is my hobby - for living I design equipment for low voltage power networks.

As far as I understand the available documents, you get the movements in real time plus 2 seconds. So you have to be careful if dynamic of your system does not match the one setup in Mach - if you use much faster settings, you will stall your controller - Mach most likely will not give you more data these 2 seconds ahead.

Good that you know something about axis slaving - that was also a question on my list.

How to proceed ? I have an idea worth trying. I thought of creating 'virtual'  motion plugin. The control device would be just an emulation software located on local ethernet port.  I would also add doxygen tags and all findings - mine and yours, plus everything else extracted from the documentation.
This would create nice help file with tags, references and a lot of sections with questions.
I would be ready to spend some time on it on one condition - we get somebody from Mach developers to review our plugin and answer our questions. So we create together new motion plugin example to be put to SDK - so everybody  benefits.
Any idea how to involve them - emaybe new topic like "Artsoft help us - support our initiative?"