1919
2020namespace rcs {
2121namespace hw {
22- Franka::Franka (const std::string& ip,
23- std::optional<std::shared_ptr<common::Kinematics>> ik,
24- const std::optional<FrankaConfig>& cfg)
25- : robot(ip), m_ik(ik) {
22+ Franka::Franka (const FrankaConfig& cfg,
23+ std::optional<std::shared_ptr<common::Kinematics>> ik)
24+ : m_cfg(cfg),
25+ m_ik (ik),
26+ robot(cfg.ip, cfg.ignore_realtime ? franka::RealtimeConfig::kIgnore
27+ : franka::RealtimeConfig::kEnforce ) {
2628 // set collision behavior and impedance
2729 this ->set_default_robot_behavior ();
2830 this ->set_guiding_mode (true , true , true , true , true , true , true );
29-
30- if (cfg.has_value ()) {
31- this ->cfg = cfg.value ();
32- } // else default constructor
3331}
3432
3533Franka::~Franka () {
@@ -46,11 +44,11 @@ Franka::~Franka() {
4644 * otherwise the call will fail
4745 */
4846bool Franka::set_config (const FrankaConfig& cfg) {
49- this ->cfg = cfg;
50- this ->cfg .speed_factor = std::min (std::max (cfg.speed_factor , 0.0 ), 1.0 );
47+ this ->m_cfg = cfg;
48+ this ->m_cfg .speed_factor = std::min (std::max (cfg.speed_factor , 0.0 ), 1.0 );
5149
52- if (this ->cfg .load_parameters .has_value ()) {
53- auto load_value = &(this ->cfg .load_parameters .value ());
50+ if (this ->m_cfg .load_parameters .has_value ()) {
51+ auto load_value = &(this ->m_cfg .load_parameters .value ());
5452 if (!load_value->f_x_cload .has_value ()) {
5553 load_value->f_x_cload = Eigen::Vector3d::Zero ();
5654 }
@@ -69,7 +67,7 @@ bool Franka::set_config(const FrankaConfig& cfg) {
6967FrankaConfig* Franka::get_config () {
7068 // copy config to heap
7169 FrankaConfig* cfg = new FrankaConfig ();
72- *cfg = this ->cfg ;
70+ *cfg = this ->m_cfg ;
7371 return cfg;
7472}
7573
@@ -110,19 +108,19 @@ common::Pose Franka::get_cartesian_position() {
110108 x = common::Pose (this ->curr_state .O_T_EE );
111109 this ->interpolator_mutex .unlock ();
112110 }
113- if (!this ->cfg .tcp_offset_configured_in_desk ) {
114- return x * cfg .tcp_offset ;
111+ if (!this ->m_cfg .tcp_offset_configured_in_desk ) {
112+ return x * this -> m_cfg .tcp_offset ;
115113 }
116114 return x;
117115}
118116
119117void Franka::set_joint_position (const common::VectorXd& q) {
120- if (this ->cfg .async_control ) {
118+ if (this ->m_cfg .async_control ) {
121119 this ->controller_set_joint_position (q);
122120 return ;
123121 }
124122 // sync control
125- FrankaMotionGenerator motion_generator (this ->cfg .speed_factor , q);
123+ FrankaMotionGenerator motion_generator (this ->m_cfg .speed_factor , q);
126124 this ->robot .control (motion_generator);
127125}
128126
@@ -635,8 +633,8 @@ void Franka::move_home() {
635633 // sync
636634 this ->stop_control_thread ();
637635 FrankaMotionGenerator motion_generator (
638- this ->cfg .speed_factor ,
639- common::robots_meta_config.at (this ->cfg .robot_type ).q_home );
636+ this ->m_cfg .speed_factor ,
637+ common::robots_meta_config.at (this ->m_cfg .robot_type ).q_home );
640638 this ->robot .control (motion_generator);
641639}
642640
@@ -713,28 +711,28 @@ std::optional<std::shared_ptr<common::Kinematics>> Franka::get_ik() {
713711
714712void Franka::set_cartesian_position (const common::Pose& x) {
715713 // pose is assumed to be in the robots coordinate frame
716- if (this ->cfg .async_control ) {
714+ if (this ->m_cfg .async_control ) {
717715 this ->osc_set_cartesian_position (x);
718716 return ;
719717 }
720718 // TODO: this should handled with tcp offset config
721719 common::Pose nominal_end_effector_frame_value;
722- if (this ->cfg .nominal_end_effector_frame .has_value ()) {
720+ if (this ->m_cfg .nominal_end_effector_frame .has_value ()) {
723721 nominal_end_effector_frame_value =
724- this ->cfg .nominal_end_effector_frame .value ();
722+ this ->m_cfg .nominal_end_effector_frame .value ();
725723 } else {
726724 nominal_end_effector_frame_value = common::Pose::Identity ();
727725 }
728726 // nominal end effector frame should be on top of tcp offset as franka already
729727 // takes care of the default franka hand offset lets add a franka hand offset
730728
731- if (this ->cfg .ik_solver == IKSolver::franka_ik) {
729+ if (this ->m_cfg .ik_solver == IKSolver::franka_ik) {
732730 // if gripper is attached the tcp offset will automatically be applied
733731 // by libfranka
734732 this ->robot .setEE (nominal_end_effector_frame_value.affine_array ());
735733 this ->set_cartesian_position_internal (x, 1.0 , std::nullopt , std::nullopt );
736734
737- } else if (this ->cfg .ik_solver == IKSolver::rcs_ik) {
735+ } else if (this ->m_cfg .ik_solver == IKSolver::rcs_ik) {
738736 this ->set_cartesian_position_ik (x);
739737 }
740738}
@@ -746,7 +744,7 @@ void Franka::set_cartesian_position_ik(const common::Pose& pose) {
746744 " position." );
747745 }
748746 auto joints = this ->m_ik .value ()->inverse (pose, this ->get_joint_position (),
749- this ->cfg .tcp_offset );
747+ this ->m_cfg .tcp_offset );
750748
751749 if (joints.has_value ()) {
752750 this ->set_joint_position (joints.value ());
@@ -758,8 +756,9 @@ void Franka::set_cartesian_position_ik(const common::Pose& pose) {
758756}
759757
760758common::Pose Franka::get_base_pose_in_world_coordinates () {
761- return this ->cfg .world_to_robot .has_value () ? this ->cfg .world_to_robot .value ()
762- : common::Pose ();
759+ return this ->m_cfg .world_to_robot .has_value ()
760+ ? this ->m_cfg .world_to_robot .value ()
761+ : common::Pose ();
763762}
764763
765764void Franka::set_cartesian_position_internal (const common::Pose& pose,
0 commit comments