Flexiv RDK APIs  1.9.0
robot.hpp
Go to the documentation of this file.
1 
6 #ifndef FLEXIV_RDK_ROBOT_HPP_
7 #define FLEXIV_RDK_ROBOT_HPP_
8 
9 #include "data.hpp"
10 #include "mode.hpp"
11 #include <vector>
12 #include <memory>
13 #include <exception>
14 #include <map>
15 
16 namespace flexiv {
17 namespace rdk {
18 
24 class Robot
25 {
26 public:
53  Robot(const std::string& robot_sn,
54  const std::vector<std::string>& network_interface_whitelist = {}, bool verbose = true,
55  bool lite = false);
56  virtual ~Robot();
57 
58  //========================================= ACCESSORS ==========================================
63  bool lite() const;
64 
69  bool connected() const;
70 
75  RobotInfo info() const;
76 
81  Mode mode() const;
82 
88 
93  bool stopped() const;
94 
102  bool operational() const;
103 
109 
117  bool busy() const;
118 
123  bool fault() const;
124 
135  bool reduced() const;
136 
148  bool recovery() const;
149 
154  bool estop_released() const;
155 
161 
169 
177  std::vector<RobotEvent> event_log() const;
178 
179  //======================================= SYSTEM CONTROL =======================================
187  void Enable();
188 
199  void Brake(bool engage);
200 
215 
221  void Stop();
222 
235  bool ClearFault(unsigned int timeout_sec = 30);
236 
247 
259  void SetGlobalVariables(const std::map<std::string, FlexivDataTypes>& global_vars);
260 
269  std::map<std::string, FlexivDataTypes> global_variables() const;
270 
280  void LockExternalAxes(bool toggle);
281 
291  void SyncWithPositioner(bool toggle);
292 
302  void SetTimelinessFailureLimit(double percentage = 2.0);
303 
304  //======================================= PLAN EXECUTION =======================================
324  unsigned int index, bool continue_exec = false, bool block_until_started = true);
325 
344  const std::string& name, bool continue_exec = false, bool block_until_started = true);
345 
355  void PausePlan(bool toggle);
356 
364  void StopPlan();
365 
372  std::vector<std::string> plan_list() const;
373 
384 
395  void SetBreakpointMode(bool is_enabled);
396 
408 
421  void SetVelocityScale(unsigned int velocity_scale);
422 
423  //==================================== PRIMITIVE EXECUTION =====================================
451  void ExecutePrimitive(const std::string& primitive_name,
452  const std::map<std::string, FlexivDataTypes>& input_params,
453  bool block_until_started = true);
454 
462  std::map<std::string, FlexivDataTypes> primitive_states() const;
463 
464  //==================================== DIRECT JOINT CONTROL ====================================
480  void StreamJointTorque(const std::vector<double>& torques, bool enable_gravity_comp = true,
481  bool enable_soft_limits = true);
482 
501  void StreamJointPosition(const std::vector<double>& positions,
502  const std::vector<double>& velocities, const std::vector<double>& accelerations);
503 
528  void SendJointPosition(const std::vector<double>& positions,
529  const std::vector<double>& velocities, const std::vector<double>& max_vel,
530  const std::vector<double>& max_acc);
531 
549  void SetJointImpedance(const std::vector<double>& K_q, const std::vector<double>& Z_q = {});
550 
564  void SetMaxContactTorque(const std::vector<double>& max_torques);
565 
582  void SetJointInertiaScale(const std::vector<double>& inertia_scales);
583 
584  //================================== DIRECT CARTESIAN CONTROL ==================================
630  void StreamCartesianMotionForce(const std::array<double, kPoseSize>& pose,
631  const std::array<double, kCartDoF>& wrench = {},
632  const std::array<double, kCartDoF>& velocity = {},
633  const std::array<double, kCartDoF>& acceleration = {});
634 
682  void SendCartesianMotionForce(const std::array<double, kPoseSize>& pose,
683  const std::array<double, kCartDoF>& wrench = {},
684  const std::array<double, kCartDoF>& velocity = {}, double max_linear_vel = 0.5,
685  double max_angular_vel = 1.0, double max_linear_acc = 2.0, double max_angular_acc = 5.0);
686 
708  void SetCartesianImpedance(const std::array<double, kCartDoF>& K_x,
709  const std::array<double, kCartDoF>& Z_x = {0.7, 0.7, 0.7, 0.7, 0.7, 0.7});
710 
729  void SetMaxContactWrench(const std::array<double, kCartDoF>& max_wrench);
730 
754  void SetNullSpacePosture(const std::vector<double>& ref_positions);
755 
778  void SetNullSpaceObjectives(double linear_manipulability = 0.0,
779  double angular_manipulability = 0.0, double ref_positions_tracking = 0.5);
780 
801  void SetForceControlAxis(const std::array<bool, kCartDoF>& enabled_axes,
802  const std::array<double, kCartDoF / 2>& max_linear_vel = {1.0, 1.0, 1.0});
803 
836  const std::array<double, kPoseSize>& T_in_root = {0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0});
837 
859  void SetPassiveForceControl(bool is_enabled);
860 
861  //======================================== IO CONTROL ========================================
872  void SetDigitalOutputs(const std::map<unsigned int, bool>& digital_outputs);
873 
880  std::array<bool, kIOPorts> digital_inputs() const;
881 
882 private:
883  class Impl;
884  std::unique_ptr<Impl> pimpl_;
885 
886  friend class Device;
887  friend class FileIO;
888  friend class Gripper;
889  friend class Maintenance;
890  friend class Model;
891  friend class Safety;
892  friend class Tool;
893  friend class WorkCoord;
894 };
895 
896 } /* namespace rdk */
897 } /* namespace flexiv */
898 
899 #endif /* FLEXIV_RDK_ROBOT_HPP_ */
Interface to control the peripheral device(s) connected to the robot.
Definition: device.hpp:23
Interface to exchange files with the robot. Only certain types of file can be transferred.
Definition: file_io.hpp:19
Interface to control the gripper installed on the robot. Because gripper is also a type of robot devi...
Definition: gripper.hpp:77
Interface to run maintenance operations on the robot.
Definition: maintenance.hpp:19
Interface to obtain certain model data of the robot, including kinematics and dynamics.
Definition: model.hpp:21
Main interface to control the robot, containing several function categories and background services.
Definition: robot.hpp:25
void ExecutePlan(unsigned int index, bool continue_exec=false, bool block_until_started=true)
[Blocking] Execute a plan by specifying its index.
void SetNullSpaceObjectives(double linear_manipulability=0.0, double angular_manipulability=0.0, double ref_positions_tracking=0.5)
[Blocking] Set weights of the three optimization objectives while computing the robot's null-space po...
RobotInfo info() const
[Non-blocking] General information about the robot.
void SetMaxContactTorque(const std::vector< double > &max_torques)
[Blocking] Set maximum contact torques for the robot's joint motion controller used in the joint impe...
void SetJointInertiaScale(const std::vector< double > &inertia_scales)
[Blocking] Set inertia shaping scales for the robot's joint motion controller used in the joint imped...
void SetMaxContactWrench(const std::array< double, kCartDoF > &max_wrench)
[Blocking] Set maximum contact wrench for the motion control part of the Cartesian motion-force contr...
RobotStates states() const
[Non-blocking] Current states data of the robot.
bool recovery() const
[Non-blocking] Whether the robot is in recovery state.
void Brake(bool engage)
[Blocking] Force robot brakes to engage or release during normal operation. Restrictions apply,...
OperationalStatus operational_status() const
[Non-blocking] Current operational status of the robot.
void SetJointImpedance(const std::vector< double > &K_q, const std::vector< double > &Z_q={})
[Blocking] Set impedance properties of the robot's joint motion controller used in the joint impedanc...
void StepBreakpoint()
[Blocking] If breakpoint mode is enabled, step to the next breakpoint. The plan execution will contin...
bool stopped() const
[Non-blocking] Whether the robot has come to a complete stop.
void SetGlobalVariables(const std::map< std::string, FlexivDataTypes > &global_vars)
[Blocking] Set values to global variables that already exist in the robot.
Mode mode() const
[Non-blocking] Current control mode of the robot.
void ExecutePrimitive(const std::string &primitive_name, const std::map< std::string, FlexivDataTypes > &input_params, bool block_until_started=true)
[Blocking] Execute a primitive by specifying its name and parameters, which can be found in the Flexi...
void StreamJointTorque(const std::vector< double > &torques, bool enable_gravity_comp=true, bool enable_soft_limits=true)
[Non-blocking] Continuously stream joint torque commands to the robot.
void SetDigitalOutputs(const std::map< unsigned int, bool > &digital_outputs)
[Blocking] Set one or more digital output ports, including 16 on the control box plus 2 inside the wr...
void StreamCartesianMotionForce(const std::array< double, kPoseSize > &pose, const std::array< double, kCartDoF > &wrench={}, const std::array< double, kCartDoF > &velocity={}, const std::array< double, kCartDoF > &acceleration={})
[Non-blocking] Continuously stream Cartesian motion and/or force commands for the robot to track usin...
void SetVelocityScale(unsigned int velocity_scale)
[Blocking] Set overall velocity scale of robot motions during plan and primitive execution.
std::vector< RobotEvent > event_log() const
[Non-blocking] Robot events stored since the last successful instantiation of this class.
void SetForceControlFrame(CoordType root_coord, const std::array< double, kPoseSize > &T_in_root={0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0})
[Blocking] Set reference frame for force control while in the Cartesian motion-force control modes....
void Stop()
[Blocking] Stop the robot and transit its control mode to IDLE.
void SendJointPosition(const std::vector< double > &positions, const std::vector< double > &velocities, const std::vector< double > &max_vel, const std::vector< double > &max_acc)
[Non-blocking] Discretely send joint position and velocity commands to the robot. The robot's interna...
void SwitchMode(Mode mode)
[Blocking] Switch the robot to a new control mode and wait for the mode transition to finish.
std::map< std::string, FlexivDataTypes > global_variables() const
[Blocking] Existing global variables and their current values.
void PausePlan(bool toggle)
[Blocking] Pause or resume the execution of the current plan.
void SetCartesianImpedance(const std::array< double, kCartDoF > &K_x, const std::array< double, kCartDoF > &Z_x={0.7, 0.7, 0.7, 0.7, 0.7, 0.7})
[Blocking] Set impedance properties of the robot's Cartesian motion controller used in the Cartesian ...
bool reached_timeliness_failure_limit() const
[Non-blocking] Whether the timeliness failure limit has been reached within a 1-second moving window.
bool reduced() const
[Non-blocking] Whether the robot is in reduced state.
void StopPlan()
[Blocking] Stop the execution of the current plan.
bool connected() const
[Non-blocking] Whether the connection with the robot is established.
bool enabling_button_pressed() const
[Non-blocking] Whether the enabling button is pressed.
void SetTimelinessFailureLimit(double percentage=2.0)
[Non-blocking] Set the maximum tolerable percentage of real-time commands that arrived the robot too ...
void SyncWithPositioner(bool toggle)
[Blocking] Sync/unsync the robot TCP's motion with the movement of the positioner (if any) during pri...
void SetForceControlAxis(const std::array< bool, kCartDoF > &enabled_axes, const std::array< double, kCartDoF/2 > &max_linear_vel={1.0, 1.0, 1.0})
[Blocking] Set Cartesian axes to enable force control while in the Cartesian motion-force control mod...
std::map< std::string, FlexivDataTypes > primitive_states() const
[Blocking] Names and values of the executing primitive's state parameters.
std::vector< std::string > plan_list() const
[Blocking] A list of all available plans.
bool operational() const
[Non-blocking] Whether the robot is ready to be operated, which requires the following conditions to ...
void SetBreakpointMode(bool is_enabled)
[Blocking] Enable or disable the breakpoint mode during plan execution. When enabled,...
void LockExternalAxes(bool toggle)
[Blocking] Lock/unlock external axes (if any) during primitive execution, direct joint control,...
void ExecutePlan(const std::string &name, bool continue_exec=false, bool block_until_started=true)
[Blocking] Execute a plan by specifying its name.
Robot(const std::string &robot_sn, const std::vector< std::string > &network_interface_whitelist={}, bool verbose=true, bool lite=false)
[Blocking] Instantiate the robot control interface. RDK services will be started and establish connec...
PlanInfo plan_info() const
[Blocking] Detailed information about the executing plan. Contains plan name, primitive name,...
void StreamJointPosition(const std::vector< double > &positions, const std::vector< double > &velocities, const std::vector< double > &accelerations)
[Non-blocking] Continuously stream joint position, velocity, and acceleration commands to the robot....
void Enable()
[Blocking] Enable the robot. If E-stop is released and there's no fault, the robot will release brake...
bool lite() const
[Non-blocking] Whether this rdk::Robot instance is a lite one.
bool fault() const
[Non-blocking] Whether the robot is in fault state.
void SetPassiveForceControl(bool is_enabled)
[Blocking] Enable or disable passive force control for the Cartesian motion-force control modes....
bool ClearFault(unsigned int timeout_sec=30)
[Blocking] Try to clear minor or critical fault for the robot without a power cycle.
bool estop_released() const
[Non-blocking] Whether the emergency stop (E-stop) is released.
void SendCartesianMotionForce(const std::array< double, kPoseSize > &pose, const std::array< double, kCartDoF > &wrench={}, const std::array< double, kCartDoF > &velocity={}, double max_linear_vel=0.5, double max_angular_vel=1.0, double max_linear_acc=2.0, double max_angular_acc=5.0)
[Non-blocking] Discretely send Cartesian motion and/or force commands for the robot to track using it...
bool busy() const
[Non-blocking] Whether the robot is busy. This includes any user commanded operations that requires t...
void RunAutoRecovery()
[Blocking] Run automatic recovery to bring joints that are outside the allowed position range back in...
std::array< bool, kIOPorts > digital_inputs() const
[Non-blocking] Current reading from all digital input ports, including 16 on the control box plus 2 i...
void SetNullSpacePosture(const std::vector< double > &ref_positions)
[Blocking] Set reference joint positions for the null-space posture control module used in the Cartes...
Interface to manage safety settings of the robot. A password is required to authenticate this interfa...
Definition: safety.hpp:49
Interface to manage tools of the robot. All updates take effect immediately without a power cycle....
Definition: tool.hpp:42
Interface to manage work coordinates of the robot. All updates take effect immediately without a powe...
Definition: work_coord.hpp:20
Header file containing various constant expressions, data structures, and enums.
CoordType
Type of commonly-used reference coordinates.
Definition: data.hpp:65
OperationalStatus
Operational status of the robot. Except for the first two, the other enumerators indicate the cause o...
Definition: data.hpp:40
Mode
Robot control modes. The robot needs to be switched into the correct control mode before the correspo...
Definition: mode.hpp:22
Information of the on-going primitive/plan.
Definition: data.hpp:318
General information about the connected robot.
Definition: data.hpp:114
Robot states data in joint and Cartesian space.
Definition: data.hpp:174