Functional overview
-
- Old Timer
- Posts: 152
- Joined: Sat Jun 02, 2012 5:45 am
Re: Functional overview
100% SUCCESS
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);
FreeSetSpeed( MySpindleAxis, speed);
print("Frequency set to " + freq );
for (inx=0;inx<6;inx+=1)
{
myser.SendHex(vfd[inx]);
CRC=Crc16(CRC,vfd[inx]);
};
print("the CRC " + CRC);
myser.SendHex(ToInt(CRC/256));
myser.SendHex(ToInt(CRC%256));
};
};
global Crc16 = function(crc,byte_in)
{
//print("CRC " + byte_in );
crc = crc ^ byte_in ;
for (c=0;c<8;c+=1){
if (crc&1)
{
crc= ((crc>>1) ^0xa001 ) ;
}
else
{
crc= crc>>1;
};
};
return ToInt(crc);
};
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);
FreeSetSpeed( MySpindleAxis, speed);
print("Frequency set to " + freq );
for (inx=0;inx<6;inx+=1)
{
myser.SendHex(vfd[inx]);
CRC=Crc16(CRC,vfd[inx]);
};
print("the CRC " + CRC);
myser.SendHex(ToInt(CRC/256));
myser.SendHex(ToInt(CRC%256));
};
};
global Crc16 = function(crc,byte_in)
{
//print("CRC " + byte_in );
crc = crc ^ byte_in ;
for (c=0;c<8;c+=1){
if (crc&1)
{
crc= ((crc>>1) ^0xa001 ) ;
}
else
{
crc= crc>>1;
};
};
return ToInt(crc);
};
Re: Functional overview
Awesome.. amazing how easy it looks after you figure it out , eh? I do like GameMonkey scripting... amazingly powerfull
Art
Art
-
- Old Timer
- Posts: 152
- Joined: Sat Jun 02, 2012 5:45 am
Re: Functional overview
I will let you know if I ever get thereamazing how easy it looks after you figure it out
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 );
for (inx=0;inx<tableCount(vfd);inx+=1)
{
myser.SendHex(vfd[inx]);
CRC=Crc16(CRC,vfd[inx]);
};
print("the CRC " + CRC);
myser.SendHex(ToInt(CRC/256));
myser.SendHex(ToInt(CRC%256));
};
};
// calculate a ccitt 16 bit crc on byte at a time
// preset crc to 0xffff to initialise a new calc
global Crc16 = function(crc,byte_in)
{
//print("CRC " + byte_in );
crc = crc ^ byte_in ;
for (c=0;c<8;c+=1){
if (crc&1)
{
crc= ((crc>>1) ^0xa001 ) ;
}
else
{
crc= crc>>1;
};
};
return ToInt(crc);
};
Re: Functional overview
Thanks Art, but I'm closer to a "glutton for punishment".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.
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. :D
Craig
-
- Old Timer
- Posts: 152
- Joined: Sat Jun 02, 2012 5:45 am
Re: Functional overview
had to make some more changes , vfd was not happy with the data stream from setspeed 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
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 Wednesday, January 04, 2017
// Author rc -- Do not edit above this line
// vfd stuff
// the rs485 port
global myser = Serial();
// open and init the port
global 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()
{
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 spindle control,
//it will use only rs485 port
//to control a the spindle
//on/off spindle, on or off an speed
global SpindleOff = function()
{
vfd= table(0x01,0x03,0x01,0x08,0xF1,0x8E);
myser.Table = vfd;
myser.SendTable();
print("Spindle speed zeroed");
};
//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 )
{
CRC=0xffff;
print("speed set to " + speed);
vfd=table(0x01,0x05,0x03,0,0,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 );
for (inx=0;inx<(tableCount(vfd)-2);inx+=1)
{
CRC=Crc16(CRC,vfd[inx]);
};
// print("the CRC " + CRC);
vfd[7]=ToInt(CRC/256);
vfd[6]=ToInt(CRC%256);
myser.Table = vfd;
myser.SendTable();
};
// calculate a ccitt 16 bit crc on byte at a time
// preset crc to 0xffff to initialise a new calc
global Crc16 = function(crc,byte_in)
{
//print("CRC " + byte_in );
crc = crc ^ byte_in ;
for (c=0;c<8;c+=1){
if (crc&1)
{
crc= ((crc>>1) ^0xa001 ) ;
}
else
{
crc= crc>>1;
};
};
return ToInt(crc);
};
Re: Functional overview
How about something like this
Code: Select all
global SpindleSpeed = function( speed )
{
CRC=0xffff;
print("speed set to " + speed);
vfd={0x0,0x0,0x0,0x0,0x0,0x88,0x0,0x0,0x0};
vfd[0]=0x01;
vfd[1]=0x05;
vfd[2]=0x03;
freq=(speed/55.0)*100;
vfd[3]=ToInt(freq/256);
vfd[4]=ToInt(freq%256);
FreeSetSpeed( MySpindleAxis, speed);
print("Frequency set to : " + freq );
for (inx=0;inx<6;inx+=1)
{
print("vfd ",vfd[inx]);
CRC=Crc16(CRC,vfd[inx]);
}
print("the CRC " + CRC);
vfd[6]=ToInt(CRC%256);
vfd[7]=ToInt(CRC/256);
for (inx=0;inx<8;inx+=1)
{
print("the vfd["+ inx + "] " + vfd[inx]);
}
myser.Table = vfd;
myser.SendTable();
};
Re: Functional overview
Hi:
>>can't figure how to add elements to a table yet either ,that would be useful
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
>>can't figure how to add elements to a table yet either ,that would be useful
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
-
- Old Timer
- Posts: 152
- Joined: Sat Jun 02, 2012 5:45 am
Re: Functional overview
thanks guys
adding elements like this works perfectly
if I wanted to add a speed dro that read the spindle freq say 2 times / sec , are there any 'timers' or such available to schedule calls to dro update function
adding elements like this works perfectly
Code: Select all
global SpindleSpeed = function( speed )
{
CRC=0xffff;
print("speed set to " + speed);
//FreeSetSpeed( MySpindleAxis, speed);
vfd=table(0x01,0x05,0x03);
freq=speed/55.0;
freq=freq*100;
vfd[3]=ToInt(freq/256);
vfd[4]=ToInt(freq%256);
vfd[5]=0;
print("Frequency set to " + freq );
for (inx=0;inx<tableCount(vfd);inx+=1)
{
CRC=Crc16(CRC,vfd[inx]);
};
// print("the CRC " + CRC);
vfd[7]=ToInt(CRC/256);
vfd[6]=ToInt(CRC%256);
myser.Table = vfd;
myser.SendTable();
};
if I wanted to add a speed dro that read the spindle freq say 2 times / sec , are there any 'timers' or such available to schedule calls to dro update function
-
- Old Timer
- Posts: 152
- Joined: Sat Jun 02, 2012 5:45 am
Re: Functional overview
just to complete things the system call back script was altered also as below
Code: Select all
// Library SystemCallBacks
// Created Thursday, December 31, 2015
// Author Art -- Do not edit above this line
// Enter Global vars below this line.
// 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()
{
myser.Close(); // shut vfd port
print( "--System -- System Disabled.");
//shut off any spindle since I use one..
if( lookup("SpindleOff")) { SpindleOff(); };
//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()
{
Vfd_Open(); // open vfd port
print( "--System -- System enabling.");
};
//This script is called whenever
//the user presses RUN if the run was allowed
global OnRun = function()
{
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 )
{
print( "--System -- User has zeroed an axis" );
};
//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 )
{
print( "--System -- User has homed an axis" );
};
//This script is called whenever
//the user regens the toolpath
global OnRegen = function()
{
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()
{
print( "--System -- System has reset Scripting system.");
};
Re: Functional overview
Hi Richard:
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)
{
SpindleFeed =...
sleep(1);
}
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 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");
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
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)
{
SpindleFeed =...
sleep(1);
}
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 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");
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
-
- Old Timer
- Posts: 152
- Joined: Sat Jun 02, 2012 5:45 am
Re: Functional overview
first try at getting some data back from vfd ,although the the vfd accepts the cmd and replies accordingly
myser.ReadData( 8 ) returns nothing :-\
[the vfd takes at least 8mS to reply] see pic for cmd and response
global GetVfdSpeed = function( )
{
vfd={0x01,0x04,0x03,0x01,0,0,0xA1,0x8E};
myser.Table = vfd;
myser.SendTable();
sleep(1);
string = myser.ReadData( 8 );
print(string);
vfdrpm=(ToInt(string[4])*256+ToInt(string[5]))*55/100;
print("Rpm read " + vfdrpm );
return vfdrpm;
};
myser.ReadData( 8 ) returns nothing :-\
[the vfd takes at least 8mS to reply] see pic for cmd and response
global GetVfdSpeed = function( )
{
vfd={0x01,0x04,0x03,0x01,0,0,0xA1,0x8E};
myser.Table = vfd;
myser.SendTable();
sleep(1);
string = myser.ReadData( 8 );
print(string);
vfdrpm=(ToInt(string[4])*256+ToInt(string[5]))*55/100;
print("Rpm read " + vfdrpm );
return vfdrpm;
};
Last edited by Richard Cullin on Thu Jan 05, 2017 2:29 pm, edited 1 time in total.
Re: Functional overview
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
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
-
- Old Timer
- Posts: 152
- Joined: Sat Jun 02, 2012 5:45 am
Re: Functional overview
buff depth 19
Script MCode10() called
attempt to call non function type
unknown(75) : str = myser.GetData();
callstack..
unknown(75): GetVfdSpeed
unknown(23): MCode10
unknown(1): __main
Variable ScriptError calls with current:1.0000
from this
global GetVfdSpeed = function( )
{
vfd={0x01,0x04,0x03,0x01,0,0,0xA1,0x8E};
myser.Table = vfd;
myser.SendTable();
//sleep(1);
while( !myser.DataWaiting() ) { yield();};
print("buff depth " + myser.DataWaiting() );
str = myser.GetData();
print( "buffer "+str );
string = myser.ReadData( 8 );
print("got this " + string);
vfdrpm=(ToInt(string[4])*256+ToInt(string[5]))*55/100;
print("Rpm read " + vfdrpm );
return vfdrpm;
};
Script MCode10() called
attempt to call non function type
unknown(75) : str = myser.GetData();
callstack..
unknown(75): GetVfdSpeed
unknown(23): MCode10
unknown(1): __main
Variable ScriptError calls with current:1.0000
from this
global GetVfdSpeed = function( )
{
vfd={0x01,0x04,0x03,0x01,0,0,0xA1,0x8E};
myser.Table = vfd;
myser.SendTable();
//sleep(1);
while( !myser.DataWaiting() ) { yield();};
print("buff depth " + myser.DataWaiting() );
str = myser.GetData();
print( "buffer "+str );
string = myser.ReadData( 8 );
print("got this " + string);
vfdrpm=(ToInt(string[4])*256+ToInt(string[5]))*55/100;
print("Rpm read " + vfdrpm );
return vfdrpm;
};
-
- Old Timer
- Posts: 152
- Joined: Sat Jun 02, 2012 5:45 am
Re: Functional overview
buff depth 8
got this
buff depth now 0
Script MCode10() called
operator getind bad operand int for string
unknown(84) : vfdrpm=(ToInt(string[4])*256+ToInt(string[5]))*55/100;
callstack..
unknown(84): GetVfdSpeed
unknown(23): MCode10
unknown(1): __main
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( )
{
vfd={0x01,0x04,0x03,0x01,0,0,0xA1,0x8E};
myser.Table = vfd;
myser.SendTable();
//sleep(1);
while( !myser.DataWaiting() ) { yield();};
print("buff depth " + myser.DataWaiting() );
//str = myser.GetData();
//print( "buffer "+str );
string = myser.ReadData( myser.DataWaiting() );
print("got this " + string);
print("buff depth now " + myser.DataWaiting() );
vfdrpm=(ToInt(string[4])*256+ToInt(string[5]))*55/100;
print("Rpm read " + vfdrpm );
return vfdrpm;
};
got this
buff depth now 0
Script MCode10() called
operator getind bad operand int for string
unknown(84) : vfdrpm=(ToInt(string[4])*256+ToInt(string[5]))*55/100;
callstack..
unknown(84): GetVfdSpeed
unknown(23): MCode10
unknown(1): __main
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( )
{
vfd={0x01,0x04,0x03,0x01,0,0,0xA1,0x8E};
myser.Table = vfd;
myser.SendTable();
//sleep(1);
while( !myser.DataWaiting() ) { yield();};
print("buff depth " + myser.DataWaiting() );
//str = myser.GetData();
//print( "buffer "+str );
string = myser.ReadData( myser.DataWaiting() );
print("got this " + string);
print("buff depth now " + myser.DataWaiting() );
vfdrpm=(ToInt(string[4])*256+ToInt(string[5]))*55/100;
print("Rpm read " + vfdrpm );
return vfdrpm;
};
Re: Functional overview
Richard:
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
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
Who is online
Users browsing this forum: No registered users and 5 guests