libfranka 0.18.0
FCI C++ API
Loading...
Searching...
No Matches
robot.h
Go to the documentation of this file.
1// Copyright (c) 2023 Franka Robotics GmbH
2// Use of this source code is governed by the Apache-2.0 license, see LICENSE
3#pragma once
4
5#include <functional>
6#include <memory>
7#include <mutex>
8#include <string>
9
11#include <franka/duration.h>
14#include <franka/robot_state.h>
15#include <research_interface/robot/service_types.h>
16#include <franka/commands/get_robot_model_command.hpp>
17
22namespace franka {
23
24class Model;
25
26class ActiveControlBase;
27
68class Robot {
69 public:
73 static constexpr size_t kNumJoints = 7;
74
78 using ServerVersion = uint16_t;
79
92 explicit Robot(const std::string& franka_address,
93 RealtimeConfig realtime_config = RealtimeConfig::kEnforce,
94 size_t log_size = 50);
95
101 Robot(Robot&& other) noexcept;
102
110 Robot& operator=(Robot&& other) noexcept;
111
115 virtual ~Robot() noexcept;
116
180 void control(std::function<Torques(const RobotState&, franka::Duration)> control_callback,
181 bool limit_rate = false,
182 double cutoff_frequency = kDefaultCutoffFrequency);
183
209 std::function<Torques(const RobotState&, franka::Duration)> control_callback,
210 std::function<JointPositions(const RobotState&, franka::Duration)> motion_generator_callback,
211 bool limit_rate = false,
212 double cutoff_frequency = kDefaultCutoffFrequency);
213
239 std::function<Torques(const RobotState&, franka::Duration)> control_callback,
240 std::function<JointVelocities(const RobotState&, franka::Duration)> motion_generator_callback,
241 bool limit_rate = false,
242 double cutoff_frequency = kDefaultCutoffFrequency);
243
269 std::function<Torques(const RobotState&, franka::Duration)> control_callback,
270 std::function<CartesianPose(const RobotState&, franka::Duration)> motion_generator_callback,
271 bool limit_rate = false,
272 double cutoff_frequency = kDefaultCutoffFrequency);
273
298 void control(std::function<Torques(const RobotState&, franka::Duration)> control_callback,
299 std::function<CartesianVelocities(const RobotState&, franka::Duration)>
300 motion_generator_callback,
301 bool limit_rate = false,
302 double cutoff_frequency = kDefaultCutoffFrequency);
303
327 std::function<JointPositions(const RobotState&, franka::Duration)> motion_generator_callback,
328 ControllerMode controller_mode = ControllerMode::kJointImpedance,
329 bool limit_rate = false,
330 double cutoff_frequency = kDefaultCutoffFrequency);
331
355 std::function<JointVelocities(const RobotState&, franka::Duration)> motion_generator_callback,
356 ControllerMode controller_mode = ControllerMode::kJointImpedance,
357 bool limit_rate = false,
358 double cutoff_frequency = kDefaultCutoffFrequency);
359
383 std::function<CartesianPose(const RobotState&, franka::Duration)> motion_generator_callback,
384 ControllerMode controller_mode = ControllerMode::kJointImpedance,
385 bool limit_rate = false,
386 double cutoff_frequency = kDefaultCutoffFrequency);
387
410 void control(std::function<CartesianVelocities(const RobotState&, franka::Duration)>
411 motion_generator_callback,
412 ControllerMode controller_mode = ControllerMode::kJointImpedance,
413 bool limit_rate = false,
414 double cutoff_frequency = kDefaultCutoffFrequency);
415
440 void read(std::function<bool(const RobotState&)> read_callback);
441
455
470 auto getRobotModel() -> std::string;
471
478 auto getUpperJointVelocityLimits(const std::array<double, kNumJoints>& joint_positions)
479 -> std::array<double, kNumJoints>;
480
487 auto getLowerJointVelocityLimits(const std::array<double, kNumJoints>& joint_positions)
488 -> std::array<double, kNumJoints>;
489
526 void setCollisionBehavior(const std::array<double, 7>& lower_torque_thresholds_acceleration,
527 const std::array<double, 7>& upper_torque_thresholds_acceleration,
528 const std::array<double, 7>& lower_torque_thresholds_nominal,
529 const std::array<double, 7>& upper_torque_thresholds_nominal,
530 const std::array<double, 6>& lower_force_thresholds_acceleration,
531 const std::array<double, 6>& upper_force_thresholds_acceleration,
532 const std::array<double, 6>& lower_force_thresholds_nominal,
533 const std::array<double, 6>& upper_force_thresholds_nominal);
534
561 void setCollisionBehavior(const std::array<double, 7>& lower_torque_thresholds,
562 const std::array<double, 7>& upper_torque_thresholds,
563 const std::array<double, 6>& lower_force_thresholds,
564 const std::array<double, 6>& upper_force_thresholds);
565
578 const std::array<double, 7>& K_theta); // NOLINT(readability-identifier-naming)
579
595 const std::array<double, 6>& K_x); // NOLINT(readability-identifier-naming)
596
611 void setGuidingMode(const std::array<bool, 6>& guiding_mode, bool elbow);
612
625 void setK(const std::array<double, 16>& EE_T_K); // NOLINT(readability-identifier-naming)
626
642 void setEE(const std::array<double, 16>& NE_T_EE); // NOLINT(readability-identifier-naming)
643
660 void setLoad(double load_mass,
661 const std::array<double, 3>& F_x_Cload, // NOLINT(readability-identifier-naming)
662 const std::array<double, 9>& load_inertia);
663
673
685 virtual std::unique_ptr<ActiveControlBase> startTorqueControl();
686
701 const research_interface::robot::Move::ControllerMode& control_type);
702
718 const research_interface::robot::Move::ControllerMode& control_type,
719 const std::optional<std::vector<double>>& maximum_velocities);
720
734 const research_interface::robot::Move::ControllerMode& control_type);
735
749 const research_interface::robot::Move::ControllerMode& control_type);
750
765 const research_interface::robot::Move::ControllerMode& control_type);
766
776 void stop();
777
791
792 // Loads the model library for the unittests mockRobotModel
793 Model loadModel(std::unique_ptr<RobotModelBase> robot_model);
794
800 ServerVersion serverVersion() const noexcept;
801
803 Robot(const Robot&) = delete;
804 Robot& operator=(const Robot&) = delete;
806
807 class Impl;
808
809 protected:
815 Robot(std::shared_ptr<Impl> robot_impl);
816
820 Robot() = default;
821
822 private:
837 template <typename MotionGeneratorType>
838 std::unique_ptr<ActiveControlBase> startControl(
839 const research_interface::robot::Move::ControllerMode& controller_type);
840
841 std::shared_ptr<Impl> impl_;
842 std::mutex control_mutex_;
843
858 template <typename MotionGeneratorType>
859 auto startAsyncControl(const research_interface::robot::Move::ControllerMode& controller_type,
860 const std::optional<std::vector<double>>& maximum_velocities)
861 -> std::unique_ptr<ActiveControlBase>;
862};
863
864} // namespace franka
Robot dynamic parameters computed from the URDF model with Pinocchio.
Definition robot_model_base.h:16
Allows the user to read the state of a Robot and to send new control commands after starting a contro...
Definition active_control_base.h:27
Stores values for Cartesian pose motion generation.
Definition control_types.h:127
Stores values for Cartesian velocity motion generation.
Definition control_types.h:211
Represents a duration with millisecond resolution.
Definition duration.h:19
Stores values for joint position motion generation.
Definition control_types.h:72
Stores values for joint velocity motion generation.
Definition control_types.h:99
Calculates poses of joints and dynamic properties of the robot.
Definition model.h:49
Maintains a network connection to the robot, provides the current robot state, gives access to the mo...
Definition robot.h:68
void control(std::function< Torques(const RobotState &, franka::Duration)> control_callback, bool limit_rate=false, double cutoff_frequency=kDefaultCutoffFrequency)
Starts a control loop for sending joint-level torque commands.
void setCollisionBehavior(const std::array< double, 7 > &lower_torque_thresholds_acceleration, const std::array< double, 7 > &upper_torque_thresholds_acceleration, const std::array< double, 7 > &lower_torque_thresholds_nominal, const std::array< double, 7 > &upper_torque_thresholds_nominal, const std::array< double, 6 > &lower_force_thresholds_acceleration, const std::array< double, 6 > &upper_force_thresholds_acceleration, const std::array< double, 6 > &lower_force_thresholds_nominal, const std::array< double, 6 > &upper_force_thresholds_nominal)
Changes the collision behavior.
Model loadModel()
Loads the model library from the robot.
Robot & operator=(Robot &&other) noexcept
Move-assigns this Robot from another Robot instance.
Robot(Robot &&other) noexcept
Move-constructs a new Robot instance.
auto getUpperJointVelocityLimits(const std::array< double, kNumJoints > &joint_positions) -> std::array< double, kNumJoints >
Computes upper limits for joint velocities based on current joint positions.
ServerVersion serverVersion() const noexcept
Returns the software version reported by the connected server.
virtual std::unique_ptr< ActiveControlBase > startJointPositionControl(const research_interface::robot::Move::ControllerMode &control_type)
Starts a new joint position motion generator.
auto getRobotModel() -> std::string
virtual std::unique_ptr< ActiveControlBase > startAsyncJointPositionControl(const research_interface::robot::Move::ControllerMode &control_type, const std::optional< std::vector< double > > &maximum_velocities)
Starts a new async joint position motion generator.
void stop()
Stops all currently running motions.
void setGuidingMode(const std::array< bool, 6 > &guiding_mode, bool elbow)
Locks or unlocks guiding mode movement in (x, y, z, roll, pitch, yaw).
void read(std::function< bool(const RobotState &)> read_callback)
Starts a loop for reading the current robot state.
virtual std::unique_ptr< ActiveControlBase > startCartesianVelocityControl(const research_interface::robot::Move::ControllerMode &control_type)
Starts a new cartesian velocity motion generator.
virtual std::unique_ptr< ActiveControlBase > startTorqueControl()
Starts a new torque controller.
void setJointImpedance(const std::array< double, 7 > &K_theta)
Sets the impedance for each joint in the internal controller.
virtual std::unique_ptr< ActiveControlBase > startCartesianPoseControl(const research_interface::robot::Move::ControllerMode &control_type)
Starts a new cartesian position motion generator.
virtual ~Robot() noexcept
Closes the connection.
void setCartesianImpedance(const std::array< double, 6 > &K_x)
Sets the Cartesian stiffness/compliance (for x, y, z, roll, pitch, yaw) in the internal controller.
void setK(const std::array< double, 16 > &EE_T_K)
Sets the transformation from end effector frame to stiffness frame.
uint16_t ServerVersion
Version of the robot server.
Definition robot.h:78
virtual std::unique_ptr< ActiveControlBase > startJointVelocityControl(const research_interface::robot::Move::ControllerMode &control_type)
Starts a new joint velocity motion generator.
virtual RobotState readOnce()
Waits for a robot state update and returns it.
Robot(const std::string &franka_address, RealtimeConfig realtime_config=RealtimeConfig::kEnforce, size_t log_size=50)
Establishes a connection with the robot.
void setEE(const std::array< double, 16 > &NE_T_EE)
Sets the transformation from nominal end effector to end effector frame.
static constexpr size_t kNumJoints
Number of joints of the robot.
Definition robot.h:73
void automaticErrorRecovery()
Runs automatic error recovery on the robot.
auto getLowerJointVelocityLimits(const std::array< double, kNumJoints > &joint_positions) -> std::array< double, kNumJoints >
Computes lower limits for joint velocities based on current joint positions.
void setLoad(double load_mass, const std::array< double, 3 > &F_x_Cload, const std::array< double, 9 > &load_inertia)
Sets dynamic parameters of a payload.
Stores joint-level torque commands without gravity and friction.
Definition control_types.h:45
Contains helper types for returning motion generation and joint-level torque commands.
ControllerMode
Available controller modes for a franka::Robot.
Definition control_types.h:19
RealtimeConfig
Used to decide whether to enforce realtime mode for a control loop thread.
Definition control_types.h:26
Contains the franka::Duration type.
Contains functions for filtering signals with a low-pass filter.
Abstract interface class for robot dynamic parameters computed from the URDF model with Pinocchio.
Contains the franka::RobotState types.
Describes the robot state.
Definition robot_state.h:34