Skip to content

Commit dde15e8

Browse files
committed
refactor: rename fr3 class to franka
- rename fr3 c++ classes to franka as they are now shared between fr3 and panda - added config subclasses for both robots - added fixed pybind11-stubgen fork which should be removed as soon as the PR is accepted
1 parent a80c32e commit dde15e8

25 files changed

Lines changed: 208 additions & 176 deletions

‎extensions/rcs_fr3/README.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ DESK_PASSWORD=...
1616
```python
1717
import rcs_fr3
1818
from rcs_fr3._core import hw
19-
from rcs_fr3.desk import FCI, ContextManager, Desk, load_creds_fr3_desk
20-
user, pw = load_creds_fr3_desk()
19+
from rcs_fr3.desk import FCI, ContextManager, Desk, load_creds_franka_desk
20+
user, pw = load_creds_franka_desk()
2121
with FCI(Desk(ROBOT_IP, user, pw), unlock=False, lock_when_done=False):
2222
urdf_path = rcs.scenes["fr3_empty_world"].urdf
2323
ik = rcs.common.RL(str(urdf_path))
24-
robot = hw.FR3(ROBOT_IP, ik)
25-
robot_cfg = FR3Config()
24+
robot = hw.Franka(ROBOT_IP, ik)
25+
robot_cfg = hw.FR3Config()
2626
robot_cfg.tcp_offset = rcs.common.Pose(rcs.common.FrankaHandTCPOffset())
2727
robot_cfg.ik_solver = IKSolver.rcs_ik
2828
robot.set_config(robot_cfg)

‎extensions/rcs_fr3/src/hw/CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
add_library(hw)
2-
target_sources(hw PRIVATE FR3.cpp FrankaHand.cpp FR3MotionGenerator.cpp)
2+
target_sources(hw PRIVATE Franka.cpp FrankaHand.cpp FrankaMotionGenerator.cpp)
33
target_link_libraries(
44
hw
55
PUBLIC franka rcs pinocchio::all Eigen3::Eigen
Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "FR3.h"
1+
#include "Franka.h"
22

33
#include <franka/duration.h>
44
#include <franka/exception.h>
@@ -14,14 +14,14 @@
1414
#include <string>
1515
#include <thread>
1616

17-
#include "FR3MotionGenerator.h"
17+
#include "FrankaMotionGenerator.h"
1818
#include "rcs/Pose.h"
1919

2020
namespace rcs {
2121
namespace hw {
22-
FR3::FR3(const std::string &ip,
22+
Franka::Franka(const std::string &ip,
2323
std::optional<std::shared_ptr<common::Kinematics>> ik,
24-
const std::optional<FR3Config> &cfg)
24+
const std::optional<FrankaConfig> &cfg)
2525
: robot(ip), m_ik(ik) {
2626
// set collision behavior and impedance
2727
this->set_default_robot_behavior();
@@ -32,14 +32,14 @@ FR3::FR3(const std::string &ip,
3232
} // else default constructor
3333
}
3434

35-
FR3::~FR3() {}
35+
Franka::~Franka() {}
3636

3737
/**
3838
* @brief Set the parameters for the robot
39-
* @param cfg The configuration for the robot, it should be a FR3Config type
39+
* @param cfg The configuration for the robot, it should be a FrankaConfig type
4040
* otherwise the call will fail
4141
*/
42-
bool FR3::set_config(const FR3Config &cfg) {
42+
bool Franka::set_config(const FrankaConfig &cfg) {
4343
this->cfg = cfg;
4444
this->cfg.speed_factor = std::min(std::max(cfg.speed_factor, 0.0), 1.0);
4545

@@ -60,20 +60,20 @@ bool FR3::set_config(const FR3Config &cfg) {
6060
return true;
6161
}
6262

63-
FR3Config *FR3::get_config() {
63+
FrankaConfig *Franka::get_config() {
6464
// copy config to heap
65-
FR3Config *cfg = new FR3Config();
65+
FrankaConfig *cfg = new FrankaConfig();
6666
*cfg = this->cfg;
6767
return cfg;
6868
}
6969

70-
FR3State *FR3::get_state() {
70+
FrankaState *Franka::get_state() {
7171
// dummy state until we define a prober state
72-
FR3State *state = new FR3State();
72+
FrankaState *state = new FrankaState();
7373
return state;
7474
}
7575

76-
void FR3::set_default_robot_behavior() {
76+
void Franka::set_default_robot_behavior() {
7777
this->robot.setCollisionBehavior({{20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0}},
7878
{{20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0}},
7979
{{10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0}},
@@ -86,7 +86,7 @@ void FR3::set_default_robot_behavior() {
8686
this->robot.setCartesianImpedance({{3000, 3000, 3000, 300, 300, 300}});
8787
}
8888

89-
common::Pose FR3::get_cartesian_position() {
89+
common::Pose Franka::get_cartesian_position() {
9090
common::Pose x;
9191
if (this->running_controller == Controller::none) {
9292
this->curr_state = this->robot.readOnce();
@@ -99,17 +99,17 @@ common::Pose FR3::get_cartesian_position() {
9999
return x;
100100
}
101101

102-
void FR3::set_joint_position(const common::VectorXd &q) {
102+
void Franka::set_joint_position(const common::VectorXd &q) {
103103
if (this->cfg.async_control) {
104104
this->controller_set_joint_position(q);
105105
return;
106106
}
107107
// sync control
108-
FR3MotionGenerator motion_generator(this->cfg.speed_factor, q);
108+
FrankaMotionGenerator motion_generator(this->cfg.speed_factor, q);
109109
this->robot.control(motion_generator);
110110
}
111111

112-
common::VectorXd FR3::get_joint_position() {
112+
common::VectorXd Franka::get_joint_position() {
113113
common::Vector7d joints;
114114
if (this->running_controller == Controller::none) {
115115
this->curr_state = this->robot.readOnce();
@@ -122,7 +122,7 @@ common::VectorXd FR3::get_joint_position() {
122122
return joints;
123123
}
124124

125-
void FR3::set_guiding_mode(bool x, bool y, bool z, bool roll, bool pitch,
125+
void Franka::set_guiding_mode(bool x, bool y, bool z, bool roll, bool pitch,
126126
bool yaw, bool elbow) {
127127
std::array<bool, 6> activated = {x, y, z, roll, pitch, yaw};
128128
this->robot.setGuidingMode(activated, elbow);
@@ -158,7 +158,7 @@ void TorqueSafetyGuardFn(std::array<double, 7> &tau_d_array, double min_torque,
158158
}
159159
}
160160

161-
void FR3::controller_set_joint_position(const common::Vector7d &desired_q) {
161+
void Franka::controller_set_joint_position(const common::Vector7d &desired_q) {
162162
// from deoxys/config/osc-position-controller.yml
163163
double traj_interpolation_time_fraction = 1.0; // in s
164164
// form deoxys/config/charmander.yml
@@ -186,13 +186,13 @@ void FR3::controller_set_joint_position(const common::Vector7d &desired_q) {
186186
// if not thread is running, then start
187187
if (this->running_controller == Controller::none) {
188188
this->running_controller = Controller::jsc;
189-
this->control_thread = std::thread(&FR3::joint_controller, this);
189+
this->control_thread = std::thread(&Franka::joint_controller, this);
190190
} else {
191191
this->interpolator_mutex.unlock();
192192
}
193193
}
194194

195-
void FR3::osc_set_cartesian_position(
195+
void Franka::osc_set_cartesian_position(
196196
const common::Pose &desired_pose_EE_in_base_frame) {
197197
// from deoxys/config/osc-position-controller.yml
198198
double traj_interpolation_time_fraction = 1.0;
@@ -222,14 +222,14 @@ void FR3::osc_set_cartesian_position(
222222
// if not thread is running, then start
223223
if (this->running_controller == Controller::none) {
224224
this->running_controller = Controller::osc;
225-
this->control_thread = std::thread(&FR3::osc, this);
225+
this->control_thread = std::thread(&Franka::osc, this);
226226
} else {
227227
this->interpolator_mutex.unlock();
228228
}
229229
}
230230

231231
// method to stop thread
232-
void FR3::stop_control_thread() {
232+
void Franka::stop_control_thread() {
233233
if (this->control_thread.has_value() &&
234234
this->running_controller != Controller::none) {
235235
this->running_controller = Controller::none;
@@ -238,7 +238,7 @@ void FR3::stop_control_thread() {
238238
}
239239
}
240240

241-
void FR3::osc() {
241+
void Franka::osc() {
242242
franka::Model model = this->robot.loadModel();
243243

244244
this->controller_time = 0.0;
@@ -451,7 +451,7 @@ void FR3::osc() {
451451
});
452452
}
453453

454-
void FR3::joint_controller() {
454+
void Franka::joint_controller() {
455455
franka::Model model = this->robot.loadModel();
456456
this->controller_time = 0.0;
457457

@@ -545,17 +545,17 @@ void FR3::joint_controller() {
545545
});
546546
}
547547

548-
void FR3::zero_torque_guiding() {
548+
void Franka::zero_torque_guiding() {
549549
if (this->running_controller != Controller::none) {
550550
throw std::runtime_error(
551551
"A controller is currently running. Please stop it first.");
552552
}
553553
this->controller_time = 0.0;
554554
this->running_controller = Controller::ztc;
555-
this->control_thread = std::thread(&FR3::zero_torque_controller, this);
555+
this->control_thread = std::thread(&Franka::zero_torque_controller, this);
556556
}
557557

558-
void FR3::zero_torque_controller() {
558+
void Franka::zero_torque_controller() {
559559
// high collision threshold values for high impedance
560560
robot.setCollisionBehavior(
561561
{{100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0}},
@@ -578,26 +578,26 @@ void FR3::zero_torque_controller() {
578578
});
579579
}
580580

581-
void FR3::move_home() {
581+
void Franka::move_home() {
582582
// sync
583-
FR3MotionGenerator motion_generator(
583+
FrankaMotionGenerator motion_generator(
584584
this->cfg.speed_factor,
585-
common::robots_meta_config.at(common::RobotType::FR3).q_home);
585+
common::robots_meta_config.at(this->cfg.robot_type).q_home);
586586
this->robot.control(motion_generator);
587587
}
588588

589-
void FR3::automatic_error_recovery() { this->robot.automaticErrorRecovery(); }
589+
void Franka::automatic_error_recovery() { this->robot.automaticErrorRecovery(); }
590590

591-
void FR3::reset() {
591+
void Franka::reset() {
592592
this->stop_control_thread();
593593
this->automatic_error_recovery();
594594
}
595595

596-
void FR3::wait_milliseconds(int milliseconds) {
596+
void Franka::wait_milliseconds(int milliseconds) {
597597
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
598598
}
599599

600-
void FR3::double_tap_robot_to_continue() {
600+
void Franka::double_tap_robot_to_continue() {
601601
auto s = this->robot.readOnce();
602602
int touch_counter = false;
603603
bool can_be_touched_again = true;
@@ -651,11 +651,11 @@ double quintic_polynomial_speed_profile(double time, double start_time,
651651
// return (1 - std::cos(M_PI * progress)) / 2.0;
652652
}
653653

654-
std::optional<std::shared_ptr<common::Kinematics>> FR3::get_ik() {
654+
std::optional<std::shared_ptr<common::Kinematics>> Franka::get_ik() {
655655
return this->m_ik;
656656
}
657657

658-
void FR3::set_cartesian_position(const common::Pose &x) {
658+
void Franka::set_cartesian_position(const common::Pose &x) {
659659
// pose is assumed to be in the robots coordinate frame
660660
if (this->cfg.async_control) {
661661
this->osc_set_cartesian_position(x);
@@ -683,7 +683,7 @@ void FR3::set_cartesian_position(const common::Pose &x) {
683683
}
684684
}
685685

686-
void FR3::set_cartesian_position_ik(const common::Pose &pose) {
686+
void Franka::set_cartesian_position_ik(const common::Pose &pose) {
687687
if (!this->m_ik.has_value()) {
688688
throw std::runtime_error(
689689
"No inverse kinematics was provided. Cannot use IK to set cartesian "
@@ -701,12 +701,12 @@ void FR3::set_cartesian_position_ik(const common::Pose &pose) {
701701
}
702702
}
703703

704-
common::Pose FR3::get_base_pose_in_world_coordinates() {
704+
common::Pose Franka::get_base_pose_in_world_coordinates() {
705705
return this->cfg.world_to_robot.has_value() ? this->cfg.world_to_robot.value()
706706
: common::Pose();
707707
}
708708

709-
void FR3::set_cartesian_position_internal(const common::Pose &pose,
709+
void Franka::set_cartesian_position_internal(const common::Pose &pose,
710710
double max_time,
711711
std::optional<double> elbow,
712712
std::optional<double> max_force) {
Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef RCS_FR3_H
2-
#define RCS_FR3_H
1+
#ifndef RCS_FRANKA_H
2+
#define RCS_FRANKA_H
33

44
#include <franka/robot.h>
55

@@ -21,7 +21,7 @@ namespace hw {
2121

2222
const double DEFAULT_SPEED_FACTOR = 0.2;
2323

24-
struct FR3Load {
24+
struct FrankaLoad {
2525
double load_mass;
2626
std::optional<Eigen::Vector3d> f_x_cload;
2727
std::optional<Eigen::Matrix3d> load_inertia;
@@ -30,26 +30,32 @@ enum IKSolver { franka_ik = 0, rcs_ik };
3030
// modes: joint-space control, operational-space control, zero-torque
3131
// control
3232
enum Controller { none = 0, jsc, osc, ztc };
33-
struct FR3Config : common::RobotConfig {
33+
struct FrankaConfig : common::RobotConfig {
3434
// TODO: max force and elbow?
3535
// TODO: we can either write specific bindings for each, or we use python
3636
// dictionaries with these objects
3737
common::RobotType robot_type = common::RobotType::FR3;
3838
common::RobotPlatform robot_platform = common::RobotPlatform::HARDWARE;
39-
IKSolver ik_solver = IKSolver::franka_ik;
39+
IKSolver ik_solver = IKSolver::rcs_ik;
4040
double speed_factor = DEFAULT_SPEED_FACTOR;
41-
std::optional<FR3Load> load_parameters = std::nullopt;
41+
std::optional<FrankaLoad> load_parameters = std::nullopt;
4242
std::optional<common::Pose> nominal_end_effector_frame = std::nullopt;
4343
std::optional<common::Pose> world_to_robot = std::nullopt;
4444
bool async_control = false;
4545
};
4646

47-
struct FR3State : common::RobotState {};
47+
struct FR3Config : FrankaConfig {};
48+
struct PandaConfig : FrankaConfig {
49+
common::RobotType robot_type = common::RobotType::Panda;
50+
};
51+
52+
53+
struct FrankaState : common::RobotState {};
4854

49-
class FR3 : public common::Robot {
55+
class Franka : public common::Robot {
5056
private:
5157
franka::Robot robot;
52-
FR3Config cfg;
58+
FrankaConfig cfg;
5359
std::optional<std::shared_ptr<common::Kinematics>> m_ik;
5460
std::optional<std::thread> control_thread = std::nullopt;
5561
common::LinearPoseTrajInterpolator traj_interpolator;
@@ -63,16 +69,16 @@ class FR3 : public common::Robot {
6369
void zero_torque_controller();
6470

6571
public:
66-
FR3(const std::string &ip,
72+
Franka(const std::string &ip,
6773
std::optional<std::shared_ptr<common::Kinematics>> ik = std::nullopt,
68-
const std::optional<FR3Config> &cfg = std::nullopt);
69-
~FR3() override;
74+
const std::optional<FrankaConfig> &cfg = std::nullopt);
75+
~Franka() override;
7076

71-
bool set_config(const FR3Config &cfg);
77+
bool set_config(const FrankaConfig &cfg);
7278

73-
FR3Config *get_config() override;
79+
FrankaConfig *get_config() override;
7480

75-
FR3State *get_state() override;
81+
FrankaState *get_state() override;
7682

7783
void set_default_robot_behavior();
7884

@@ -119,4 +125,4 @@ class FR3 : public common::Robot {
119125
} // namespace hw
120126
} // namespace rcs
121127

122-
#endif // RCS_FR3_H
128+
#endif // RCS_FRANKA_H

0 commit comments

Comments
 (0)