...
The Lynxmotion Smart Servos (LSS) are compact, modular and configurable actuators that provide greater control than standard PWM servos. The servo lineup currently includes three “smart servos” which appear physically the same, sharing the same dimensions and mounting points but differing in maximum torque and speed.
...
The lynx motion has a simple serial protocol for controlling the motor, that is human-readable:
Number sign #
Servo ID number as an integer
Action command (two to three letters, no spaces, capital or lower case)
Configuration value in the correct units with no decimal
End with a control / carriage return '<cr>'
Ex: #5PD1443<cr>
Additional Parts:
...
| Code Block | ||
|---|---|---|
| ||
#include <SoftwareSerial.h>
#define rxPin 8
#define txPin 9
SoftwareSerial mySerial(rxPin, txPin); // Create the new software serial instance
#define LSS_ID 254 // ID 254 to broadcast to every motor on bus
void setup()
{
servoSerialmySerial.begin(115200); // Important! this is the standard speed for talking to LSS
mySerial.print("#0D1500\r"); // this is used to clear the serial buffer
}
void loop()
{
// Loop through each of the 8 LED color (black = 0, red = 1, ..., white = 7)
for (uint8_t LEDCode = 0; LEDCode <= 7; LEDCode++){
// Set the color (session only) of the LSS
// Options are:
// LSS_LED_Black = 0
// LSS_LED_Red = 1
// LSS_LED_Green = 2
// LSS_LED_Blue = 3
// LSS_LED_Yellow = 4
// LSS_LED_Cyan = 5
// LSS_LED_Magenta = 6
// LSS_LED_White = 7
mySerial.print(String("#") + LSS_ID + String("LED") + LEDCode + "\r"); // set LED
delay(1000);
}
} |
...
| Code Block | ||
|---|---|---|
| ||
#include <LSS<SoftwareSerial.h> #include <SoftwareSerial.h> #define rxPin 8 #define txPin 9 SoftwareSerial servoSerialmySerial(8rxPin, 9txPin); // Create the new software serial instance #define LSS_ID ( 254) // ID 254 to broadcast to every motor on bus #define LSS_BAUD (LSS_DefaultBaudvoid setup() { mySerial.begin(115200); // CreateImportant! onethis LSSis objectthe LSSstandard myLSSspeed = LSS(LSS_ID); void setup() { servoSerial.begin(LSS_BAUD); for talking to LSS mySerial.print("#0D1500\r"); // Initializethis theis LSSused busto clear LSS::initBus(servoSerial, LSS_BAUD); Serial.begin(LSS_BAUD); the serial buffer } void loop() { // Move the LSS continuously in one direction myLSSmySerial.wheelRPM(10); delay(5000); print(String("#") + LSS_ID + String("WR") + 10 + "\r"); // Move RPM move delay(5000); // Move the LSS continuously in the oposite direction myLSS.wheelRPM(-10);mySerial.print(String("#") + LSS_ID + String("WR") + -10 + "\r"); // RPM move delay(5000); // faster! myLSSmySerial.wheelRPM(-60); print(String("#") + LSS_ID + String("WR") + -60 + "\r"); // RPM move delay(3000); // go Limp! myLSS.limp(); delay(5000); // mySerial.print(String("#") + LSS_ID + String("L") + "\r"); // Limp delay(5000); // move relative from current position in 1/10° (i.e 100 = 10 degrees) myLSSmySerial.moveRelative(100); delay(5000); print(String("#") + LSS_ID + String("D") + int(60*10) + "\r"); // Movemove to 100 degrees delay(5000); // Move to specific position in 1/10° (i.e 100 = 10 degrees) myLSSmySerial.move(400); delay(7000); }print(String("#") + LSS_ID + String("D") + int(360*10) + "\r"); // move 360 degrees delay(7000); } |
Multiple Servos
For controlling multiple servos, you will first need to give each motor a unique ID. You will need to must attach each motor separately , and modify the code below to change it’s its ID to a value between 0 and 253. Afterwards, the servo will always remember it’s new ID.
| Code Block | ||
|---|---|---|
| ||
#include <LSS.h> #include <SoftwareSerial.h> SoftwareSerial servoSerialmySerial(8, 9); // ID set to default LSS ID = 0 #define LSS_ID_old (254)354 // ID 254 to broadcast to every motor on bus #define LSS_ID (0) // the new ID #define LSS_BAUD (LSS_DefaultBaud) // Create one LSS object LSS myLSS = LSS(LSS_ID); void setup() { // setmySerial.begin(115200); // Important! this is the datastandard ratespeed for thetalking SoftwareSerialto portLSS servoSerialmySerial.begin(LSS_BAUDprint("#0D1500\r"); // this is used to clear the serial buffer servoSerial.print("#0D1500\r"delay(1000); delay(1000);//change ID LSS::initBus(servoSerial, LSS_BAUD); //change ID servoSerial mySerial.print(String("#") + LSS_ID_old + String("CID") + LSS_ID + "\r"); delay(2000); } void loop() { } |
...
| Code Block | ||
|---|---|---|
| ||
#include <LSS<SoftwareSerial.h> #include <SoftwareSerial.h> SoftwareSerial servoSerialmySerial(8, 9); #define LSS_ID1 (1) #define LSS_ID2 (0) #define LSS_BAUD int (LSS_DefaultBaud)direction = //-1; Create twovoid LSSsetup() objects{ LSS myLSS1 = LSS(LSS_ID1 mySerial.begin(115200); LSS// myLSS2Important! = LSS(LSS_ID2); int direction = -1; void setup() { servoSerial.begin(LSS_BAUD); this is the standard speed for talking to LSS mySerial.print("#0D1500\r"); // Initializethis theis LSSused busto clear LSS::initBus(servoSerial, LSS_BAUD); Serial.begin(LSS_BAUD);the serial buffer } void loop() { // motor direction myLSS1.wheelRPM(-direction*60); myLSS2.wheelRPM(60*direction);mySerial.print(String("#") + LSS_ID + String("WR") +-direction*60) + "\r"); // RPM move mySerial.print(String("#") + LSS_ID + String("WR") + 60*direction + "\r"); // RPM move delay(40005000); // reversreverse dierctiondirection direction = -direction; } |
...
A reset may sometimes be needed
| Code Block | ||
|---|---|---|
| ||
#include <LSS.h> #include <SoftwareSerial.h> SoftwareSerial servoSerial(8, 9); // ID set to default LSS ID = 0 #define LSS_ID_old (254) // ID 254 to broadcast to every motor on bus #define LSS_BAUD (LSS_DefaultBaud) LSS_ID 254 // CreateID 254 oneto LSSbroadcast objectto LSSevery myLSSmotor = LSS(LSS_ID);on bus void setup() { mySerial.begin(115200); // Important! //this setis the datastandard ratespeed for thetalking SoftwareSerialto portLSS servoSerialmySerial.begin(LSS_BAUDprint("#0D1500\r"); // this is used to clear the serial buffer servoSerial.print("#0D1500\r"); delay(1000); LSS::initBus(servoSerial, LSS_BAUD); // reset servoSerialmySerial.print(String("#") + LSS_ID_old + String("DEFAULT")+"\r"); delay(500); servoSerialmySerial.print(String("#") + LSS_ID_old + String("CONFIRM")+"\r"); delay(2000); } void loop() { } |
...
TIP: Use the millis() function to find the elapsed time.
Possible Solution: This is one solution , but it could use some improvement: It needs a denounce and a pause without delay function to avoid blocking your code. This solution uses an older arduino library that might need to be updated.
| Code Block | ||
|---|---|---|
| ||
#include <LSS.h>
#include <SoftwareSerial.h>
SoftwareSerial servoSerial(8, 9);
// ID set to default LSS ID = 0
#define LSS_ID (0)
#define LSS_BAUD (LSS_DefaultBaud)
// Create one LSS object
LSS myLSS = LSS(LSS_ID);
int ServoPosition = 0;
bool counting = true;
int resetTime = 0;
int lastMovement;
void setup() {
servoSerial.begin(LSS_BAUD);
// Initialize the LSS bus
LSS::initBus(servoSerial, LSS_BAUD);
Serial.begin(LSS_BAUD);
myLSS.move(0);
// allow time to move to 0 position
delay(3000);
myLSS.setMaxSpeed(600, LSS_SetConfig);
//buttons
pinMode(11, INPUT);
pinMode(10, INPUT);
}
void loop() {
delay(1000);
if (counting) {
int seconds = (millis() - resetTime)/1000; // see below for an explanation of resetTime
ServoPosition = seconds * 60; // if we divide 360 by 60 we get 6.0 degrees
myLSS.move(ServoPosition); // move servo to position
Serial.println(seconds);
lastMovement = millis();
} else {
resetTime = millis() - lastMovement; // this helps us return to the last position of the clock movement
}
// buttons
if (digitalRead(10) == HIGH) {
// stop or start
counting = !counting;
Serial.println("Start/Stop");
// this could be improved on with a debounce!
}
if (digitalRead(11) == HIGH) {
// reset
Serial.println("reset");
myLSS.move(0);
delay(2000);
resetTime = millis(); // we use this to restart our counter from 0
}
} |
...