Machsupport Forum

Mach Discussion => Mach SDK plugin questions and answers. => Topic started by: warcomeb on September 21, 2011, 04:59:16 AM

Title: USB plugin don't fill Trajectories array
Post by: warcomeb on September 21, 2011, 04:59:16 AM
Hi, sorry for my english!
I develop a plugin for an italian company that use Mach3.
I try to connect Mach3 with USB... before this I try to print in a console data inside Engine->Trajectories array after load a gcode, with this simple code:
Code: [Select]
void USBPlugin::update (void)
{
    if (Engine->TrajHead == Engine->TrajIndex)
    {
        PluginConsole::getInstance()->printMessage("Same positions...");
        return;
    }
    else
    {
        Engine->TrajIndex++;
        PluginConsole::getInstance()->printMessage("New positions...");
    }
}
this function is called by myUpdate().

When I run the application and stop with breakpoint the trajectory elements are all empty.

Can you hel me?

best regards
Marco Giammarini
Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on September 21, 2011, 06:45:45 AM
Check my virtual plugin - it does work :-)

http://www.machsupport.com/forum/index.php/topic,17612.0.html
Title: Re: USB plugin don't fill Trajectories array
Post by: warcomeb on September 21, 2011, 06:58:25 AM
Check my virtual plugin - it does work :-)

http://www.machsupport.com/forum/index.php/topic,17612.0.html

thanks for the reply!

i have just see your plugin and i have added this lines to myInitControl function:

Code: [Select]
/* For 1ms timed waypoints... */
MainPlanner->ExTime = .001;
/* For variable ms timing... */
MainPlanner->ExternalType = EX_VMS;
/* Setup external pulse rate */
for( int x = 0; x < 7; x++ )
{
MainPlanner->ExternalPulseRates[x] = 1000000;
}

in this case the data exist in the trajectories array... but the appliccation don't work very well.
This is my step:
1) load gcode example with Mach3Mill profile.
2) press reset button
3) press cycle start...
4) the gcode stop at the third line where the gcode is
Code: [Select]
G90
G49
M3 S15000
G0 X52.000 Y27.663 Z7.472
G1   Z-0.500 F200
G1 X52.000 Y27.663 Z-0.500 F1200
X33.344 Y20.577
X33.197 Y20.535
X33.033 Y20.520
X32.858 Y20.537
...
5) press stop
6) press reset
7) and press another time cycle start
8) after this step i found data in array but in mach3 application the table display don't move and the disply for the axis don't move.

why?

if i disable the plugin, all works well!!

can you help me?

Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on September 21, 2011, 08:16:54 AM
Does it work if you run the code in my virtual plugin ?
Title: Re: USB plugin don't fill Trajectories array
Post by: warcomeb on September 21, 2011, 08:32:51 AM
I have VS2003 and I can not compile your plugin.  :(
Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on September 21, 2011, 08:38:45 AM
You can download Visual Express 2010 and try. Not sure if 2003 is supported for Mach plugins.
Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on September 21, 2011, 08:46:13 AM
One more thing - you may have to install Mach plugin wizzard as well - I think my project refereces some files from there ( instead of SDK)
Title: Re: USB plugin don't fill Trajectories array
Post by: warcomeb on September 21, 2011, 08:59:48 AM
You can download Visual Express 2010 and try. Not sure if 2003 is supported for Mach plugins.

I start to download VS2010 express.... VS2003 is supported, indeed the video tutorial is on VS2003.
Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on September 21, 2011, 10:07:52 AM
Here you have it : http://www.joshua1systems.com/machpluginwizard/
Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on September 21, 2011, 05:01:48 PM
I have run your GCode. As far as I can tell your problem comes from lack of Dwelling support.
Title: Re: USB plugin don't fill Trajectories array
Post by: warcomeb on September 22, 2011, 01:52:33 AM
how can I solve this problem?

Once I run the GCode with the plugin activated, the Mach3 crazy!
Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on September 22, 2011, 02:27:56 AM
Do you develop commercial product or you do it for fun ?

I have almost finished my devices ( now they are in test phase). I have ethernet motion controller ( originally it was using USB, but I decided for ethernet for final version).I plan to sell plugin software + design ( so everybody can do it himself)

You are in the beginnig of the road with your motion controller - there are many things to go until you have it running.I can help you  answering your questions, but for something "how can I solve it" - this sound like consultancy.
There are some examples in SDK ( in source code of old plugins).

 I wanted to create open source motion plugin, but I ended up making it myslef in 99% ( there was no help :-( ), that is why this become commercial ( if you want it  this way, contact me with private message).

About dwelling - in some cases ( like M3, when the spindle starts) you need to process Mach request to "delay" motion processing. You need stat machine in your plugin ( for this and e.g. jogging and homeing). Your plugin is "locked" until you finish the request.



Title: Re: USB plugin don't fill Trajectories array
Post by: warcomeb on September 22, 2011, 02:53:45 AM
I develop a commercial plugin for an Italian company... but I don't know anything of Mach3 and CNC. My boss give me this... and I am desperate.  :o  :o  :o

You are in the beginnig of the road with your motion controller - there are many things to go until you have it running.I can help you  answering your questions, but for something "how can I solve it" - this sound like consultancy.
;D

Quote
You are in the beginnig of the road with your motion controller - there are many things to go until you have it running.I can help you  answering your questions, but for something "how can I solve it" - this sound like consultancy.

Thanks... I try to solve this problem!  ;)
Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on September 22, 2011, 04:21:39 AM
Your boss is crazy.

Because there is no documentation how to do it, it is complicated. The only thing which helps are old examples in SDK ( unfortunately written in junk style, with no comments).
Nobody helps because these who have the knowledge paid high price getting there ( being reverse engineers).

Do you know that you need to create your state machine for jogging and manual movement ? Mach does not provide trajectory info for that. You need to understand motion constrains and be able to build your own trjectory for such cases. Together with state machine which handles it within mach.

Title: Re: USB plugin don't fill Trajectories array
Post by: warcomeb on September 22, 2011, 05:40:26 AM
Quote
Do you know that you need to create your state machine for jogging and manual movement ? Mach does not provide trajectory info for that

I imagined that it was necessary to do this...

thanks for your replies!
Title: Re: USB plugin don't fill Trajectories array
Post by: warcomeb on September 22, 2011, 06:00:41 AM
anyway... i don't understand where is the problem in dwell and how to reselve it!  ???  ???
Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on September 22, 2011, 06:11:46 AM
Well, hard to tell what the real problem is without knowing your code ( Dwell was just a guess as I had this problem with M3 and processing it). Ask your boss if you can post your code here - if it was made with VC 2010 then I can run it myself and check.
Title: Re: USB plugin don't fill Trajectories array
Post by: warcomeb on September 22, 2011, 06:38:29 AM
my code is in VS2003, but it is very empty and i can post it.

thanks for your help.
Title: Re: USB plugin don't fill Trajectories array
Post by: warcomeb on September 22, 2011, 06:51:07 AM
my code is in VS2003, but it is very empty and i can post it.

thanks for your help.


ps. sorry for the second posting... but the forum give me an error with .zip file!
Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on September 22, 2011, 06:52:11 AM
Cannot open your zip file :-(
Title: Re: USB plugin don't fill Trajectories array
Post by: warcomeb on September 22, 2011, 06:53:21 AM
with the rar file?
Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on September 22, 2011, 06:56:29 AM
With RAR it is ok
Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on September 22, 2011, 07:05:15 AM
Ok, I have looked at it.

I strongly recommend you to use my virtual plugin as startup.I managed to get most vital variables setup properly, so it does simulate work ( have not checked it with your M3 code however).

I found out why your code stalls - you need to set "MainPlanner->ExternalStill = true;" once you finish your movement or you reset your plugin.
You also do not update line position, so Mach does not show properly GCode line position.
Title: Re: USB plugin don't fill Trajectories array
Post by: warcomeb on September 23, 2011, 03:41:31 AM
Hi! i have tried your plugin and it work but this happen:
1) start M3
2) load gcode
3) push reset button
4) push start button...
The system is blocked as shown in attached figure, with Dwell led that blink, is it normal?
i push stop, push reset twice, and start... the application start.

This is the same thing is happening in my plugin ... but in my, position and the line of gcode still are not updated.

thanks
Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on September 23, 2011, 03:49:40 AM
Try to set    Engine->DwellTime = 0; in  ::Dwell(double time) call.

See code in my example which touches "Engine->DisplayLine"  as reference how to update GCode line
Title: Re: USB plugin don't fill Trajectories array
Post by: warcomeb on September 23, 2011, 04:01:27 AM
Try to set    Engine->DwellTime = 0; in  ::Dwell(double time) call.
ok, in this way work well!

About dwelling - in some cases ( like M3, when the spindle starts) you need to process Mach request to "delay" motion processing. You need stat machine in your plugin ( for this and e.g. jogging and homeing). Your plugin is "locked" until you finish the request.

If I had not put the dwell to 0, the user does not have access to the code of the plugin as it could solve?
Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on September 23, 2011, 04:12:33 AM
Dwelling tells your plugin to stop processing ( and executing) movement as e.g. spindle needs some time to reach its operational speeds ( may take few seconds). That is why you have noticed it after M3 ( it enables spindle ). But this is only one of few possible cases

In final version you should process the delay time given in Dwell(double time) call - meaning you should create state machine which waits until the delay expires and then set Engine->DwellTime = 0;


void MyDeviceClass::HandleSequences(void)
{

....

  switch(sequence)
  {

      case SEQ_DWELLING:
      {
         if(GetTickCount() - DwellTimestamp > DwellDelay)
         {
            // Well, dwelling time has expired
            Engine->DwellTime = 0;
            sequence          = SEQ_IDLE;
         }
      }break;


   




Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on September 23, 2011, 04:13:03 AM
//
 void MyDeviceClass::Dwell(double time)
 {

   // Calculate dwell time and record timestamp - will be serviced from state machine
   if( !MainPlanner->DwellMilli )
   {
      time = time * 1000;
   }
   
   DwellTimestamp  = GetTickCount();
   DwellDelay      = (DWORD)time;

   // Tell Mach we are dwelling
   Engine->DwellTime = 1;

   // There is silent assumption that dwell request will  come
   // only during GCode execution, when there is no other sequences running
   // ( no homing,jogging probing - etc.)
   assert( (sequence == SEQ_IDLE) || (sequence == SEQ_DWELLING) );

   sequence = SEQ_DWELLING;


   stats.DwellCall++;
 }
Title: Re: USB plugin don't fill Trajectories array
Post by: warcomeb on September 30, 2011, 03:17:01 AM
I found out why your code stalls - you need to set "MainPlanner->ExternalStill = true;" once you finish your movement or you reset your plugin.
You also do not update line position, so Mach does not show properly GCode line position.

Hi jarekk,
I have a question for you! I have insert in the update function this code
Code: [Select]
//If these ring buffer pointers are not equal, we have movement waiting..
if( Engine->TrajHead != Engine->TrajIndex)


//if Mavg is not set properly for the coming movement, set it now in a dwell message of 0 dwell
  while ( Engine->TrajHead != Engine->TrajIndex )
  {
Engine->DisplayLine = Engine->Trajectories[ Engine->TrajIndex ].ID;

Engine->TrajIndex++;  //increment ring
Engine->TrajIndex &= 0xfff; //rotate the ring if necessary..
  }
}
if( (Engine->TrajHead == Engine->TrajIndex) &&  MainPlanner->BufferEnding )
{
finalizeMoves();
}

and i have set a breakpoin in finalizeMoves function... but M3 stop in this function only when have read the last line of GCode. it is correctly?

The axis position and tool tool view are not updated. why? i don't understand!!!! help me!

thanks for help

Marco
Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on October 01, 2011, 12:56:37 AM
About th M3 stop - Well, I do not understand what you really mean.


About the position update - have you analyzed my code at all ? :P

It is your responsiibility to update Mach variables  - it is your plugin which is supposed to create motion according to given trajectory and report back the result ( as position).

Once uoy update position, you will also get tool view updated.
Title: Re: USB plugin don't fill Trajectories array
Post by: warcomeb on October 01, 2011, 05:35:51 AM
About the position update - have you analyzed my code at all ? :P

It is your responsiibility to update Mach variables  - it is your plugin which is supposed to create motion according to given trajectory and report back the result ( as position).

Once uoy update position, you will also get tool view updated.

Thank! I've read most of your code and I solved the problem.

Quote
About th M3 stop - Well, I do not understand what you really mean.
I have put in this line a breakpoint and M3 arrive in this line only when have read the last line of GCode. it is correctly?

Thanks
Marco

ps. I have another question but i think you kill me! :D
Title: Re: USB plugin don't fill Trajectories array
Post by: warcomeb on October 01, 2011, 06:00:12 AM
hello!

my question: what is the relationship between kernel velicity, ExternalPulseRates, motor velocity, ExBufferHi and ExTime?
i don't understand what values ​​should I put...

thanks
Marco
Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on October 03, 2011, 04:18:01 AM
finalizeMoves() is called when Mach finishes your Gcode processing - so it is correct behaviour.

About:  ExternalPulseRates, motor velocity, ExBufferHi and ExTime - these are configuration variables for your plugin. All these settings are independent. Most were described in my plugin.
 ExternalPulseRates - your max step signal frequency
 ExBufferHi - max lookahead buffer for movements
 ExTime - tyime slice for single motion record ( time period with constant speed data records you get from trajectory)
 motor velocity - this describes CNC machine movement constrains
Title: Re: USB plugin don't fill Trajectories array
Post by: warcomeb on February 29, 2012, 04:15:37 AM
I have a new question  ;D

whene home function is called by M3?

regards
Marco
Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on February 29, 2012, 05:05:53 AM
No idea - but this you can easily debug and trace producing such code.

But - M3 is related to spindle control - whay do you ask about homing ( which is something different)
Title: Re: USB plugin don't fill Trajectories array
Post by: warcomeb on February 29, 2012, 05:17:53 AM
I have in my CNC a three homing sensors and I have no idea how to handle them.
I use my homing sensors as inputs?

when I push "REF ALL HOME" in a GUI, What does this mean?

No idea - but this you can easily debug and trace producing such code.

I have inserted a breakpoint in home function, but this is never called!
Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on February 29, 2012, 05:23:57 AM
Well, home function is being called once you tell Mach  to home axis.
The basic idea is that you configure your inputs as "home inputs" so Mach knows which inputs to use when executing home procedure
Title: Re: USB plugin don't fill Trajectories array
Post by: warcomeb on February 29, 2012, 09:36:54 AM
Ok, i have enabled home input and and i have pushed REF ALL HOME button, but motors do not move...
Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on February 29, 2012, 10:08:01 AM
The bad news is that once you make motion plugin you have to code the homing motion yourself - Mach will not do it for you. See my code - I had to calculate everything myself and send my own motion commands to my hardware controller.
Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on February 29, 2012, 10:08:37 AM
See Home() function in the plugin template - it is called for homeing
Title: Re: USB plugin don't fill Trajectories array
Post by: warcomeb on February 29, 2012, 01:26:00 PM
In this new plugin?
http://www.machsupport.com/forum/index.php/topic,19697.0.html
Title: Re: USB plugin don't fill Trajectories array
Post by: jarekk on March 01, 2012, 04:06:17 AM
It is operational  and I have opened the code - so you can have a look at it.
It has been there for some time - I do not continue its development it as there was not much interest.

Note - it has not been heavily tested, but basic operation do work.
Title: Re: USB plugin don't fill Trajectories array
Post by: warcomeb on April 03, 2012, 02:20:33 AM
Thanks for your help!
I have the last question (really the last question): Probe, what is it? what do my program when this input is activated? and when Probe function in SDK is called?

Thanks
Marco
Title: Re: USB plugin don't fill Trajectories array
Post by: warcomeb on April 05, 2012, 09:20:42 AM
I have another question  :-[ !!!!
how can I update the coordinates on the GUI of the Mach when I'm jog motion? which variable should I update?

thanks
Marco
Title: Re: USB plugin don't fill Trajectories array
Post by: crisvenua on July 17, 2012, 01:11:01 PM
Hi I am developing a plugin to control 4 motors with 6 inputs 6 outputs, I have my very advanced project, now I doubt arises, I can not move the motor by setting jog-hotkeys, any know how to implement this in a motion plugin?