Announcement

Collapse
No announcement yet.

Incremental Motor Control in Android Studio

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • RedfishRobotics
    replied
    Works perfectly!

    Originally posted by GearTicks View Post
    Here is some untested code that should do what you want:
    Code:
    public class IncrementalPowerOp extends OpMode {
    	private static final double[] POWERS = new double[]{0.0, 0.7, 0.8, 0.9, 1.0};
    	private int currentPowerIndex;
    	private DcMotor motor;
    	private boolean aPressedLast;
    Each time the A button is pressed, it advances to the next power. It assumes your motor is registered as "motor" in the config file.

    Thanks again, once they worked it into the existing opmode that gets the particles to the shooter it worked perfectly.

    Leave a comment:


  • RedfishRobotics
    replied
    Originally posted by GearTicks View Post
    Here is some untested code that should do what you want:
    Code:
    public class IncrementalPowerOp extends OpMode {
    	private static final double[] POWERS = new double[]{0.0, 0.7, 0.8, 0.9, 1.0};
    	private int currentPowerIndex;
    	private DcMotor motor;
    	private boolean aPressedLast;
    Each time the A button is pressed, it advances to the next power. It assumes your motor is registered as "motor" in the config file.
    Thanks! We'll give it a try and report back.

    Leave a comment:


  • GearTicks
    replied
    Here is some untested code that should do what you want:
    Code:
    public class IncrementalPowerOp extends OpMode {
    	private static final double[] POWERS = new double[]{0.0, 0.7, 0.8, 0.9, 1.0};
    	private int currentPowerIndex;
    	private DcMotor motor;
    	private boolean aPressedLast;
    
    
    	public void init() {
    		this.currentPowerIndex = 0;
    		this.motor = (DcMotor)this.hardwareMap.get("motor");
    		this.aPressedLast = false;
    	}
    	public void loop() {
    		final boolean aPressed = this.gamepad1.a;
    		if (aPressed && !this.aPressedLast) this.currentPowerIndex = (this.currentPowerIndex + 1) % POWERS.length;
    		this.aPressedLast = aPressed;
    		this.motor.setPower(POWERS[this.currentPowerIndex]);
    	}
    }
    Each time the A button is pressed, it advances to the next power. It assumes your motor is registered as "motor" in the config file.

    Leave a comment:


  • RedfishRobotics
    started a topic Incremental Motor Control in Android Studio

    Incremental Motor Control in Android Studio

    Hey everyone, hope all your teams are having a great season.

    Our team has developed a single-wheel pitching machine type particle shooter ( https://youtu.be/NrnutuhPUe4 ), and they asked if I thought it was possible to make an incremental speed control (on a single button), so they don't have to use multiple buttons for each speed setting. (with this robot, speed +/- converts to distance from the Vortex).

    As we don't have any "real" programmers on hand (mentors or students), the best I can do in way of a description is this pseudo code...


    On button press

    If motor is not running (stopped, idle, etc.), run at 70%

    If motor is running at 70% change to 80%

    If motor is running at 80% change to 90%

    If motor is running at 90% change to 100%

    If motor is running at 100%, stop motor


    So basically, each time the operator presses the "A" button, the motor increments to one of those 5 states.

    I figured it was something like....

    Power = GetMotorPower (in the init)

    Then in the method, on button press, if Power = 7, Power = Power + 1, etc.


    Any help or resources are really appreciated, as the kids are trying to make it to a scrimmage they were invited to next weekend in Mississippi and just need a little fine tuning.


    Thanks and good luck this season!
Working...
X