View unanswered posts | View active topics It is currently Wed Oct 01, 2014 4:37 am






Reply to topic  [ 4 posts ] 
RobotCProgram runs when stepped through but not in real time 
Author Message
Rookie

Joined: Tue Jan 20, 2009 5:07 pm
Posts: 4
Post RobotCProgram runs when stepped through but not in real time
Hello,

I am totally new to C and RobotC. I have written the following code which seems to work perfectly when I single step through it. Then when I run the program normally everything wihin the while loop works but once the while loop is exited the final 3 lines- PlaySoundFile("Woops.rso");
nxtDisplayTextLine(4, "fini: %d", bMovement);
wait1Msec(300000);
do not run. Any suggestions would be much apreciated.

Many thanks
Martin

//*!!Sensor, S1, sonarSensor, sensorSONAR, , !!*//
//*!! Sensor S2 touchSensor !!*//

const tSensors sonarSensor = (tSensors) S1; //sensorSONAR //*!!!!*//
const tSensors touchSensor = (tSensors) S2; //sensorTouch //*!!!!*//
//*!!CLICK to edit 'wizard' created sensor & motor configuration. !!*//

//******************************************************************************//
// Obstacle Detect //
// ROBOTC on NXT //
// //
// This program allows robot to move forward until it detects an obstacle or motors stalled/slowed//
// and then stops. //
// //
// Notes //
// //
// 1. The sonar and touch Sensor is mounted on the front of the robot. //
// 2. The encoder is checked to ensure movement is occuring when expected //
// 3. Less movement is expectrd initially when motor first starts //
// //
// Motors & Sensors //
// [I/O Port] [Name] [Type] [Description] //
// Port 1 sonarsensor Sonar Sensor Sonar Sensor //
// Port A none Motor Right Motor //
// Port B none Motor Left Motor //
//******************************************************************************//


task main()
{

int nStartup =1;
int aMovement=10 ;
int bMovement=10 ;
while((SensorValue[sonarSensor] > 30) && ((SensorValue(touchSensor) > 200)) && (aMovement != 0)&& (bMovement != 0))
{
//PlaySoundFile("woops.rso");
aMovement=nMotorEncoder[motorA];
bMovement=nMotorEncoder[motorB];
motor[motorA] = 60; //motor A is run at a 60 power level
motor[motorB] = 60; //motor B is run at a 60 power level
if (nStartup)wait1Msec(30); //If motor starting more time required
else wait1Msec(10); // give time for movement and some encoder counts
nStartup =0;
aMovement=(nMotorEncoder[motorA]-aMovement);
bMovement=(nMotorEncoder[motorB]-bMovement);
nxtDisplayTextLine(2, "Range: %d", SensorValue(sonarSensor));

nxtDisplayTextLine(3, "EncoderA: %d", aMovement);
nxtDisplayTextLine(4, "EncoderB: %d", bMovement);
}
PlaySoundFile("Woops.rso");
nxtDisplayTextLine(4, "fini: %d", bMovement);
wait1Msec(300000);
}


Tue Jan 20, 2009 5:30 pm
Profile
Expert
User avatar

Joined: Mon Oct 06, 2008 6:30 pm
Posts: 176
Location: Netherlands
Post Re: RobotCProgram runs when stepped through but not in real time
IK think it's the number in the wait statement. It is to high for an integer. Maibe it is translated into a negative value. Your program halts immidiately and no sound is heard. While debugging you are slow enough to hear the sound.

Use nwait10 and or a smaller number.

_________________
My most recent blog: A grain of sugar


Wed Jan 21, 2009 7:43 pm
Profile WWW
Rookie

Joined: Tue Jan 20, 2009 5:07 pm
Posts: 4
Post Re: RobotCProgram runs when stepped through but not in real time
Many thanks Aswin,

I reduced the delay and everything was okay. I was a bit surprised you have to put a delay in to hear the sound file play. I had expected the PlaySoundFile function to complete before the next line executed so I was a bit careless when I added the wait function.

Thanks again

Martin


Thu Jan 22, 2009 4:48 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post Re: RobotCProgram runs when stepped through but not in real time
I usually do something like this:
Code:
  PlaySound(soundFastUpwardTones);
  while (bSoundActive) {}
  PlaySound(soundDownwardTones);
  while (bSoundActive) {}


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]


Thu Jan 22, 2009 5:18 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 4 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.