Content:
OCSMode
- enumOCS_SERVO
- Servo mode (0-360 degrees)OCS_MOTOR
- Constant torque output mode
OCSResponseLevel
- enumOCS_RESPOND_READ_ONLY
- Servo responds only to read and ping commandsOCS_RESPOND_ALL
- Servo responds to all commands
OCSResponse
- structbyte prefix[2]
- Prefix0xFF, 0xFF
byte id
- ID of servobyte length
- Length of instructionbyte instruction
- Instructionint numberOfParameters
- Number of parametersbyte parameters[16]
- Supplementary control information except instructionbyte checksum
- Checksum = ~(ID+Length+Param1+...+ParamN)
OCServo (byte id, SoftwareSerial *serialPort)
id
- ID of servomotorserialPort
- SoftwareSerial port servo connected to
OCServo (byte id, HardwareSerial *serialPort)
id
- ID of servomotorserialPort
- HardwareSerial port servo connected to
void ping()
- Used to read the work state of the servo
OCSResponse ocsRead(byte address, byte length)
address
- Data addresslength
- Read length- Used to read the data inside the servo
OCSResponse ocsWrite(byte address, int paramsNumber, byte *params)
address
- Data addressparamsNumber
- Number of parameters*params
- Pointer to array of parameters- This command is used to write parameters to the servo memory control table
OCSResponse setID(byte new_id)
new_id
- New ID for servo (0-254)- Changes ID of servomotor
void setBaudRate(long baudrate)
baudrate
- New baudrate value- Changes baudrate of servo (supported baud rates: 1M, 500000, 250000, 128000, 115200, 76800, 57600, 38400)
OCSResponse setMaxTorque(int torque)
torque
- Torque value (0-1000)- Sets max output torque (0 - min value, 1000 - max value)
OCSResponse setMode(int mode)
mode
-OCS_SERVO
orOCS_MOTOR
- Sets motor mode
OCSResponse setGoalAngle(int angle, long timeMillis= 0)
angle
- Angle in degrees (0-360)timeMillis=0
- Time to reach goal im ms (0-65535). Default is 0 (maximum speed)- Sets goal angle for servo. It is possible to specify time in milliseconds.
OCSResponse setGoalPosition(int position, long timeMillis = 0)
position
- Goal position (0-4095)timeMillis
- Time to reach goal im ms (0-65535). Default is 0 (maximum speed)- Sets goal angle for servo. It is possible to specify time in milliseconds. Same as setGoalAngle, but has more control of angle.
OCSResponse setOperationTime(long timeMillis)
timeMillis
- Time to reach goal im ms (0-65535). Default is 0 (maximum speed)- Sets time to reach goal. Will be overwritten by setGoalAngle or setGoalPosition.
OCSResponse setResponseDelay(int delayMicros)
delayMicros
- Delay in microseconds (0-510)- Sets response delay.
OCSResponse setResponseLevel(int level)
level
-OCS_RESPOND_READ_ONLY
orOCS_RESPOND_ALL
- Sets level of response.
OCSResponse setMinAngle(int angle)
angle
- Angle (0-4095)- Sets min angle of servo
OCSResponse setMaxAngle(int angle)
angle
- Angle (0-4095)- Sets max angle servo
OCSResponse setMaxVoltage(int voltage)
voltage
- .
OCSResponse setMinVoltage(int voltage)
voltage
- .
OCSResponse setOperationSpeed(long speed)
speed
- Speed of a servo, AD/ms (0-65535)- Sets the speed of the servo.
byte getID()
- Returns ID of a servo
- Returns 255 if error occured
long getBaudRate()
- Returns current baud rate of a servo
- Returns -1 if error occured
int getMaxTorque()
- Returns max torque of a servo
- Returns -1 if error occured
int getMode()
- Returns motor mode
- Returns -1 if error occured.
int getGoalAngle()
- Returns goal angle (0-360 degrees)
int getGoalPosition()
- Returns goal position (0-4095)
long getOperationTime()
- Returns operation time in ms (0-65535)
int getResponseDelay()
- Returns response delay in microseconds (0-510)
int getResponseLevel()
- Returns response level (
OCS_RESPOND_READ_ONLY
orOCS_RESPOND_ALL
)
- Returns response level (
int getMinAngle()
- Returns min angle of servo (0-4095)
int getMaxAngle()
- Returns max angle of servo (0-4095)
int getMaxVoltage()
- .
int getMinVoltage()
- .
long getOperationSpeed()
- Returns operation speed in AD/ms (0-65535)
bool reachedGoal()
- Returns true if servo reached it's goal. Otherwise returns false
void begin(long baudrate=1000000)
baudrate
- Baud rate value. Default is 1M- Sets baudrate value for serial port servo connected to.
- Function
setBaudRate
calls this method inside, so you do not need to do this manually.
void printResponse(OCSResponse response)
response
-OCSResponse
struct with response.- Prints response structure.