View unanswered posts | View active topics It is currently Fri Aug 29, 2014 12:19 pm






Reply to topic  [ 6 posts ] 
crashes on download 
Author Message
Rookie

Joined: Sun Jan 13, 2008 6:48 pm
Posts: 5
Post crashes on download
The following code crashes robotc when I try to download it to my NXT, at the point where normally the start/stop pop up appears it just closes down the the application. I've tried loading some of the sample progs. and they are fine. Any help would be much appreciated.
Code:
int iLoop;
bool bRead;

void rotate()
{
   nMotorEncoder[motorA] = 0;
   for (iLoop=0; iLoop<=50; iLoop=iLoop+=10)
   {
     do while (nMotorEncoder[motorA]<=iLoop)
     {
     motor[motorA] = 75;
    motor[motorC] = -75;
    bRead = true;
    }
   }
}
task main()
{
   do
   {
    rotate;
   }
}


Thu Jan 17, 2008 2:32 pm
Profile
Expert
User avatar

Joined: Fri Nov 09, 2007 4:51 am
Posts: 121
Location: Hungary, Europe
Post first try
not bad for the first try, check the following points:

for (iLoop=0; iLoop<=50; iLoop=iLoop+=10)

I assume you wanted to write iLoop = iLoop + 10 then you might have found the more compact way iLoop += 10. In this context it causes only redundancy and no harm, but does not look nice :-)

The following is however surely will not work:

do while (nMotorEncoder[motorA]<=iLoop)
{
motor[motorA] = 75;
motor[motorC] = -75;
bRead = true;
}

there are two types of conditional loops. the first one is the
while( condition ) { core of the loop }
the other one is
do { core of the loop } while ( condition );

your code is the second form without any action within the loop core.
the RobotC will infinitely repeat the do while(...) loop since the motor is not working.

May I propose an alternative architecture:

start the motor (e.g. motor[ motorA ] = required power)

make a loop that waits for the motor encoder to reach the target

stop the motor by setting motor[ motorA ] = 0

also, if you are a beginner, it helps a lot if you have a piece of paper with columns for the variables and try to play the role of the computer.


Thu Jan 17, 2008 5:02 pm
Profile
Expert
User avatar

Joined: Fri Nov 09, 2007 4:51 am
Posts: 121
Location: Hungary, Europe
Post robotC is very fast
I would like to call your attention that robotc is very fast.

what you will see that your robot rotates a bit (more precisely, the motors make almost a half turn, the B in opposite direction) and then it stops.

I can't tell you why the robotc crashes but that requires another investigation (have you tried to compile and download sample programs?)


Thu Jan 17, 2008 5:12 pm
Profile
Rookie

Joined: Sun Jan 13, 2008 6:48 pm
Posts: 5
Post 
Elemes,
Thanks for the advice on the loops, it's most welcome.My main problem is still the crashing, yes I've already tried the sample programmes and they work fine. Thanks again.


Fri Jan 18, 2008 7:59 am
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 602
Post 
When doing function calls in ROBOTC, you may want to call them like functions, as ROBOTC might confuse your function names as reserved words... Also, you do not need just a "do" loop.

I've edited your code just quickly. I'll test it in a bit if I get a chance:


Code:
int iLoop;
bool bRead;

void rotate()
{
   nMotorEncoder[motorA] = 0;
   for (iLoop=0; iLoop<=50; iLoop=iLoop+=10)
   {
     while(nMotorEncoder[motorA]<=iLoop)
     {
     motor[motorA] = 75;
     motor[motorC] = -75;
     bRead = true;
     }
   }
}
task main()
{
    rotate();
}

_________________
Timothy Friez
ROBOTC Developer - SW Engineer
tfriez@robotc.net


Wed Jan 30, 2008 5:08 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post 
ROBOTC compiler was not generating error messages for some of the incorrect syntax in this program. Things like:
1. Bad "do while" syntax (twice)
2. Function name without "()".

These errors meant that the executable file was bad because there was no code generated for task "main".

The fact that task main was empty was the ultimate cause of the crash.

ROBOTC compiler has been fixed to generate error messages.


Wed Mar 05, 2008 1:17 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.