Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added the supervised interfaces #67

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flash3388.flashlib.robot.motion.supervised;

import com.flash3388.flashlib.control.Stoppable;

public interface Supervisable extends Stoppable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supervisable isn't the best name for it. I understand where it comes from, but saying supervision implies something completely different.

Maybe something around Limit?

boolean isInBounds(double input);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.flash3388.flashlib.robot.motion.supervised;

import com.flash3388.flashlib.control.Direction;
import com.flash3388.flashlib.control.Stoppable;
import com.flash3388.flashlib.scheduling.Requirement;

public interface SupervisedMovable extends Stoppable, Supervisable, Requirement {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just extend Movable... You wouldn't need to provide the defaults in that case.

Do the same with the rest.


default void supervisedMove(double speed) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It kinda sounds like it should almost be implicit (the idea that the motion is supervised), such that a call to move is automatically supervised.

Remember that it's an interface, you don't actually need to provide all the capabilities in it with default, simply require someone to implement it to your specifications.

Same for rest.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to do it... I just copied them and didnt finish it lol

if (isInBounds(speed))
move(speed);
else
stop();
}

/**
* Moves along the axis at a given speed.
*
* @param speed speed of motion [-1..1] describing
* percentage of power and direction.
*/
void move(double speed);

/**
* Moves along the axis at a given speed and direction.
*
* @param speed absolute speed of motion [0...1] describing
* percentage of power.
* @param direction direction of motion.
*/
default void move(double speed, Direction direction) {
move(Math.abs(speed) * direction.sign());
}

/**
* Moves along the axis forward at a given speed.
*
* @param speed absolute speed of motion [0...1] describing
* percentage of power.
*/
default void forward(double speed) {
move(speed, Direction.FORWARD);
}

/**
* Moves along the axis backward at a given speed.
*
* @param speed absolute speed of motion [0...1] describing
* percentage of power.
*/
default void backward(double speed) {
move(speed, Direction.BACKWARD);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.flash3388.flashlib.robot.motion.supervised;

import com.flash3388.flashlib.control.Direction;
import com.flash3388.flashlib.scheduling.Requirement;
import com.jmath.vectors.Vector2;

/**
* Describes a component capable of moving along a 2 axes.
*
* @since FlashLib 2.0.0
*/
public interface SupervisedMovable2D extends SupervisedMovable, Requirement {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You copied the documentation.... Fix it to something correct.


default void supervisedMove(Vector2 motionVector) {
if (isInBounds(motionVector))
move(motionVector);
else
stop();
}

boolean isInBounds(Vector2 motionVector);

/**
* Moves along both axes at given speeds.
*
* @param motionVector vector describing speed of motion, where
* each axis [-1...1] describes percentage of power
* and direction.
*/
void move(Vector2 motionVector);

@Override
default void supervisedMove(double speed) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you re-do the default here?

if (isInBounds(speed))
move(speed);
else
stop();
}

/**
* Moves along Y axis at a given speed.
*
* @param speed speed of motion [-1..1] describing percentage of
* power and direction.
*/
@Override
default void move(double speed) {
move(Vector2.polar(speed, 0.0));
}

/**
* Moves along Y axis at a given speed.
*
* @param speed speed of motion [0..1] describing percentage of
* power.
* @param direction direction motion.
*/
@Override
default void move(double speed, Direction direction) {
move(speed * direction.sign());
}

/**
* Moves forward along Y axis at a given speed.
*
* @param speed speed of motion [0..1] describing percentage of
* power.
*/
@Override
default void forward(double speed) {
move(speed, Direction.FORWARD);
}

/**
* Moves backward along Y axis at a given speed.
*
* @param speed speed of motion [0..1] describing percentage of
* power.
*/
@Override
default void backward(double speed) {
move(speed, Direction.BACKWARD);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.flash3388.flashlib.robot.motion.supervised;

import com.flash3388.flashlib.control.Direction;
import com.flash3388.flashlib.control.Stoppable;
import com.flash3388.flashlib.scheduling.Requirement;

public interface SupervisedRotatable extends Stoppable, Supervisable, Requirement {

default void supervisedRotate(double speed) {
if (isInBounds(speed))
rotate(speed);
else
stop();
}

/**
* Rotates the system at a given speed.
*
* @param speed speed of motion [-1..1] describing percentage of power and direction.
*/
void rotate(double speed);

/**
* Rotates the system at a given speed.
*
* @param speed speed of motion [0..1] describing percentage of power.
* @param direction right - forward, left - backward
*/
default void rotate(double speed, Direction direction){
rotate(speed * direction.sign());
}

/**
* Rotates the system at a speed to the right.
*
* <p>Default implementation calls {@link #rotate(double, Direction)} with the given speed
* and {@link Direction#FORWARD} for direction.
* @param speed speed of motion [0..1] describing percentage of power.
*/
default void rotateRight(double speed){
rotate(speed, Direction.FORWARD);
}

/**
* Rotates the system at a speed to the left.
*
* <p>Default implementation calls {@link #rotate(double, Direction)} with the given speed
* and {@link Direction#BACKWARD} for direction.
* @param speed speed speed of motion [0..1] describing percentage of power.
*/
default void rotateLeft(double speed){
rotate(speed, Direction.BACKWARD);
}
}