Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   roboRIO Command Based Problems (http://www.chiefdelphi.com/forums/showthread.php?t=133698)

King Nerd III 29-01-2015 23:45

roboRIO Command Based Problems
 
Has anyone else had problems with the roboRIO deleting Command Based code as soon as teleop is enabled? It's probably the worst problem we've had so far.

kylelanman 30-01-2015 00:56

Re: roboRIO Command Based Problems
 
What do you mean by deleting it?

If the robot code light is turning off then most likely you are not initializing something properly and are getting null pointer exception and crashing your program on the RoboRio.

You can check the driver station log area for errors or you can do "Debug As" instead of "Run As" in eclipse. When your code crashes while debugging it will drop you in to the debugger with a stack trace showing you where the problem is.

If you are still having problems after that then post your code and we can take a look at it.

King Nerd III 30-01-2015 00:59

Re: roboRIO Command Based Problems
 
Quote:

Originally Posted by kylelanman (Post 1435986)
What do you mean by deleting it?

If the robot code light is turning off then most likely you are not initializing something properly and are getting null pointer exception and crashing your program on the RoboRio.

You can check the driver station log area for errors or you can do "Debug As" instead of "Run As" in eclipse. When your code crashes while debugging it will drop you in to the debugger with a stack trace showing you where the problem is.

If you are still having problems after that then post your code and we can take a look at it.

I mean it literally deletes it. The roboRIO says there is no code loaded, even if restarted.

kylelanman 30-01-2015 01:08

Re: roboRIO Command Based Problems
 
What are the steps you are using to deploy your code to the RoboRio?

It is also possible that you are not initializing something properly in robotinit which runs before the robot is enabled.

It is entirely possible that the code is getting deleted as you have suggested but the Robot Code light is indicative of whether or not your program is running oppose to if your program actually exists on the RoboRio.

King Nerd III 30-01-2015 01:10

Re: roboRIO Command Based Problems
 
Quote:

Originally Posted by kylelanman (Post 1435990)
What are the steps you are using to deploy your code to the RoboRio?

It is also possible that you are not initializing something properly in robotinit which runs before the robot is enabled.

It is entirely possible that the code is getting deleted as you have suggested but the Robot Code light is indicative of whether or not your program is running oppose to if your program actually exists on the RoboRio.

We're going to reformat it again, that helped last time. Its annoying, though, as everytime we reformat it something else breaks.

Ben Wolsieffer 30-01-2015 08:59

Re: roboRIO Command Based Problems
 
Are you sure your code is not crashing? When your code crashes, the robot code light will turn off and a stack trace should be printed to the log window in the DS. I doubt it is actually being deleted.

King Nerd III 03-02-2015 11:33

Re: roboRIO Command Based Problems
 
Quote:

Originally Posted by lopsided98 (Post 1436030)
Are you sure your code is not crashing? When your code crashes, the robot code light will turn off and a stack trace should be printed to the log window in the DS. I doubt it is actually being deleted.

We fixed the problem by reformatting it 20 or so times. We also had a problem with a roboRIO where some kid turned it off WHILE IT WAS FORMATTING. Of course we fixed it, but it took a bunch of formatting.
Long story short the lesson here is when in doubt reformat until it works!

Alan Anderson 03-02-2015 11:49

Re: roboRIO Command Based Problems
 
Quote:

Originally Posted by King Nerd III (Post 1437645)
Long story short the lesson here is when in doubt reformat until it works!

I doubt that is good advice. Unless there is something physically wrong with the system, reimaging a roboRIO a bunch of times can't do anything that reimaging it once will do. The class of problems that can be solved with a single reimage step is very small, and they are very rare.

Instead of going for the reimaging/reformatting voodoo, you should troubleshoot your original problem using the tools suggested here by the people trying to help you.

King Nerd III 03-02-2015 11:52

Re: roboRIO Command Based Problems
 
Quote:

Originally Posted by Alan Anderson (Post 1437652)
I doubt that is good advice. Unless there is something physically wrong with the system, reimaging a roboRIO a bunch of times can't do anything that reimaging it once will do. The class of problems that can be solved with a single reimage step is very small, and they are very rare.

Instead of going for the reimaging/reformatting voodoo, you should troubleshoot your original problem using the tools suggested here by the people trying to help you.

It's usually all that works for us. The troubleshooting will help with minor things, but when the robot is turned off mid format? Nothing else would help. Heck, the troubleshooting tools wouldn't even detect the roboRIO.

solopilot 03-02-2015 12:27

Re: roboRIO Command Based Problems
 
Could it be that you are taking too long in a command's execute() function?

King Nerd III 03-02-2015 12:53

Re: roboRIO Command Based Problems
 
Quote:

Originally Posted by solopilot (Post 1437670)
Could it be that you are taking too long in a command's execute() function?

We do occasionally and randomly get an error that says something about MotorSafetyHelper.h not updating fast enough on line 117, but there are two problems. One is that MotorSafetyHelper.h has no line 117, and we start running it. Any ideas?

Ben Wolsieffer 03-02-2015 13:47

Re: roboRIO Command Based Problems
 
Quote:

Originally Posted by King Nerd III (Post 1437673)
We do occasionally and randomly get an error that says something about MotorSafetyHelper.h not updating fast enough on line 117, but there are two problems. One is that MotorSafetyHelper.h has no line 117, and we start running it. Any ideas?

You are getting the MotorSafetyHelper error because you are not updating the motor outputs fast enough so the watchdog timer is expiring. If any execute method blocks for a long time, it will prevent all commands from running, therefore causing a watchdog timeout.

King Nerd III 03-02-2015 13:48

Re: roboRIO Command Based Problems
 
Quote:

Originally Posted by lopsided98 (Post 1437693)
You are getting the MotorSafetyHelper error because you are not updating the motor outputs fast enough so the watchdog timer is expiring. If any execute method blocks for a long time, it will prevent all commands from running, therefore causing a watchdog timeout.

That's what we thought, but it doesn't happen every single time, which confused me. How would we fix that?

Alan Anderson 03-02-2015 14:15

Re: roboRIO Command Based Problems
 
Quote:

Originally Posted by King Nerd III (Post 1437694)
How would we fix that?

That depends on what is making it take too long. We can guess at possible causes, but unless you show us your code we can't give confident help.

Post your code, as Kyle suggested in his first response.

King Nerd III 03-02-2015 14:29

Re: roboRIO Command Based Problems
 
5 Attachment(s)
Quote:

Originally Posted by Alan Anderson (Post 1437713)
That depends on what is making it take too long. We can guess at possible causes, but unless you show us your code we can't give confident help.

Post your code, as Kyle suggested in his first response.

I added the DriveBase subsystem, and the drive command to the post. Tell me what you think.

kylelanman 04-02-2015 00:51

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.

King Nerd III 04-02-2015 00:57

Re: roboRIO Command Based Problems
 
Quote:

Originally Posted by kylelanman (Post 1438064)
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.

Thanks for the tip, but that couldn't be what's causing the error with not updating fast enough. That method isn't even called in the code yet, plus ita autonomous and we only get the error in teleop. Thanks for the tip, though! I'll probably use that!

King Nerd III 10-12-2015 15:22

Re: roboRIO Command Based Problems
 
I know this is an old thread, and I'm replying to myself, but yesterday we figured out the problem. In the Robot.cpp we were calling auto_command->End(); in the TeleOpInit Phase, but we had not given a specific command to auto_command, so when TeleOp was enabled it couldn't end the command and just died... At least that's how I believe we fixed it. Commenting out the auto_command->End() got rid of this problem, so we believe that's what it was.
Hope this helps!
Isaac


All times are GMT -5. The time now is 14:05.

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