code not running on Sim

This forum is for all topics related to Simulator for Arduino v0.98. Please include sample code where possible.

Moderator: Adrian

dhruvdroids
Master Class
Posts: 14
Joined: Tue Dec 25, 2012 6:03 am

code not running on Sim

Postby dhruvdroids » Tue Dec 25, 2012 6:17 am

Hi, I just got the pro version and it seems that that none of my code( running perfectly on my Arduino board ) works on the Sim.
first I have the ''Evaluate called 30 times'' following which I had to break my statements.
next I receive the error " division by zero'' for which I replaced 22/7 with PI and it works.
And then I have incorrect results.


Code: Select all

void joint_space(float p_foot, float q_foot)
{
  int alpha = 188; 
  float p = sqrt(sq(p_foot) + sq(q_foot)); 
  float beta = atan(p_foot/q_foot) * 180*7/22;
  theta_j3 = acos((sq(l1) +sq(l2) -sq(p)) / (2*l1*l2)) * 7*180/22;   
 
  theta_j4 = 180 + asin(l2/p * sin(theta_j3*22/7/180)) * 180*7/22 - beta; 
                                               
  theta_j2 = 355 - (theta_j4-180) - theta_j3;

dhruvdroids
Master Class
Posts: 14
Joined: Tue Dec 25, 2012 6:03 am

Re: code not running on Sim

Postby dhruvdroids » Thu Dec 27, 2012 4:20 am

kindly fix the "evaluate called 30 times " and similar errors, else there will be no point using the Sim since I'll have to break up my entire code to debug, which will be wastage of time.

Simulator_admin
Site Admin
Posts: 239
Joined: Thu Feb 02, 2012 6:07 pm

Re: code not running on Sim

Postby Simulator_admin » Fri Jan 04, 2013 8:24 pm

OK, we had a look at this code, and it appears that the line below causes errors:

Code: Select all

 theta_j3 = acos((sq(l1) +sq(l2) -sq(p)) / (2*l1*l2)) * 7*180/22;   


This happens since acos expects a value between -1 and 1 and it received a number larger than 5 in our test. We have improved the simulator to return 0 if the argument is out of range.

With this line below, l2/p*sin(theta_lj3...) now becomes l2/p*0 which is a divide by zero error.

Code: Select all

theta_j4 = 180 + asin(l2/p * sin(theta_j3*22/7/180)) * 180*7/22 - beta; 


The Evaluate called 30 times error is used to stop the Simulator going into endless loops so it cannot be removed.

dhruvdroids
Master Class
Posts: 14
Joined: Tue Dec 25, 2012 6:03 am

Re: code not running on Sim

Postby dhruvdroids » Sat Jan 05, 2013 4:55 am

This is strange :!: , as the same code is running perfectly on my arduino board. And as for

Code: Select all

 theta_j3 = acos((sq(l1) +sq(l2) -sq(p)) / (2*l1*l2)) * 7*180/22;   
the argument can not be 5, kindly clarify the values you assigned, because with p=127, l1=112, l2=110, the argument is around 0.6

dhruvdroids
Master Class
Posts: 14
Joined: Tue Dec 25, 2012 6:03 am

Re: code not running on Sim

Postby dhruvdroids » Sat Jan 05, 2013 4:57 am

Code: Select all

asin(l2/p * sin(theta_j3*22/7/180))
isn't there the left to right priority of math operation , since l2/p should first occur and then (l2/p) * sin(...) should be performed

dhruvdroids
Master Class
Posts: 14
Joined: Tue Dec 25, 2012 6:03 am

Re: code not running on Sim

Postby dhruvdroids » Sat Jan 05, 2013 5:48 am

I have splitted the statements as follows and it works,
and theta_j3 gives the desired result but theta_j4 = l2/p *theta_j4 gives erroneous result(assigned p_foot = -44, q_foot = 201, l1 =112, l2 = 110) And theta_j4 = 180 + asin(theta_j4) * 180*7/22 - beta still gives error dialogs.

I believe the simulator has issues performing multiple operations in a single statement :idea:

Code: Select all

{
  int alpha = 188;  //orientatio angle of ankle for robo standing at max heighti.e.,230mm hip-joint to ankle-joint
  float p = sqrt(sq(p_foot) + sq(q_foot));  // length of vector from hip C.S to ankle joint
  float beta = atan(p_foot/q_foot) * 180*7/22;// angle made by vector 'p' with vertical
  //theta_j3 = acos((sq(l1) +sq(l2) -sq(p)) / (2*l1*l2)) * 7*180/22;    //angle in degres

  theta_j3 = (sq(l1) +sq(l2) -sq(p))/(2*l1*l2) ;   
  theta_j3 = acos(theta_j3) * 7*180/22;   //angle in degres
 
  //theta_j4 = 180 + asin(l2/p * sin(theta_j3*22/7/180)) * 180*7/22 - beta;  //angle in degrees,
  theta_j4 = sin(theta_j3*PI/180);
  theta_j4 = l2/p *theta_j4 ;                          //180 added to map it to 4 bar calculations
  theta_j4 = 180 + asin(theta_j4) * 180*7/22 - beta;
  theta_j2 = 355 - (theta_j4-180) - theta_j3;  //180 subtracted to get j4 in 1st qdrnt                                               
                                               //355 instead of 360 from fine tunning of ankle
}

Simulator_admin
Site Admin
Posts: 239
Joined: Thu Feb 02, 2012 6:07 pm

Re: code not running on Sim

Postby Simulator_admin » Sun Jan 06, 2013 6:16 pm

Here is the order of precedence for these operators:
'&' // done first
'|'
'+'
'-'
'/'
'*'
%'
'!'
?' // done last

So, an equation like a = b/c*d will find the / or divide first and split the equation into b (divide by) c*d. So:
theta_j4 = l2/p *theta_j4 ; becomes theta_j4 = l2 divide by (p*theta_j4)
Adding brackets will fix this so:
theta_j4 = (l2/p)*theta_j4 will evaluate (l2/p) first

With the equations below, there was a problem where the one line version below gives different answers. Changing the Evaluate limit to 40 removed one error but we still have a different result.
//theta_j3 = acos((sq(l1) +sq(l2) -sq(p)) / (2*l1*l2)) * 7*180/22; //angle in degrees

theta_j3 = (sq(l1) +sq(l2) -sq(p))/(2*l1*l2) ;
theta_j3 = acos(theta_j3) * 7*180/22; //angle in degrees

The error was caused by the Simulator counting the brackets and finding that the right bracket was not at the end of the line and there is a small comment - to protect against errors from (a)+(acos(b)... Anyway, this issue is fixed and will be available with the next release. Thanks for picking up this issue.

dhruvdroids
Master Class
Posts: 14
Joined: Tue Dec 25, 2012 6:03 am

Re: code not running on Sim

Postby dhruvdroids » Sun Jan 06, 2013 9:00 pm

Thanks, I guess the next release is close by. I 'll try out the modifications on my code.

dhruvdroids
Master Class
Posts: 14
Joined: Tue Dec 25, 2012 6:03 am

Re: code not running on Sim

Postby dhruvdroids » Thu Jan 10, 2013 3:15 am

I have downloaded the 98.A but it seems the sim still cant perform operations

Code: Select all

float theta_j3 =acos((sq(112) +sq(110) -sq(203)) / (2*112*110))*(180/PI)
.
when i reduce the no of operations in the statement

Code: Select all

float theta_j3 = acos( -0.67)*180/3.14
I get the desired result. Also

Code: Select all

acos((sq(112) +sq(110) -sq(203)) / (2*112*110))
works fine but on adding the "*(180/PI)" operation give ''evaluate 30 times ...error". Whats wrong that the sim cant perform such basic math...

Simulator_admin
Site Admin
Posts: 239
Joined: Thu Feb 02, 2012 6:07 pm

Re: code not running on Sim

Postby Simulator_admin » Thu Jan 10, 2013 12:13 pm

Yes, still a few bugs. We just added a check brackets function so acos(((sq(l1)+sq(l2)) will give an error message.

With the 180/PI, there is an error with this. When using PI, the number type was not set. A temporary workaround is to use 180.0/PI. This will be fixed with the next version.

We had a few more bugs relating to brackets. We found that simply adding the brackets was not good enough, so have added more code. The next release will happen soon, when we can get as many of these issues fixed as possible. Thanks.


Return to “Version 0.98”

Who is online

Users browsing this forum: Google [Bot] and 1 guest