Skip to content

Commit 6c88b88

Browse files
committed
refactor: rename ik into kinematics and inverse
1 parent f710594 commit 6c88b88

16 files changed

Lines changed: 65 additions & 58 deletions

File tree

extensions/rcs_fr3/src/hw/FR3.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
namespace rcs {
2121
namespace hw {
22-
FR3::FR3(const std::string &ip, std::optional<std::shared_ptr<common::IK>> ik,
22+
FR3::FR3(const std::string &ip,
23+
std::optional<std::shared_ptr<common::Kinematics>> ik,
2324
const std::optional<FR3Config> &cfg)
2425
: robot(ip), m_ik(ik) {
2526
// set collision behavior and impedance
@@ -650,7 +651,9 @@ double quintic_polynomial_speed_profile(double time, double start_time,
650651
// return (1 - std::cos(M_PI * progress)) / 2.0;
651652
}
652653

653-
std::optional<std::shared_ptr<common::IK>> FR3::get_ik() { return this->m_ik; }
654+
std::optional<std::shared_ptr<common::Kinematics>> FR3::get_ik() {
655+
return this->m_ik;
656+
}
654657

655658
void FR3::set_cartesian_position(const common::Pose &x) {
656659
// pose is assumed to be in the robots coordinate frame
@@ -686,8 +689,8 @@ void FR3::set_cartesian_position_ik(const common::Pose &pose) {
686689
"No inverse kinematics was provided. Cannot use IK to set cartesian "
687690
"position.");
688691
}
689-
auto joints = this->m_ik.value()->ik(pose, this->get_joint_position(),
690-
this->cfg.tcp_offset);
692+
auto joints = this->m_ik.value()->inverse(pose, this->get_joint_position(),
693+
this->cfg.tcp_offset);
691694

692695
if (joints.has_value()) {
693696
this->set_joint_position(joints.value());

extensions/rcs_fr3/src/hw/FR3.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <string>
1111
#include <thread>
1212

13-
#include "rcs/IK.h"
13+
#include "rcs/Kinematics.h"
1414
#include "rcs/LinearPoseTrajInterpolator.h"
1515
#include "rcs/Pose.h"
1616
#include "rcs/Robot.h"
@@ -48,7 +48,7 @@ class FR3 : public common::Robot {
4848
private:
4949
franka::Robot robot;
5050
FR3Config cfg;
51-
std::optional<std::shared_ptr<common::IK>> m_ik;
51+
std::optional<std::shared_ptr<common::Kinematics>> m_ik;
5252
std::optional<std::thread> control_thread = std::nullopt;
5353
common::LinearPoseTrajInterpolator traj_interpolator;
5454
double controller_time = 0.0;
@@ -62,7 +62,7 @@ class FR3 : public common::Robot {
6262

6363
public:
6464
FR3(const std::string &ip,
65-
std::optional<std::shared_ptr<common::IK>> ik = std::nullopt,
65+
std::optional<std::shared_ptr<common::Kinematics>> ik = std::nullopt,
6666
const std::optional<FR3Config> &cfg = std::nullopt);
6767
~FR3() override;
6868

@@ -100,7 +100,7 @@ class FR3 : public common::Robot {
100100

101101
void set_cartesian_position(const common::Pose &pose) override;
102102

103-
std::optional<std::shared_ptr<common::IK>> get_ik() override;
103+
std::optional<std::shared_ptr<common::Kinematics>> get_ik() override;
104104

105105
void set_cartesian_position_internal(const common::Pose &pose,
106106
double max_time,

extensions/rcs_fr3/src/hw/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <franka/exception.h>
22
#include <franka/gripper.h>
33
#include <franka/robot.h>
4-
#include <rcs/IK.h>
4+
#include <rcs/Kinematics.h>
55

66
#include <iostream>
77
#include <memory>

extensions/rcs_fr3/src/pybind/rcs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include <memory>
1111

12-
#include "rcs/IK.h"
12+
#include "rcs/Kinematics.h"
1313
#include "rcs/Pose.h"
1414
#include "rcs/Robot.h"
1515
#include "rcs/utils.h"
@@ -99,7 +99,7 @@ PYBIND11_MODULE(_core, m) {
9999
(py::object)py::module_::import("rcs").attr("common").attr("Robot");
100100
py::class_<rcs::hw::FR3, std::shared_ptr<rcs::hw::FR3>>(hw, "FR3", robot)
101101
.def(py::init<const std::string &,
102-
std::optional<std::shared_ptr<rcs::common::IK>>>(),
102+
std::optional<std::shared_ptr<rcs::common::Kinematics>>>(),
103103
py::arg("ip"), py::arg("ik") = std::nullopt)
104104
.def("set_config", &rcs::hw::FR3::set_config, py::arg("cfg"))
105105
.def("get_config", &rcs::hw::FR3::get_config)

extensions/rcs_fr3/src/rcs_fr3/_core/hw/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class FHState(rcs._core.common.GripperState):
5252
def width(self) -> float: ...
5353

5454
class FR3(rcs._core.common.Robot):
55-
def __init__(self, ip: str, ik: rcs._core.common.IK | None = None) -> None: ...
55+
def __init__(self, ip: str, ik: rcs._core.common.Kinematics | None = None) -> None: ...
5656
def automatic_error_recovery(self) -> None: ...
5757
def controller_set_joint_position(
5858
self, desired_q: numpy.ndarray[tuple[typing.Literal[7]], numpy.dtype[numpy.float64]]

extensions/rcs_so101/src/rcs_so101/hw.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def reset(self) -> None:
5555
pass
5656

5757
def set_cartesian_position(self, pose: common.Pose) -> None:
58-
joints = self.ik.ik(pose, q0=self.get_joint_position())
58+
joints = self.ik.inverse(pose, q0=self.get_joint_position())
5959
if joints is not None:
6060
self.set_joint_position(joints)
6161

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
namespace rcs {
2121
namespace common {
2222

23-
class IK {
23+
class Kinematics {
2424
public:
25-
virtual ~IK(){};
26-
virtual std::optional<VectorXd> ik(
25+
virtual ~Kinematics(){};
26+
virtual std::optional<VectorXd> inverse(
2727
const Pose& pose, const VectorXd& q0,
2828
const Pose& tcp_offset = Pose::Identity()) = 0;
2929
virtual Pose forward(const VectorXd& q0, const Pose& tcp_offset) = 0;
3030
};
3131

32-
class RL : public IK {
32+
class RL : public Kinematics {
3333
private:
3434
const int random_restarts = 0;
3535
const double eps = 1e-3;
@@ -41,13 +41,13 @@ class RL : public IK {
4141

4242
public:
4343
RL(const std::string& path, size_t max_duration_ms = 300);
44-
std::optional<VectorXd> ik(
44+
std::optional<VectorXd> inverse(
4545
const Pose& pose, const VectorXd& q0,
4646
const Pose& tcp_offset = Pose::Identity()) override;
4747
Pose forward(const VectorXd& q0, const Pose& tcp_offset) override;
4848
};
4949

50-
class Pin : public IK {
50+
class Pin : public Kinematics {
5151
private:
5252
const double eps = 1e-4;
5353
const int IT_MAX = 1000;
@@ -60,7 +60,7 @@ class Pin : public IK {
6060

6161
public:
6262
Pin(const std::string& path, const std::string& frame_id, bool urdf);
63-
std::optional<VectorXd> ik(
63+
std::optional<VectorXd> inverse(
6464
const Pose& pose, const VectorXd& q0,
6565
const Pose& tcp_offset = Pose::Identity()) override;
6666
Pose forward(const VectorXd& q0, const Pose& tcp_offset) override;

include/rcs/Robot.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <optional>
66
#include <string>
77

8-
#include "IK.h"
8+
#include "Kinematics.h"
99
#include "Pose.h"
1010
#include "utils.h"
1111

@@ -152,7 +152,7 @@ class Robot {
152152

153153
virtual void set_cartesian_position(const Pose& pose) = 0;
154154

155-
virtual std::optional<std::shared_ptr<IK>> get_ik() = 0;
155+
virtual std::optional<std::shared_ptr<Kinematics>> get_ik() = 0;
156156

157157
common::Pose to_pose_in_world_coordinates(
158158
const Pose& pose_in_robot_coordinates);

python/rcs/_core/common.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ __all__ = [
2121
"Hand",
2222
"HandConfig",
2323
"HandState",
24-
"IK",
2524
"IdentityRotMatrix",
2625
"IdentityRotQuatVec",
2726
"IdentityTranslation",
27+
"Kinematics",
2828
"LATERAL_GRASP",
2929
"POWER_GRASP",
3030
"PRECISION_GRASP",
@@ -128,13 +128,13 @@ class HandConfig:
128128
class HandState:
129129
def __init__(self) -> None: ...
130130

131-
class IK:
131+
class Kinematics:
132132
def forward(self, q0: numpy.ndarray[tuple[M], numpy.dtype[numpy.float64]], tcp_offset: Pose = ...) -> Pose: ...
133-
def ik(
133+
def inverse(
134134
self, pose: Pose, q0: numpy.ndarray[tuple[M], numpy.dtype[numpy.float64]], tcp_offset: Pose = ...
135135
) -> numpy.ndarray[tuple[M], numpy.dtype[numpy.float64]] | None: ...
136136

137-
class Pin(IK):
137+
class Pin(Kinematics):
138138
def __init__(self, path: str, frame_id: str = "fr3_link8", urdf: bool = True) -> None: ...
139139

140140
class Pose:
@@ -195,7 +195,7 @@ class Pose:
195195
def translation(self) -> numpy.ndarray[tuple[typing.Literal[3]], numpy.dtype[numpy.float64]]: ...
196196
def xyzrpy(self) -> numpy.ndarray[tuple[typing.Literal[6]], numpy.dtype[numpy.float64]]: ...
197197

198-
class RL(IK):
198+
class RL(Kinematics):
199199
def __init__(self, urdf_path: str, max_duration_ms: int = 300) -> None: ...
200200

201201
class RPY:
@@ -223,7 +223,7 @@ class Robot:
223223
def get_base_pose_in_world_coordinates(self) -> Pose: ...
224224
def get_cartesian_position(self) -> Pose: ...
225225
def get_config(self) -> RobotConfig: ...
226-
def get_ik(self) -> IK | None: ...
226+
def get_ik(self) -> Kinematics | None: ...
227227
def get_joint_position(self) -> numpy.ndarray[tuple[M], numpy.dtype[numpy.float64]]: ...
228228
def get_state(self) -> RobotState: ...
229229
def move_home(self) -> None: ...

python/rcs/_core/sim.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class SimGripperState(rcs._core.common.GripperState):
151151

152152
class SimRobot(rcs._core.common.Robot):
153153
def __init__(
154-
self, sim: Sim, ik: rcs._core.common.IK, cfg: SimRobotConfig, register_convergence_callback: bool = True
154+
self, sim: Sim, ik: rcs._core.common.Kinematics, cfg: SimRobotConfig, register_convergence_callback: bool = True
155155
) -> None: ...
156156
def get_config(self) -> SimRobotConfig: ...
157157
def get_state(self) -> SimRobotState: ...

0 commit comments

Comments
 (0)