View unanswered posts | View active topics It is currently Thu Nov 27, 2014 7:15 am






Reply to topic  [ 3 posts ] 
while loop braces not executing? 
Author Message
Rookie

Joined: Fri Mar 16, 2007 9:12 am
Posts: 26
Post while loop braces not executing?
Hi, I'm not sure how to say this exactly, hence the poor subject choice, but I'm trying to get the NXT to check to see if the motors have stopped, then switch tasks to the only other task that's running, which checks a reflected light sensor and then ends its own time slice as well. The idea is to check and switch tasks as quickly as possible while moving. Anyhow, for some reason, the NXT doesn't seem to execute the EndTimeSlice() call in the braces of this (or any other) function's while loop.

Code:
void moveDumb(int distance)
{
  bFloatDuringInactiveMotorPWM = false;
  nMotorEncoder[motorB]       = 0;
  nMotorEncoderTarget[motorB] = 0;
  nMotorEncoder[motorC]            = 0;
  nMotorEncoderTarget[motorC]   = 0;
   int mov = 0;
   float wheelCirc = 18;
   nSyncedMotors            = synchBC;
  nSyncedTurnRatio         = 100;
  nPidUpdateInterval       = 5;
  mov=(distance/wheelCirc)*360;
  if (distance>0)
  {
     nMotorEncoderTarget[motorB] = mov;
     motor[motorB]               = 100;
   }
   else
   {
      nMotorEncoderTarget[motorB] = mov*-1;
      motor[motorB]                        = -100;
   }
  while (nMotorRunState[motorB] != runStateIdle) // wait for action to complete
   {
      EndTimeSlice();
   }
   nSyncedMotors=synchNone;

}


Any ideas? The task that it should be switching to has the same priority as main, which is what would be running this function. The priority is changed to high before it checks the reflected light sensor value and then switched back before ending its timeslice. I'll include it here too, since it's probably easier than reading all the junk I just wrote..
Code:
task edgeDet()
{
   SensorType[lightSensor]=sensorLightActive;
   while(true)
   {
   nSchedulePriority=kHighPriority;
   if (SensorValue[lightSensor]<15)
      StopAllTasks();
   else
   {
      nSchedulePriority=kDefaultTaskPriority;
      EndTimeSlice();
   }
   }
}

The reason I think that the EndTimeSlice isn't happening is because this task never runs (or at least I'm pretty sure it doesn't) during the wheel movement.
Thanks.


Wed Apr 25, 2007 10:54 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post 
I'm reasonably sure that the task scheduling functions all work as expected as there are numerous examples where they perform as expected.
Did you remember to call "StartTask" on the second task. When a program starts up it starts running task "main". If you want other tasks to run then they have to be explicitly started via a call to "startTask"!


Thu Apr 26, 2007 9:07 am
Profile
Rookie

Joined: Fri Mar 16, 2007 9:12 am
Posts: 26
Post 
Here is my task main() where I first start the edgeDet task and then continue. The moveDumb function is called from main, and is as listed above. The turn() function contains similar synchronization and EndTimeSlice() calls inside of the while loops. The main executes as if the edgeDet task is never called, except that the light turns on on the light sensor.

Code:
task main()
{
   int CurrentX=0;
   int CurrentY=0;
   int CurrentAngle=0;
   nSchedulePriority=kHighPriority;
   StartTask(edgeDet);
   nSchedulePriority=kDefaultTaskPriority;
   int xPath[10] = {0,-10,0,0,0,0,0,0,0,0};
   int yPath[10] = {0,-10,0,0,0,0,0,0,0,0};
   int distance = 0;
   int angle =   0;
   //Cannot use due to firmware issues with
   //asin(), acos(), and atan() functions
   //built into the firmware of the NXT
   //GoToPoint(CurrentX, CurrentY, xPath[1],yPath[1], CurrentAngle);
   findAngle(distance, angle);
   if (angle<0)
   {
      angle=(angle-10);
   }
   else angle=(angle+10);
   turn(angle,CurrentAngle);
   moveDumb(distance);
   moveDumb(distance*-1);
   turn(angle * (-1),CurrentAngle);
   nxtDisplayTextLine(1,"Edge Found:%d",angle);
   nxtDisplayTextLine(2,"Distance:%d",distance);
   wait10Msec(1000);
}


Thu Apr 26, 2007 1:12 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.