3#include "rby1-sdk/version.h"
5#include <condition_variable>
9#include "control_manager_state.h"
10#include "dynamics/robot.h"
14#include "robot_command_builder.h"
15#include "robot_command_feedback.h"
16#include "robot_info.h"
17#include "robot_state.h"
53class SerialStreamImpl;
68class RBY1_SDK_API
Robot :
public std::enable_shared_from_this<Robot<T>> {
78 static std::shared_ptr<Robot<T>>
Create(std::string address);
98 bool Connect(
int max_retries = 5,
int timeout_ms = 1000, std::function<
bool()> signal_check =
nullptr);
143 bool PowerOn(
const std::string& dev_name)
const;
167 bool ServoOn(
const std::string& dev_name)
const;
221 bool SetPositionPIDGain(
const std::string& dev_name, uint16_t p_gain, uint16_t i_gain, uint16_t d_gain)
const;
387 void StartLogStream(
const std::function<
void(
const std::vector<Log>&)>& cb,
double rate);
479 bool SetParameter(
const std::string& name,
const std::string& value,
bool write_db =
true);
489 [[deprecated(
"Use FactoryResetParameter() instead.")]]
490 bool ResetParameterToDefault(
const std::string& name)
const;
492 [[deprecated(
"Use FactoryResetAllParameters() instead.")]]
493 void ResetAllParametersToDefault()
const;
572 std::shared_ptr<dyn::Robot<T::kRobotDOF>>
GetDynamics(
const std::string& urdf_model =
"");
585 bool blinking =
false,
double blinking_freq = 1 );
592 std::tuple<struct timespec, std::string, std::string>
GetSystemTime()
const;
601 bool SetSystemTime(
struct timespec utc_time, std::optional<std::string> time_zone = std::nullopt)
const;
619 bool SetBatteryConfig(
double cutoff_voltage,
double fully_charged_voltage,
const std::array<double, 4>& coefficients);
663 bool ConnectWifi(
const std::string& ssid,
const std::string& password =
"",
bool use_dhcp =
true,
664 const std::string& ip_address =
"",
const std::string& gateway =
"",
665 const std::vector<std::string>& dns = {})
const;
698 std::unique_ptr<SerialStream>
OpenSerialStream(
const std::string& device_path,
int buadrate,
int bytesize,
699 char parity,
int stopbits)
const;
708 bool DownloadFile(
const std::string& path, std::ostream& output)
const;
720 explicit Robot(std::string address);
723 std::shared_ptr<RobotImpl<T>> impl_;
785 std::unique_ptr<RobotCommandHandlerImpl<T>> impl_;
860 std::unique_ptr<RobotCommandStreamHandlerImpl<T>> impl_;
875 Eigen::Vector<bool, T::kRobotDOF> mode{Eigen::Vector<bool, T::kRobotDOF>::Constant(
false)};
877 Eigen::Vector<double, T::kRobotDOF> target{Eigen::Vector<double, T::kRobotDOF>::Zero()};
879 Eigen::Vector<unsigned int, T::kRobotDOF> feedback_gain{Eigen::Vector<unsigned int, T::kRobotDOF>::Zero()};
881 Eigen::Vector<double, T::kRobotDOF> feedforward_torque{Eigen::Vector<double, T::kRobotDOF>::Zero()};
898 Eigen::Vector<bool, T::kRobotDOF> is_ready{Eigen::Vector<bool, T::kRobotDOF>::Constant(
false)};
900 Eigen::Vector<double, T::kRobotDOF> position{Eigen::Vector<double, T::kRobotDOF>::Zero()};
902 Eigen::Vector<double, T::kRobotDOF> velocity{Eigen::Vector<double, T::kRobotDOF>::Zero()};
904 Eigen::Vector<double, T::kRobotDOF> current{Eigen::Vector<double, T::kRobotDOF>::Zero()};
906 Eigen::Vector<double, T::kRobotDOF> torque{Eigen::Vector<double, T::kRobotDOF>::Zero()};
941 Color(uint8_t _r, uint8_t _g, uint8_t _b) : r(_r), g(_g), b(_b) {}
1070 explicit SerialStream(std::unique_ptr<SerialStreamImpl> impl);
1072 std::unique_ptr<SerialStreamImpl> impl_;
1074 template <
typename T>
Definition robot_command_builder.h:730
Definition robot_command_feedback.h:395
Robot command handler.
Definition robot.h:734
bool GetStatus() const
Get gRPC status.
void Wait()
Wait for the command execution to complete.
void Cancel()
Cancel the command execution.
bool IsDone() const
Check if the command execution is complete.
bool WaitFor(int timeout_ms)
Wait for the command execution with timeout.
RobotCommandFeedback Get()
Wait for the command execution and get feedback.
Robot command stream handler for continuous command sending.
Definition robot.h:800
void Wait()
Wait for the command stream to complete.
bool WaitFor(int timeout_ms)
Wait for the command stream to complete with timeout.
RobotCommandFeedback SendCommand(const RobotCommandBuilder &builder, int timeout_ms=1000)
Send a command through the stream.
RobotCommandFeedback RequestFeedback(int timeout_ms=1000)
Request feedback from the current command stream.
bool IsDone() const
Check if the command stream is complete.
Robot control interface.
Definition robot.h:68
std::vector< SerialDevice > GetSerialDeviceList() const
Get list of available serial devices on the robot.
bool ResetBatteryConfig() const
Reset battery configuration to default.
std::string GetAddress()
Get the robot's network address.
ControlManagerState GetControlManagerState() const
Get control manager state.
std::vector< WifiNetwork > ScanWifi() const
Scan for available WiFi networks.
std::vector< std::string > GetFaultLogList() const
Get fault log list.
void StartStateUpdate(const std::function< void(const RobotState< T > &)> &cb, double rate)
Start state update callback.
bool ServoOff(const std::string &dev_name) const
Disable servo control for a device.
std::tuple< struct timespec, std::string, std::string > GetSystemTime() const
Get robot system time.
bool BrakeEngage(const std::string &dev_name) const
Engage the brake for a device.
bool SyncTime()
Synchronize time with the robot.
bool ResetOdometry(double angle, const Eigen::Vector< double, 2 > &position)
Reset odometry to specified values.
bool ResetNetworkSetting() const
Reset network settings to default.
bool SetParameter(const std::string &name, const std::string &value, bool write_db=true)
Set a robot parameter.
bool SetPositionDGain(const std::string &dev_name, uint16_t d_gain) const
Set position derivative gain for a device.
bool ResetFaultControlManager() const
Reset fault in the control manager.
void StopLogStream()
Stop log stream callback.
bool PowerOn(const std::string &dev_name) const
Power on a device.
bool Connect(int max_retries=5, int timeout_ms=1000, std::function< bool()> signal_check=nullptr)
Attempts to establish a connection with the robot.
std::optional< WifiStatus > GetWifiStatus() const
Get WiFi connection status.
void StopStateUpdate()
Stop state update callback.
bool IsServoOn(const std::string &dev_name) const
Check if servo control is enabled for a device.
bool DisconnectWifi() const
Disconnect from WiFi network.
bool ImportRobotModel(const std::string &name, const std::string &model) const
Import robot model.
rb::PIDGain GetPositionPIDGain(const std::string &dev_name) const
Get position PID gain for a specific device.
std::string GetParameter(const std::string &name) const
Get a robot parameter value.
std::vector< Log > GetLastLog(unsigned int count) const
Get last log entries.
RobotInfo GetRobotInfo() const
Retrieves static information about the robot.
bool SetPositionIGain(const std::string &dev_name, uint16_t i_gain) const
Set position integral gain for a device.
void FactoryResetAllParameters() const
Factory reset all parameters to their default values.
std::unique_ptr< RobotCommandStreamHandler< T > > CreateCommandStream(int priority=1)
Create a command stream for continuous command sending.
bool SetPositionPIDGain(const std::string &dev_name, uint16_t p_gain, uint16_t i_gain, uint16_t d_gain) const
Set position PID gains for a device.
bool DownloadFileToCallback(const std::string &path, std::function< void(const char *, size_t)> on_chunk) const
Download a file from the robot using a callback function.
bool StartTimeSync(long period_sec=10)
Start time synchronization.
bool PowerOff(const std::string &dev_name) const
Power off a device.
bool DownloadFile(const std::string &path, std::ostream &output) const
Download a file from the robot.
static std::shared_ptr< Robot< T > > Create(std::string address)
Create a robot instance.
bool SetToolFlangeDigitalOutput(const std::string &name, unsigned int channel, bool state) const
Set the digital output state of a specific channel on the tool flange.
bool SetBatteryLevel(double level) const
Set battery level.
void ResetAllParameters() const
Reset all parameters to their default values.
bool EnableControlManager(bool unlimited_mode_enabled=false) const
Enable the control manager.
std::vector< rb::PIDGain > GetLeftArmPositionPIDGains() const
Get left arm position PID gains.
void Disconnect()
Disconnect from the robot.
std::string GetRobotModel() const
Get robot model information.
bool CancelControl() const
Cancel current control operation.
double GetTimeScale() const
Get the current time scale factor.
RobotState< T > GetState() const
Get current robot state.
bool SetPositionPGain(const std::string &dev_name, uint16_t p_gain) const
Set position proportional gain for a device.
std::shared_ptr< dyn::Robot< T::kRobotDOF > > GetDynamics(const std::string &urdf_model="")
Get robot dynamics model.
bool StopTimeSync()
Stop time synchronization.
bool ResetParameter(const std::string &name) const
Reset a parameter to its default value.
bool ConnectWifi(const std::string &ssid, const std::string &password="", bool use_dhcp=true, const std::string &ip_address="", const std::string &gateway="", const std::vector< std::string > &dns={}) const
Connect to WiFi network.
void StartStateUpdate(const std::function< void(const RobotState< T > &, const ControlManagerState &)> &cb, double rate)
Start state update callback with control manager state.
bool Control(std::function< ControlInput< T >(const ControlState< T > &)> control, int port=0, int priority=1)
Start a blocking real-time control loop using a custom control callback.
bool SetToolFlangeOutputVoltage(const std::string &name, int voltage) const
Set tool flange output voltage.
bool SetLEDColor(const Color &color, double duration=1, double transition_time=0, bool blinking=false, double blinking_freq=1)
Set LED color.
bool IsPowerOn(const std::string &dev_name) const
Check if a device is powered on.
void StartLogStream(const std::function< void(const std::vector< Log > &)> &cb, double rate)
Start log stream callback.
bool HasEstablishedTimeSync()
Check if time synchronization has been established.
bool SetBatteryConfig(double cutoff_voltage, double fully_charged_voltage, const std::array< double, 4 > &coefficients)
Set battery configuration.
bool DisableControlManager() const
Disable the control manager.
bool WaitForControlReady(long timeout_ms) const
Wait until the robot is ready to accept control commands.
std::vector< std::pair< std::string, int > > GetParameterList() const
Get list of available parameters.
bool IsConnected() const
Checks whether the robot is currently connected.
bool SetPresetPosition(const std::string &joint_name) const
Set preset position for a joint (only available for PVL-based motors).
bool SetToolFlangeDigitalOutputDual(const std::string &name, bool state_0, bool state_1) const
Set the digital output states of two channels on the tool flange simultaneously.
std::unique_ptr< RobotCommandHandler< T > > SendCommand(const RobotCommandBuilder &builder, int priority=1)
Send a command to the robot.
std::vector< rb::PIDGain > GetTorsoPositionPIDGains() const
Get torso position PID gains.
std::unique_ptr< SerialStream > OpenSerialStream(const std::string &device_path, int buadrate, int bytesize, char parity, int stopbits) const
Open a serial stream.
std::vector< rb::PIDGain > GetRightArmPositionPIDGains() const
Get right arm position PID gains.
bool SetPositionPIDGain(const std::string &dev_name, const rb::PIDGain &pid_gain) const
Set position PID gains for a device.
bool FactoryResetParameter(const std::string &name) const
Factory reset a parameter to its default value.
bool ServoOn(const std::string &dev_name) const
Enable servo control for a device.
double SetTimeScale(double time_scale) const
Set the time scale for motion execution.
bool SetSystemTime(struct timespec utc_time, std::optional< std::string > time_zone=std::nullopt) const
Set robot system time.
bool BrakeRelease(const std::string &dev_name) const
Release the brake for a device.
bool HomeOffsetReset(const std::string &dev_name) const
Reset home offset for a device.
std::vector< rb::PIDGain > GetHeadPositionPIDGains() const
Get head position PID gains.
Serial communication stream interface.
Definition robot.h:969
bool IsOpened() const
Check if the serial port is opened.
bool IsCancelled() const
Check if the serial stream has been cancelled.
bool Write(const char *data, int n)
Write binary data to the serial port.
bool Write(const char *data)
Write null-terminated string data to the serial port.
bool WriteByte(char ch)
Write a single byte to the serial port.
bool Write(const std::string &data)
Write string data to the serial port.
void SetReadCallback(const std::function< void(const std::string &)> &cb)
Set callback function for incoming data.
bool WaitFor(int timeout_ms) const
Wait for the serial stream to complete with timeout.
void Wait() const
Wait for the serial stream to complete.
bool IsDone() const
Check if the serial stream is done.
void Disconnect() const
Disconnect from the serial device.
bool Connect(bool verbose) const
Connect to the serial device.
RGB color representation.
Definition robot.h:928
Color()
Construct a Color instance with default values (0, 0, 0).
Definition robot.h:932
Color(uint8_t _r, uint8_t _g, uint8_t _b)
Construct a Color instance with specified RGB values.
Definition robot.h:941
Definition control_manager_state.h:7
Robot control state information.
Definition robot.h:894
PID gain configuration.
Definition robot.h:914
uint16_t i_gain
Integral gain value.
Definition robot.h:918
uint16_t d_gain
Derivative gain value.
Definition robot.h:920
uint16_t p_gain
Proportional gain value.
Definition robot.h:916
Definition robot_info.h:27
Definition robot_state.h:94
Serial device information.
Definition robot.h:956
std::string path
Device path (e.g., "/dev/ttyUSB0").
Definition robot.h:958
std::string description
Device description.
Definition robot.h:960