XRPServo Objects
In this page we will take a look at the robot's arm- at the top of the robot.
The arm is attached onto a Servo, which in this context is a motor that rotates to a specific position when powered. The arm can be detached and reattached, allowing you to use the arm however you see fit.
The arm is important because in Depot Derby, we score game-pieces by placing them in warehouses, depots, and even the center scale. Using an XRP arm is simple, yet a reliable way to score these gamepieces.
Using the XRPServo Object
To create a XRPServo object, you'll need to have a port for the object, which should be on the motor board. Otherwise, it is very similar to creating an XRPMotor object.
XRPServo armServo = new XRPServo(0);To make the XRPServo rotate, you cannot directly set the voltage of the servo, unlike with the XRPMotors. Instead, you have two methods to do make it spin.
setAngle()
setAngle() is an angle that takes one parameter- angle. This method only accepts values between 0 and 180 degrees, and the servo will try to point at this angle. It is similar to setVoltage() of the XRPMotor, giving you more precision over the angle you choose.
setPosition()
setPosition() is similar to setAngle(), except it takes a value between 0 and 1. Similarly to set() for XRPMotors, setPosition() makes the servo rotate to a percentage of its full range. This may be worded confusingly, so here is a comparison between the two.
Here are two lines of code that function the exact same. The servo's range of angles is 0 to 180 degrees, or 0 to 1 in terms of its "position". 90 degrees is half of the servo's full range, so these two statements are the same.
armServo.setAngle(90);
armServo.setPosition(0.5);Last updated