Skip to content

Commit

Permalink
Docs: add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Eternity0xd3 committed Sep 17, 2024
1 parent c17ab60 commit a021735
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ public int registerTask(Task task) {
return registerTask(task, -1);
}

/**
* Register a task in the task map. All the tasks in the map will be iterated in
* the main loop when it's the right time to do.
*
* @param task the task that need registering.
* @param linkedTaskId the taskId of the linked task. The task being registered will
* be run after the linked task is finished. If nothing provided,
* the registered task will start to run immediately.
* @return the taskId of the registered task.
*/
public int registerTask(Task task, int linkedTaskId) {
task.init();
int taskId = findMinFreeTaskId();
Expand All @@ -67,6 +77,11 @@ public int registerTask(Task task, int linkedTaskId) {
return taskId;
}

/**
* Cancel the task and all the linked-after tasks if necessary.
*
* @param taskId the taskId of the task needs canceling.
*/
public void cancelTask(int taskId) {
Task task = tasks.get(taskId);
if (task == null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ public void scaleRange(double min, double max) {
servo.scaleRange(min, max);
}

/**
* Sets the current position of the servo in a fixed time, expressed as a fraction of
* its available range. If PWM power is enabled for the servo, the servo will attempt
* to move to the indicated position.
*
* @param position the position to which the servo should move, a value in the range [0.0, 1.0]
* @param timeMs the time that the servo will take to move.
* @return a Task object
*/
public Task setPosition(double position, long timeMs) {
final double delta = position - servo.getPosition();
final long iterationCount = timeMs / Task.TICK_MS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,33 @@
public interface Task {
int TICK_MS = 50;

/**
* This method is called in the main loop of OpMode
* It should contain the code of EACH TICK, instead of a loop in it!
*/
void iterate();

/**
* To judge whether the task needs to continue.
* @return Return true when it need to continue, otherwise false.
*/
boolean hasNext();

/**
* This method is called when the task is registered in the TaskOpMode.
*/
default void init() {
}

void iterate();

/**
* The method is called when the task is finished.
*/
default void finish() {
}

boolean hasNext();

/**
* The method is called when the task is canceled.
*/
default void cancel() {
}
}

0 comments on commit a021735

Please sign in to comment.