Doly C++ SDK v1.00
Loading...
Searching...
No Matches
ServoControl/main.cpp

Demonstrates:

  • Initializing ServoControl
  • Controlling servo positions
  • Handling servo-related events
#include <chrono>
#include <thread>
#include <spdlog/spdlog.h>
#include "ServoControl.h"
#include "Helper.h"
void onServoAbort(uint16_t id, ServoId channel)
{
spdlog::info("Servo abort id:{} channel:{}", id, static_cast<uint8_t>(channel));
}
void onServoError(uint16_t id, ServoId channel)
{
spdlog::error("Servo error id:{} channel:{}", id, static_cast<uint8_t>(channel));
}
void onServoComplete(uint16_t id, ServoId channel)
{
spdlog::info("Servo completed id:{} channel:{}", id, static_cast<uint8_t>(channel));
}
int main()
{
// Setup spdlog
spdlog::set_level(spdlog::level::info); // Set as needed
spdlog::flush_on(spdlog::level::trace); // flush everything
// *** IMPORTANT ***
// Stop doly service if running,
// otherwise instance of libraries cause conflict
spdlog::error("Doly service stop failed");
return -1;
}
// Initialize Servo Control
if (ServoControl::init() < 0)
{
spdlog::error("ServoControl init failed");
return -2;
}
// Get ServoControl version
spdlog::info("ServoControl Version:{:.3f}", ServoControl::getVersion());
// Add event listeners
// Test servos
std::this_thread::sleep_for(std::chrono::seconds(3));
// Optional release function; disables servo hold position
// Cleanup
return 0;
}
Shared helper utilities and common types used across the Doly SDK.
Public API for Doly servo control.
ServoId
Servo channel identifiers.
Definition ServoEventListener.h:25
@ SERVO_1
Definition ServoEventListener.h:27
@ SERVO_0
Definition ServoEventListener.h:26
int8_t stopDolyService()
Stop the background Doly service (if running).
int8_t setServo(uint16_t id, ServoId channel, float angle, uint8_t speed, bool invert)
Set a servo target angle.
int8_t release(ServoId channel)
Release servo hold (disable holding torque) for a channel.
float getVersion()
Get current library version.
int8_t dispose()
Dispose/stop the servo subsystem and release resources.
int8_t init()
Initialize the servo subsystem.
void RemoveListenerOnError(void(*onEvent)(uint16_t id, ServoId channel))
void AddListenerOnError(void(*onEvent)(uint16_t id, ServoId channel))
void AddListenerOnComplete(void(*onEvent)(uint16_t id, ServoId channel))
void RemoveListenerOnAbort(void(*onEvent)(uint16_t id, ServoId channel))
void RemoveListenerOnComplete(void(*onEvent)(uint16_t id, ServoId channel))
void AddListenerOnAbort(void(*onEvent)(uint16_t id, ServoId channel))