saintsrobotics / corebot-2017 Goto Github PK
View Code? Open in Web Editor NEWOur robot code for 2017, featuring coroutines
Our robot code for 2017, featuring coroutines
We had a bug on Saturday. What happened is if we disabled in the middle of our autonomous code and then reenabled, the motors would sometimes continue at the same values they had before and would not accept input. I found a tricky infinite loop and fixed it, and from then on we didn't see the issue again:
581d9e3#diff-2094e283bb3890e841571da6ac09c6b1R133
Here's my attempt at figuring out what the issue is.
Consider the following TaskRunner and example task:
new TaskRunner(
new ExampleTask(),
new UpdateMotorsTask()
);
public class ExampleTask extends Task {
public void run() {
while (true) {
Robot.motors.allDrive.set(1.0);
wait.forFrame();
}
}
}
If you enable the robot, this task will run and work fine. However, if you make the logic slightly more insidious:
public class ExampleTask extends Task {
public void run() {
while (true) {
if (condition) {
continue;
}
Robot.motors.allDrive.set(1.0);
wait.forFrame();
}
}
}
If condition
is true, then this task will get caught in an infinite loop and will not ever wait, and thus will not ever terminate. This loop will continue to run as long as condition is true...
Actually, I can't seem to get something that'd replicate the issue we saw on Saturday.
There is currently no task cancellation policy. For example, RepeatingTask.run method should return when the robot is disabled and/or switches out of the current mode (autonomous/teleop). Currently it never returns (has a while(true)). The iterator logic thread (collection thread) will never exit - will just be stuck waiting for a yield that never returns. It's not clean and it will leak threads each time there is a mode switch (when a new taskRunner instance is created, leaving the old one still hanging around stuck in some Task's yield call.) Suggestion: cancel task, and yield code should throw an exception. This support may already be there in the underlying Generator framework -need to investigate.
Cannot currently dynamically add a Task (after teleop/autonomous operation mode has started). Workaround: add all anticipated tasks during init, and if needed a Task yields until it is triggered by some future "start" condition. Can get tricky if the logical task needs to be run multiple times. We should check if this scenario can possibly arise for the competition robot, and if so try to try to test a comparable scenario earlier rather than later.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.