Go to Post Everyone please breathe before you post. - Jessica Boucher [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #16   Spotlight this post!  
Unread 02-04-2015, 12:51 AM
kylelanman's Avatar
kylelanman kylelanman is offline
Programming Mentor
AKA: Kyle
FRC #2481 (Roboteers)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2007
Location: Tremont Il
Posts: 185
kylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to all
Re: roboRIO Command Based Problems

Code:
 48void DriveBase::AutoDriveTurn(float speed, float angle){
 49         while(drive_gyro->GetAngle() >= angle){
 50                 fl_motor->Set(speed);
 51                 fr_motor->Set(speed);
 52                 bl_motor->Set(speed);
 53                 br_motor->Set(speed);
 54         }
 55 }
This function is going to cause you problems. This is called a "tight loop" and will consume all of your CPU power while blocking your main thread. Because there is no delay the CPU is going to execute the loop as fast as it possibly can. It will likely take the CPU to 100% and then start dropping control packets from the driver station. On top of that while you are in the loop none of your other commands or code in the main thread will be running.

The better way to do this that won't cause you problems is to use a command.

Code:
 32 class AutoDriveTurnCommand() {
 33 private:
 34     double mSpeed;
 35     double mAngle;
 36 public:
 37     AutoDriveTurnCommand(double speed, double angle) {
 38         mSpeed = speed;
 39         mAngle = angle;
 40     }
 41     void Initialize() {
 42         Robot::drivebase->DriveTank(speed, speed);
 43     }
 44     void Execute() {}
 45     bool IsFinished() {
 46         return Robot::drivebase->GetGyroAngle() < mAngle;
 47     }
 48     void End() {
 49         Robot::drivebase->DriveTank(0, 0);
 50     }
 51     void Interrupted() {
 52         End();
 53     }
 54 };
For this to work you will need to define a function in DriveBase called GetGyroAngle that returns the angle of the gyro.
__________________
"May the coms be with you"

Is this a "programming error" or a "programmer error"?

Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 10:51 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi