-
Notifications
You must be signed in to change notification settings - Fork 30
Arduino
Chris Courson edited this page Sep 20, 2020
·
10 revisions
xArm and LeArm servo controller library for Arduino.
Version 1.1
View releases for zip that can be installed through the Arduino IDE.
xArmServoController(xArmMode mode, Stream &serial_port);
The xArmServoController class requires two parameters. The first parameter, mode
defines the type of arm (xArm
or LeArm
) the class instance will interface with. The second parameter is the serial_port
definition and may be HardwareSerial or SoftwareSerial. The baud rate must be set to 9600.
For HardwareSerial Arduino API, refer to Arduino Serial Communication.
For SoftwareSerial Arduino API, refer to Arduino SoftwareSerial Library.
#include <xArmServoController.h>
// define servo controller
xArmServoController xarm = xArmServoController(xArm, Serial1);
void setup() {
// initialize serial port
Serial1.begin(9600);
// Your setup here.
}
void loop() {
// Your code here.
}
#include <SoftwareSerial.h>
#include <xArmServoController.h>
// define servo controller
#define rxPin 2
#define txPin 3
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
xArmServoController xarm = xArmServoController(xArm, mySerial);
void setup() {
// initialize serial port
mySerial.begin(9600);
// Your setup here.
}
void loop() {
// Your code here.
}
struct xArmServo {
uint8_t id;
uint16_t position;
};
#include <xArmServoController.h>
// define servo controller
xArmServoController xarm = xArmServoController(xArm, Serial1);
// define xArmServo object
xArmServo servo;
void setup() {
// initialize serial port
Serial1.begin(9600);
// initialize xArmServo object
servo.servo_id = 1; // Set by property
servo.position = 500; // Set by property
}
void loop() {
// set servo 1 to position 500
xarm.setPosition(servo);
// loop here indefinately
while (true) {}
}
#include <xArmServoController.h>
// define servo controller
xArmServoController xarm = xArmServoController(xArm, Serial1);
// define xArmServo object
xArmServo servo;
void setup() {
// initialize serial port
Serial1.begin(9600);
// initialize xArmServo object
servo = {1, 500}; // Set by array initializer
}
void loop() {
// set servo 1 to position 500
xarm.setPosition(servo);
// loop here indefinately
while (true) {}
}
#include <xArmServoController.h>
// define servo controller
xArmServoController xarm = xArmServoController(xArm, Serial1);
// define xArmServo object
xArmServo servo;
void setup() {
// initialize serial port
Serial1.begin(9600);
// initialize an array xArmServo objects
xArmServo servos[] = {{1, 500}, // Set by array initializer
{2, 500},
{3, 500},
{4, 500},
{5, 500},
{6, 500}};
}
void loop() {
// set servo 1 to position 500
xarm.setPosition(servos);
// loop here indefinately
while (true) {}
}
Command/Link | xArm | LeArm |
---|---|---|
setPosition | ✔️ | ✔️ |
getPosition | ✔️ | |
servoOff | ✔️ | |
actionRun | ✔️ | ✔️ |
actionStop | ✔️ | ✔️ |
actionSpeed | ✔️ | ✔️ |
actionIsRunning | ✔️ | |
serialEvent | ✔️ | |
getBatteryVoltage | ✔️ | ✔️ |
beep | ✔️ | ✔️ |
All assets are under the GNU GENERAL PUBLIC LICENSE and in the public domain unless otherwise noted.