Functional overview

Discussions and file drops for Auggie
Richard Cullin
Old Timer
Posts: 152
Joined: Sat Jun 02, 2012 5:45 am

Re: Functional overview

Post by Richard Cullin »

amazing how easy it looks after you figure it out
I will let you know if I ever get there

slight change used tableCount()  for tx loop limit
I will leave spindle off/on  as the are since the data will never change

Code: Select all


// Library Vfd-Spindle 
// Created  Wednesday, January 04, 2017 
// Author  rc       -- Do not edit above this line
  
 //  Enter Global vars below this line. 
//  the librarian no matter where they are, but its easier 
//  to find and edit them in one spot.
   
   
   
//  vfd stuff
   
global   myser = Serial();
 
 
// 
global  Vfd_Open = function()
{
myser.Open(6,9600);
myser.SendData("123");
print( "VFD opened"); 
SpindleSpeed(5500);
};
 
//this is a  HUANYANG vfd   control, 
//it will use rs485  to control a spindle
//on/off spindle, and speed 

global SpindleOn = function()
{
    vfd={0x01,0x03,0x01,0x01,0x31,0x88}; 
    myser.Table = vfd;
    myser.SendTable();
    print("Vfd Spindle was turned on");
    print("Set to Frequency " + GlobalGet("SpindleSpeed"));
};   
 
//this is a  HUANYANG vfd   control, 
//it will use rs485  to control a spindle
//on/off spindle, and speed  

global SpindleOff = function()
{
      
    vfd= table(0x01,0x03,0x01,0x08,0xF1,0x8E); 
    myser.Table = vfd;
    myser.SendTable();
    print("Spindle speed zeroed");
    
};  
 
 
global SpindleSpeed = function( speed )
{
    if( Engine.GetSpindleState() != 0)
     {
      CRC=0xffff;
      print("speed set to " + speed); 
      vfd=table(0x01,0x05,0x03,0,0,0); 
      freq=speed/55.0;
      freq=freq*100;
      vfd[3]=ToInt(freq/256);
      vfd[4]=ToInt(freq%256);  
      print("Frequency  set to " + freq );
&nbsp; &nbsp; &nbsp; for (inx=0;inx<tableCount(vfd);inx+=1)
&nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; myser.SendHex(vfd[inx]);
&nbsp; &nbsp; &nbsp; CRC=Crc16(CRC,vfd[inx]);
&nbsp; &nbsp; &nbsp; };
&nbsp; &nbsp; &nbsp; print("the CRC " + CRC);
&nbsp; &nbsp; &nbsp; myser.SendHex(ToInt(CRC/256));
&nbsp; &nbsp; &nbsp; myser.SendHex(ToInt(CRC%256));
&nbsp; &nbsp;  };
 
};&nbsp;  
 
// calculate a ccitt 16 bit crc on byte at a time
// preset crc to 0xffff to initialise a new calc



global&nbsp; Crc16 = function(crc,byte_in)
{
 //print("CRC " + byte_in );
 crc = crc ^&nbsp; byte_in ;
&nbsp; &nbsp; &nbsp; for (c=0;c<8;c+=1){
&nbsp; &nbsp; &nbsp; &nbsp;  if (crc&1)
&nbsp; &nbsp; &nbsp; &nbsp;  { 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  crc= ((crc>>1) ^0xa001 )&nbsp;  ;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp;  else
&nbsp; &nbsp; &nbsp; &nbsp;  {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  crc= crc>>1;
&nbsp; &nbsp; &nbsp; &nbsp;  };
&nbsp; &nbsp; &nbsp;  };
return ToInt(crc);
};
Ya-Nvr-No
Old Timer
Posts: 188
Joined: Wed Sep 08, 2010 11:15 am

Re: Functional overview

Post by Ya-Nvr-No »

ArtF wrote: YaNvrNo helps me a tremendous amount in primary testing , Ive crashed him hundreds of times.. (probably thousands..), so I
really have to hand it to him for stamina.
Thanks Art, but I'm closer to a "glutton for punishment".

Admit I pushed you steadily with feedback, ideas and questions, as I knew that we both wanted a dedicated CNC laser controller. Then onto a robust toolbox of goodies including scripting to develop out of the box concepts for experimenting. The big plus is you have taught us a lot of things we never would have experienced without your creative abstract thinking, persistence and ability to bring it to life.

Still have a growing wish list. So we all are not done yet. &nbsp;:D

Craig
Richard Cullin
Old Timer
Posts: 152
Joined: Sat Jun 02, 2012 5:45 am

Re: Functional overview

Post by Richard Cullin »

had to make some more changes , vfd was not happy with&nbsp; the data stream from setspeed&nbsp; for some reason [there was 2 or 3 mS gaps between bytes]
would make a crctable function a nice feature
can't figure how to add elements to a table yet either ,that would be useful



this is much better

Code: Select all

// Library Vfd-Spindle 
// Created&nbsp; Wednesday, January 04, 2017 
// Author&nbsp; rc&nbsp; &nbsp; &nbsp;  -- Do not edit above this line
&nbsp; 

&nbsp;  
&nbsp;  
//&nbsp; vfd stuff
//&nbsp; the rs485 port&nbsp;  
global&nbsp;  myser = Serial();




 
 
// open and init the port 


global&nbsp; Vfd_Open = function()
{
myser.Open(7,9600);
myser.SendData("123");
print( "VFD opened"); 

};
 
//this is a HUANYANG vfd spindle control, 
//it will use only rs485 port
//to control a the spindle
//on/off spindle, on or off and speed

global SpindleOn = function()
{
&nbsp; &nbsp; 
&nbsp; &nbsp; vfd={0x01,0x03,0x01,0x01,0x31,0x88}; 
&nbsp; &nbsp; myser.Table = vfd;
&nbsp; &nbsp; myser.SendTable();
&nbsp; &nbsp; print("Vfd Spindle was turned on");
&nbsp; &nbsp; print("Set to Frequency " + GlobalGet("SpindleSpeed"));
};&nbsp;  
 
//this is a HUANYANG vfd spindle control, 
//it will use only rs485 port
//to control a the spindle
//on/off spindle, on or off an speed
 
global SpindleOff = function()
{
&nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; vfd= table(0x01,0x03,0x01,0x08,0xF1,0x8E); 
&nbsp; &nbsp; myser.Table = vfd;
&nbsp; &nbsp; myser.SendTable();
&nbsp; &nbsp; print("Spindle speed zeroed");
&nbsp; &nbsp; 
};&nbsp; 
 

//this is a HUANYANG vfd spindle control, 
//it will use only rs485 port
//to control a the spindle
//on/off spindle, on or off an speed
 
global SpindleSpeed = function( speed )
{
 
&nbsp; &nbsp; &nbsp; CRC=0xffff;
&nbsp; &nbsp; &nbsp; print("speed set to " + speed); 
&nbsp; &nbsp; &nbsp; vfd=table(0x01,0x05,0x03,0,0,0,0,0); 
&nbsp; &nbsp; &nbsp; freq=speed/55.0;
&nbsp; &nbsp; &nbsp; freq=freq*100;
&nbsp; &nbsp; &nbsp; vfd[3]=ToInt(freq/256);
&nbsp; &nbsp; &nbsp; vfd[4]=ToInt(freq%256);&nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; print("Frequency&nbsp; set to " + freq );
&nbsp; &nbsp; &nbsp; for (inx=0;inx<(tableCount(vfd)-2);inx+=1)
&nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CRC=Crc16(CRC,vfd[inx]);
&nbsp; &nbsp; &nbsp; };
&nbsp; &nbsp; &nbsp; // print("the CRC " + CRC);
&nbsp; &nbsp; &nbsp; vfd[7]=ToInt(CRC/256);
&nbsp; &nbsp; &nbsp; vfd[6]=ToInt(CRC%256);
&nbsp; &nbsp; &nbsp; myser.Table = vfd;
&nbsp; &nbsp; &nbsp; myser.SendTable();
};&nbsp; 


// calculate a ccitt 16 bit crc on byte at a time
// preset crc to 0xffff to initialise a new calc


 
 
global&nbsp; Crc16 = function(crc,byte_in)
{
 //print("CRC " + byte_in );
 crc = crc ^&nbsp; byte_in ;
&nbsp; &nbsp; &nbsp; for (c=0;c<8;c+=1){
&nbsp; &nbsp; &nbsp; &nbsp;  if (crc&1)
&nbsp; &nbsp; &nbsp; &nbsp;  { 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  crc= ((crc>>1) ^0xa001 )&nbsp;  ;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp;  else
&nbsp; &nbsp; &nbsp; &nbsp;  {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  crc= crc>>1;
&nbsp; &nbsp; &nbsp; &nbsp;  };
&nbsp; &nbsp; &nbsp;  };
return ToInt(crc);
};
 

 
 
 
Ya-Nvr-No
Old Timer
Posts: 188
Joined: Wed Sep 08, 2010 11:15 am

Re: Functional overview

Post by Ya-Nvr-No »

How about something like this

Code: Select all

global SpindleSpeed = function( speed )
{
&nbsp; &nbsp; &nbsp; CRC=0xffff;
&nbsp; &nbsp; &nbsp; print("speed set to " + speed);
&nbsp; &nbsp; &nbsp; vfd={0x0,0x0,0x0,0x0,0x0,0x88,0x0,0x0,0x0}; 
&nbsp; &nbsp; &nbsp; vfd[0]=0x01;
&nbsp; &nbsp; &nbsp; vfd[1]=0x05;&nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; vfd[2]=0x03;&nbsp;  
&nbsp; &nbsp; &nbsp; freq=(speed/55.0)*100;
&nbsp; &nbsp; &nbsp; vfd[3]=ToInt(freq/256);
&nbsp; &nbsp; &nbsp; vfd[4]=ToInt(freq%256);&nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; FreeSetSpeed( MySpindleAxis, speed);
&nbsp; &nbsp; &nbsp; print("Frequency set to : " + freq ); 
&nbsp; &nbsp; &nbsp; for (inx=0;inx<6;inx+=1)
&nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; print("vfd ",vfd[inx]);
&nbsp; &nbsp; &nbsp; &nbsp; CRC=Crc16(CRC,vfd[inx]);
&nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; print("the CRC " + CRC);
&nbsp; &nbsp; &nbsp; vfd[6]=ToInt(CRC%256);
&nbsp; &nbsp; &nbsp; vfd[7]=ToInt(CRC/256);
&nbsp; &nbsp; &nbsp; for (inx=0;inx<8;inx+=1)
&nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; print("the vfd["+ inx + "] " + vfd[inx]);
&nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; myser.Table = vfd;
&nbsp; &nbsp; &nbsp; myser.SendTable();
};&nbsp;  
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4591
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Functional overview

Post by ArtF »

Hi:

>>can't figure how to add elements to a table yet either ,that would be useful

&nbsp; To add, just do it.

ex:

vfd = { 1,2,3 };
vfd[7] = 6;

//you now have 8 elements in vfd, the ones not set are NULL.
// 1,2,3,NULL,NULL,NULL,NULL,6;

Art
Richard Cullin
Old Timer
Posts: 152
Joined: Sat Jun 02, 2012 5:45 am

Re: Functional overview

Post by Richard Cullin »

thanks guys
adding elements&nbsp; like this works perfectly

Code: Select all

global SpindleSpeed = function( speed )
{
 
&nbsp; &nbsp; &nbsp; CRC=0xffff;
&nbsp; &nbsp; &nbsp; print("speed set to " + speed); 
&nbsp; &nbsp; &nbsp; //FreeSetSpeed( MySpindleAxis, speed);
&nbsp; &nbsp; &nbsp; vfd=table(0x01,0x05,0x03);
&nbsp; &nbsp; &nbsp; freq=speed/55.0;
&nbsp; &nbsp; &nbsp; freq=freq*100;
&nbsp; &nbsp; &nbsp; vfd[3]=ToInt(freq/256);
&nbsp; &nbsp; &nbsp; vfd[4]=ToInt(freq%256); 
&nbsp; &nbsp; &nbsp; vfd[5]=0;
&nbsp; &nbsp; &nbsp; print("Frequency&nbsp; set to " + freq );
&nbsp; &nbsp; &nbsp; for (inx=0;inx<tableCount(vfd);inx+=1)
&nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CRC=Crc16(CRC,vfd[inx]);
&nbsp; &nbsp; &nbsp; };
&nbsp; &nbsp; &nbsp; // print("the CRC " + CRC);
&nbsp; &nbsp; &nbsp; vfd[7]=ToInt(CRC/256);
&nbsp; &nbsp; &nbsp; vfd[6]=ToInt(CRC%256);
&nbsp; &nbsp; &nbsp; myser.Table = vfd;
&nbsp; &nbsp; &nbsp; myser.SendTable();
};&nbsp; 
 

if I wanted to add a speed dro&nbsp; that read the spindle freq say 2 times / sec , are there any 'timers' or such available to schedule calls to dro update function
Richard Cullin
Old Timer
Posts: 152
Joined: Sat Jun 02, 2012 5:45 am

Re: Functional overview

Post by Richard Cullin »

just to complete things the system call back script was altered also as below

Code: Select all

// Library SystemCallBacks 
// Created&nbsp; Thursday, December 31, 2015 
// Author&nbsp; Art&nbsp; &nbsp; &nbsp;  -- Do not edit above this line
&nbsp; 
//&nbsp; Enter Global vars below this line. 
 
 
&nbsp;  
 
// This script will be called 
//whenever the system is going from 
//Enabled to Disable. It is called after the 
// system shuts down motion.
 
global OnDisable = function()
{

&nbsp; myser.Close();&nbsp;  // shut vfd port
 
&nbsp; print( "--System -- System Disabled.");
&nbsp; //shut off any spindle since I use one..
&nbsp; if( lookup("SpindleOff")) { SpindleOff(); };
&nbsp; //shut down any other Estop process here..
};
 
 
//This script is called whenever 
//the system is going from disabled to
//enabled. It is called before removing Estop 
//conditions.
 
global OnEnable = function()
{

&nbsp;  Vfd_Open();&nbsp; //&nbsp; open vfd port

&nbsp;  print( "--System -- System enabling.");
};
 
//This script is called whenever 
//the user presses RUN if the run was allowed
 
global OnRun = function()
{
&nbsp;  
&nbsp;  print( "--System -- System about to run.");
};
 
//This script is called whenever 
//the user zeroes an axis, axis is a bitfield
//value, bit 1 is axis 1, bit 2 is axis 2....
//do not change the zero here, that would
//cause an infinite loop
 
global OnZero = function( axis )
{
&nbsp;  print( "--System -- User has zeroed an axis"&nbsp; );
};
 
//This script is called whenever 
//the user homes an axis, axis is a bitfield
//value, bit 1 is axis 1, bit 2 is axis 2....
//called after homing and zeroing
 
global OnHome = function( axis )
{
&nbsp;  print( "--System -- User has homed an axis" );
};
 
//This script is called whenever 
//the user regens the toolpath
 
global OnRegen = function()
{
&nbsp;  print( "--System -- User has Regened the toolpath.");
};
 
//This script is called whenever 
//the Scripting system has reset and 
// reloaded all scripts. You may do additional 
// startup tasks here.
 
global OnAllScriptsLoaded = function()
{
&nbsp;  print( "--System -- System has reset Scripting system.");
};
&nbsp; 
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4591
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Functional overview

Post by ArtF »

Hi Richard:

&nbsp; Well, when it comes to timers theres a couple of ways. Sleep releases the thread and uses no system resources, the thread
goes to sleep until the time set. So sleep(1); will return to the program and things run until at least 1 second has gone by, and it returns.

So a routine like

while(1)
{
&nbsp; SpindleFeed =...
&nbsp; sleep(1);
}

&nbsp; will run forever..updateing a dro every second.

if its a dro with motion, you can use blocks.

block("MotionUpdate"); is the same as saying sleep until an axis moves..but will be periodically called
every few seconds I believe&nbsp; even if axis dont move..just to keep things in sync.

or you can use your own blocks.

block("MyUpdate"); will put a script to sleep until some other script calls
signal("MyUpdate");

&nbsp; The combination of those two techniques handle almost any timing requirement..other than
reading time. I think theres a tick command in there.. Ill have to check..

Art



Richard Cullin
Old Timer
Posts: 152
Joined: Sat Jun 02, 2012 5:45 am

Re: Functional overview

Post by Richard Cullin »

first try at getting some data back from vfd ,although the the vfd accepts the cmd and replies accordingly
myser.ReadData( 8 ) returns nothing &nbsp;:-\

[the vfd takes at least 8mS to reply] see &nbsp;pic for &nbsp;cmd and response


global GetVfdSpeed = function( )
{

&nbsp; &nbsp;vfd={0x01,0x04,0x03,0x01,0,0,0xA1,0x8E};
&nbsp; &nbsp;myser.Table = vfd;
&nbsp; &nbsp;myser.SendTable();
&nbsp; &nbsp;sleep(1);
&nbsp; &nbsp;string = myser.ReadData( 8 );
&nbsp; &nbsp;print(string);
&nbsp; &nbsp;vfdrpm=(ToInt(string[4])*256+ToInt(string[5]))*55/100;
&nbsp; &nbsp;print("Rpm &nbsp;read " + &nbsp;vfdrpm );
&nbsp; &nbsp;return vfdrpm;
};
Attachments
screenshot.png
Last edited by Richard Cullin on Thu Jan 05, 2017 2:29 pm, edited 1 time in total.
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4591
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Functional overview

Post by ArtF »

Check if myser.DataWaiting() is a value.

as a test maybe

while( !myser.DataWaiting() ) { yield()};
print( myser.DataWaiting() );
str = myser.GetData(8);
print( str );

just out of curiousity, it may tell me whats failing. I suspect I need to add a
GetHexData function..

Art
Richard Cullin
Old Timer
Posts: 152
Joined: Sat Jun 02, 2012 5:45 am

Re: Functional overview

Post by Richard Cullin »

buff depth 19&nbsp;
&nbsp; Script MCode10() called&nbsp;
attempt to call non function type

unknown(75) : str = myser.GetData();

callstack..
unknown(75): GetVfdSpeed
unknown(23): MCode10
unknown(1): __main
&nbsp;
Variable ScriptError calls with current:1.0000


from&nbsp; this
global GetVfdSpeed = function( )
{

&nbsp; &nbsp; vfd={0x01,0x04,0x03,0x01,0,0,0xA1,0x8E};
&nbsp; &nbsp; myser.Table = vfd;
&nbsp; &nbsp; myser.SendTable();
&nbsp; &nbsp; //sleep(1);

while( !myser.DataWaiting() ) { yield();};
print("buff depth " + myser.DataWaiting() );
str = myser.GetData();
print( "buffer "+str );




&nbsp; &nbsp; string = myser.ReadData( 8 );
&nbsp; &nbsp; print("got this " + string);
&nbsp; &nbsp; vfdrpm=(ToInt(string[4])*256+ToInt(string[5]))*55/100;
&nbsp; &nbsp; print("Rpm&nbsp; read " +&nbsp; vfdrpm );
&nbsp; &nbsp; return vfdrpm;
};




Richard Cullin
Old Timer
Posts: 152
Joined: Sat Jun 02, 2012 5:45 am

Re: Functional overview

Post by Richard Cullin »

buff depth 8&nbsp;
got this &nbsp;
buff depth now 0&nbsp;
&nbsp; Script MCode10() called&nbsp;
operator getind bad operand int for string

unknown(84) :&nbsp; &nbsp; vfdrpm=(ToInt(string[4])*256+ToInt(string[5]))*55/100;

callstack..
unknown(84): GetVfdSpeed
unknown(23): MCode10
unknown(1): __main
&nbsp;
Variable RunState calls with current:1.0000
Variable InScript calls with current:0.0000
Variable ScriptError calls with current:1.0000
Variable Execute calls with current:0.0000


from code

global GetVfdSpeed = function( )
{

&nbsp; &nbsp; vfd={0x01,0x04,0x03,0x01,0,0,0xA1,0x8E};
&nbsp; &nbsp; myser.Table = vfd;
&nbsp; &nbsp; myser.SendTable();
&nbsp; &nbsp; //sleep(1);

while( !myser.DataWaiting() ) { yield();};
print("buff depth " + myser.DataWaiting() );
//str = myser.GetData();
//print( "buffer "+str );




&nbsp; &nbsp; string = myser.ReadData( myser.DataWaiting() );
&nbsp; &nbsp; print("got this " + string);
print("buff depth now " + myser.DataWaiting() );
&nbsp; &nbsp; vfdrpm=(ToInt(string[4])*256+ToInt(string[5]))*55/100;
&nbsp; &nbsp; print("Rpm&nbsp; read " +&nbsp; vfdrpm );
&nbsp; &nbsp; return vfdrpm;
};


User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4591
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Functional overview

Post by ArtF »

Richard:

&nbsp; I think, just as sending text is kinda special, so too is the difference between recieving text, and receiving data.
Ill change the code so that the myser.Table returns the data , itd be much easier to access.

Art
Richard Cullin
Old Timer
Posts: 152
Joined: Sat Jun 02, 2012 5:45 am

Re: Functional overview

Post by Richard Cullin »

thanks art
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4591
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Functional overview

Post by ArtF »

Richard:

&nbsp;New version is online, if you call myser.ReadData() to get a string, at the same time
myser.Table is filled with integers of the incoming values. So to use byte 6,7 youd use

str = myser.ReadData( 8 );
byte6 = myser.Table[6];
byte7 = myser.Table[7]; //assuming byte 0 numbering of course..

Art
Last edited by ArtF on Fri Jan 06, 2017 10:12 am, edited 1 time in total.
Post Reply

Who is online

Users browsing this forum: No registered users and 71 guests