Page 1 of 1

Question on debugging a script

Posted: Wed Jan 27, 2016 12:39 pm
by GlennD
Could you do a simple video on the procedure for debugging a script?

I was adding in a mapping function so you could say put in a spindle speed of 8000 on a 18000 rpm spindle and get the appropriate PWM value out at 0 to 100%

I was guessing that the below would return a double but it does always seem to return a integer.

Code: Select all

global map = function(Val,inMin,inMax,outMin,outMax) 
{
  result = (Val - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
  print ("Map Result " + result);
  return result;
};
The print works for getting the value but was wondering if there was a way to step through the code.

Thanks
Glenn

Woohoo JR member now ;D



Re: Question on debugging a script

Posted: Wed Jan 27, 2016 4:26 pm
by Ya-Nvr-No
Good Job Glenn

I find the best way is to open the script editor then the mainscreen script, then i can step thru and see the actions.

I create some test routines to pass the data and see what is being processed.

shows me that there is no return value to be passed back from the function.

but I might be missing something you are expecting to see.

Code: Select all

global map = function(Val,inMin,inMax,outMin,outMax) 
{
  result = (Val - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
  print ("Map Result " + result);
  r2 = ToFloat(result);
  return r2;
};
Val=2;
inMin=8000;
inMax=18000;
outMin=0.1;
outMax=100;
Val3=GlobalGet("SpindleSpeed");
debug();
v1 = map(Val,inMin,inMax,outMin,outMax);
print ("map value1: "+v1);
v2 = SetPWMDuty_1(2,map(GlobalGet("SpindleSpeed"),8000,18000,0.1,100));
print ("map value2: "+v2);
v3 = SetPWMDuty_1(2,map(Val3,8000,18000,0.1,100));
print ("map value3: "+v3);
debug();
v3 = SetPWMDuty_1(2,map(Val3,8000,18000,0.1,100));
print ("map value3: "+v3);
debug();


Re: Question on debugging a script

Posted: Wed Jan 27, 2016 4:32 pm
by GlennD
Art
Thank you for the video.
Saw some other stuff I didn't know about though.  Zooming of the screen. :)
I had 1.1 still so the debug() wasn't working. 
I thought I had updated last night but guess not.

YNN thank you for the tip.

I post this routine in the shared scripts with some things that might help people later.

Fun stuff..

Glenn


Re: Question on debugging a script

Posted: Wed Jan 27, 2016 4:43 pm
by GlennD
[s]Ok I just down loaded the latest off of the web and it still shows 1.1 and even with the debug in there it isn't dropping into the scripter to step through.
I know it updated the script files since I have to add everything back in.
Really need to copy that directory.[/s]
I wonder if I have something else wrong. 

Glenn

Edit: I did there was one Auggie hung open, when I looked in the task manager.
So it couldn't over write the existing file.  ::)

Re: Question on debugging a script

Posted: Wed Jan 27, 2016 4:47 pm
by GlennD
YNN
Sorry about that missed that you weren't getting a value.
Change out the inMin to something less than the spindle value that is getting passed.
So put in 0 to start instead of 8000. 

Looks like we need to test the value first to make sure it is more than what the inMin is.

Glenn