View unanswered posts | View active topics It is currently Thu Sep 29, 2016 1:06 am

 Page 1 of 1 [ 6 posts ]
 Print view Previous topic | Next topic
A bug with structs (robotc 2.01 for the NXT)
Author Message
Expert

Joined: Mon Oct 06, 2008 6:30 pm
Posts: 176
Location: Netherlands
A bug with structs (robotc 2.01 for the NXT)
Hi,

I encountered a problem with structs.
When I use a complex struct it is sometimes impossible to get the value from one of its members and assign that to another variable. Please see the code below and takes special notice to the statement, angle=meter.minA;, this is where te bug is.
Some remarks about the bug and the code. The statement appears twice in the program. Oce in the main task, here it works as expected, angle and dspspeed.minA have the same value. And once in the showmeter function, here angle has value 0, although it has been assigned the value of meter.minA. The funny thing is that when I make the struct less complex, by removing all members except from minA, the code works as expected. This also explains why the example is as big as it is.

 Code:// tmeter stores the information needed to display a single meter on the nxt displaytypedef struct    {   int x;   //x coordinate of the meter axis   int y;   // y coordinate of the meter axis   float minVal;   // minimum value to display   float maxVal;   // maximum value to display   float minA;    // angle for minimum value   float maxA;    // angle for maximum value   int radius;    // radius of the meter   float endX; // X-end position of last drwan meter   float endY; // Y-end position of last drwan meter   float increment; // increment of the scale   string label; // Label to display}    tmeter;// Draws the pointer of the metervoid showmeter(tmeter &meter, float current){   float angle;   angle=meter.minA;                nxtDisplayString(7, "%1.2f, %1.2f", angle,meter.minA);}task main(){   tmeter dspspeed;   dspspeed.x=50;   dspspeed.y=22;   dspspeed.minVal=0;   dspspeed.maxVal=100;   dspspeed.minA=-0.66666*PI;   dspspeed.maxA= 0.66666*PI;   dspspeed.radius=20;   dspspeed.increment=20;   dspspeed.label="";      float angle;   angle=dspspeed.minA;   nxtDisplayString(6, "%1.2f, %1.2f", angle,dspspeed.minA);      showmeter(dspspeed,0);while(true);      }

_________________
My most recent blog: A grain of sugar

Sat Jan 02, 2010 8:25 am

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Re: A bug with structs (robotc 2.01 for the NXT)
Hey Aswin,

I did some checks and it seems to be a problem with the order of the struct's members. Try the following piece of code:
 Code:#define TEST1//#undef TEST1   // uncomment to run the program with the members reversed// Test it with maxA before minA and then flip it and reverse it// ti esrever dna ti pilf neht dna Anim erofeb Axam htiw ti tseTtypedef struct    {#ifdef TEST1     float maxA;   float minA;#else   float minA;   float maxA;#endif // TEST1   } tmeter;void showMin(tmeter &meter){   float angle;   angle=meter.minA;      nxtDisplayString(7, "%1.2f, %1.2f", angle,meter.minA);}void showMax(tmeter &meter){   float angle;   angle=meter.maxA;      nxtDisplayString(2, "%1.2f, %1.2f", angle,meter.maxA);}task main(){   tmeter dspspeed;   dspspeed.minA=-0.66666*PI;   dspspeed.maxA= 0.66666*PI;      float angle;   angle=dspspeed.minA;   nxtDisplayString(6, "%1.2f, %1.2f", angle,dspspeed.minA);   showMin(dspspeed);      angle=dspspeed.maxA;   nxtDisplayString(1, "%1.2f, %1.2f", angle,dspspeed.maxA);   showMax(dspspeed);      while(true);    }

Only the first member will be displayed properly. This seems to be a bit of a compiler issue.

Regards,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Sat Jan 02, 2010 8:56 am
Expert

Joined: Mon Oct 06, 2008 6:30 pm
Posts: 176
Location: Netherlands
Re: A bug with structs (robotc 2.01 for the NXT)
Xander,

It seems you're right. Let's see what the developers think of this.

Aswin

_________________
My most recent blog: A grain of sugar

Sat Jan 02, 2010 11:20 am

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Re: A bug with structs (robotc 2.01 for the NXT)
Aswin,

I mailed Dick and Tim to make them aware of this issue.

Regards,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Sat Jan 02, 2010 11:24 am
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 616
Re: A bug with structs (robotc 2.01 for the NXT)
The fix is done will be included in the next release/patch. This appears to be a day one bug.

It only occurs with float and long variables that are structure elements that are part of a call by reference procedure parameter. And, as noted, when they are not the first element of the structure. And only sometimes -- when the procedure parameter is located in the first 256 words of user variable space.

Tue Jan 05, 2010 1:52 am
Expert

Joined: Mon Oct 06, 2008 6:30 pm
Posts: 176
Location: Netherlands
Re: A bug with structs (robotc 2.01 for the NXT)
It seems I was lucky then to find it . Although these routines used to work in 1.4#.

Glad with the quick response and looking forward to the next release. If you want me to beta test it feel free to ask me (I worked over 15 years as a software engineer).

Aswin

_________________
My most recent blog: A grain of sugar

Tue Jan 05, 2010 3:34 am
Display posts from previous:  Sort by
 Page 1 of 1 [ 6 posts ]

#### Who is online

Users browsing this forum: No registered users and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning