Package me.autobot.lib.robot.motors
Class Servo
java.lang.Object
me.autobot.lib.robot.Device
me.autobot.lib.robot.Motor
me.autobot.lib.robot.motors.Servo
- All Implemented Interfaces:
Logger
The servo motor class. This class is used to control a servo motor via the I2C bus.
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
connectToI2C
(int pin) Connects the servo to the I2C bus.protected void
Reports the speed of the servo to the I2C bus.void
setRawSpeed
(double speed) Sets the speed of the servo to a number between 0 and 180.void
setSpeed
(double speed) Sets the speed of the servo to a number between -1 and 1.void
stop()
Stops the servo via setting the speed to 90 (halfway point).Methods inherited from class me.autobot.lib.robot.Motor
brake, connectToSerial, emergencyStop, getAddress, getBus, getIdentifier, inSimulation, invert, isInverted
Methods inherited from class me.autobot.lib.robot.Device
emergencyStopAll, enableSimulation, getCurrent, getParent, getProperties, getProperty, getVoltage, registerDevice, setParent, setProperty
-
Constructor Details
-
Servo
public Servo(int identifier, int address) Creates a new servo with the given address on the default I2C bus.- Parameters:
identifier
- The identifier of the servo.address
- The I2C address of the controller.
-
Servo
public Servo(int identifier, int address, int bus) Creates a new servo with the given address on the given I2C bus.- Parameters:
identifier
- The identifier of the servo.address
- The I2C address of the controller.bus
- The I2C bus the controller is connected to.
-
-
Method Details
-
connectToI2C
public void connectToI2C(int pin) Connects the servo to the I2C bus. This is assuming that the bot has the standard interpreter for the Arduino. If you're using a different interpreter, you'll need to change this method or create a different subclass.- Overrides:
connectToI2C
in classMotor
- Parameters:
pin
- The pin to connect the servo to.
-
setRawSpeed
public void setRawSpeed(double speed) Sets the speed of the servo to a number between 0 and 180.- Parameters:
speed
- The speed to set the servo to.
-
setSpeed
public void setSpeed(double speed) Sets the speed of the servo to a number between -1 and 1. -
stop
public void stop()Stops the servo via setting the speed to 90 (halfway point). -
reportSpeed
protected void reportSpeed()Reports the speed of the servo to the I2C bus.- Overrides:
reportSpeed
in classMotor
-