Question on debugging a script

C Scripting questions and answers
Post Reply
GlennD
Old Timer
Posts: 80
Joined: Tue Oct 18, 2011 4:19 pm

Question on debugging a script

Post 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


Last edited by Anonymous on Wed Jan 27, 2016 12:49 pm, edited 1 time in total.
Ya-Nvr-No
Old Timer
Posts: 188
Joined: Wed Sep 08, 2010 11:15 am

Re: Question on debugging a script

Post 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();

Attachments
testingMap2.JPG
testingMap.JPG
Last edited by Ya-Nvr-No on Wed Jan 27, 2016 4:42 pm, edited 1 time in total.
GlennD
Old Timer
Posts: 80
Joined: Tue Oct 18, 2011 4:19 pm

Re: Question on debugging a script

Post 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

GlennD
Old Timer
Posts: 80
Joined: Tue Oct 18, 2011 4:19 pm

Re: Question on debugging a script

Post 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.  ::)
Attachments
debugger.PNG
Last edited by Anonymous on Wed Jan 27, 2016 5:11 pm, edited 1 time in total.
GlennD
Old Timer
Posts: 80
Joined: Tue Oct 18, 2011 4:19 pm

Re: Question on debugging a script

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests