Skip to content

Commit b795b46

Browse files
committed
Refactoring ik controller
1 parent 7f550bc commit b795b46

File tree

4 files changed

+184
-250
lines changed

4 files changed

+184
-250
lines changed

testing.py

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,58 +7,12 @@
77
# Load the URDF model using a free-flyer as root joint
88
model = pinocchio.buildModelFromUrdf("/home/ubuntu/ws_ros/src/auv_controllers/ik_solvers/examples/urdf/uvms.urdf", pinocchio.JointModelFreeFlyer())
99

10-
joint_names_to_lock = [
11-
"alpha_rs1_130_joint",
12-
"alpha_rs1_139_joint",
13-
"alpha_axis_a",
14-
"thruster1_joint",
15-
"thruster2_joint",
16-
"thruster3_joint",
17-
"thruster4_joint",
18-
"thruster5_joint",
19-
"thruster6_joint",
20-
"thruster7_joint",
21-
"thruster8_joint"
22-
]
23-
24-
# Convert the joint names to joint IDs
25-
joint_ids_to_lock = [
26-
model.getJointId(name) for name in joint_names_to_lock if model.existJointName(name)
27-
]
10+
controlled_joints = ["universe", "root_joint", "alpha_axis_b", "alpha_axis_c", "alpha_axis_d", "alpha_axis_e"]
11+
locked_joints = [model.getJointId(model.names[idx]) for idx, joint in enumerate(model.joints) if model.names[idx] not in controlled_joints]
2812

2913
q_ref = pinocchio.neutral(model)
30-
model = pinocchio.buildReducedModel(model, joint_ids_to_lock, q_ref)
14+
model = pinocchio.buildReducedModel(model, locked_joints, q_ref)
3115
data = model.createData()
3216

33-
# rot = R.random()
34-
q = pinocchio.neutral(model)
35-
# q[:3] = np.random.rand(3)
36-
# q[3:7] = rot.as_quat().reshape(-1)
37-
38-
for idx, joint in enumerate(model.joints):
39-
joint_name = model.names[idx]
40-
nq = joint.nq # Number of configuration variables for this joint
41-
print(f"{joint_name}: index in q = {joint.idx_q}, nq = {nq}")
42-
43-
print(q)
44-
print(len(q))
45-
46-
# Perform the forward kinematics over the kinematic tree
47-
pinocchio.forwardKinematics(model, data, q)
48-
pinocchio.updateFramePlacements(model, data)
49-
pinocchio.computeJointJacobians(model, data, q)
50-
51-
# # Get the index of the base link
52-
joint_name = "alpha_axis_b"
53-
joint_id = model.getJointId(joint_name)
54-
joint_idx = model.joints[joint_id].idx_v
55-
56-
frame_name = "alpha_tcp"
57-
frame_id = model.getFrameId(frame_name)
58-
print(f"Frame ID of {frame_name}: {frame_id}")
59-
60-
J = pinocchio.getFrameJacobian(model, data, model.getFrameId(frame_name), pinocchio.ReferenceFrame.LOCAL_WORLD_ALIGNED)
61-
# J = pinocchio.getJointJacobian(model, data, joint_id, pinocchio.ReferenceFrame.LOCAL)
62-
63-
print(f"Jacobian of {joint_name}:")
64-
print(J)
17+
for i, joint in enumerate(model.names):
18+
print(model.getJointId(joint), joint)

whole_body_controllers/include/whole_body_controllers/ik_controller.hpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,28 +86,25 @@ class IKController : public controller_interface::ChainableControllerInterface
8686
// that publish the vehicle state without the manipulator states
8787
std::shared_ptr<rclcpp::Subscription<nav_msgs::msg::Odometry>> vehicle_state_sub_;
8888
realtime_tools::RealtimeBuffer<nav_msgs::msg::Odometry> vehicle_state_;
89-
std::vector<double> system_state_values_;
90-
91-
std::shared_ptr<rclcpp::Subscription<std_msgs::msg::String>> robot_description_sub_;
89+
std::vector<double> position_state_values_, velocity_state_values_;
9290

9391
std::unique_ptr<pluginlib::ClassLoader<ik_solvers::IKSolver>> loader_;
9492
std::shared_ptr<ik_solvers::IKSolver> solver_;
9593

9694
std::unique_ptr<ik_controller::ParamListener> param_listener_;
9795
ik_controller::Params params_;
9896

99-
bool model_initialized_{false};
100-
101-
std::vector<std::string> pos_dofs_, vel_dofs_, manipulator_dofs_;
102-
std::size_t n_pos_dofs_, n_vel_dofs_, n_manipulator_dofs_;
103-
10497
// make the free-flyer position and velocity dof names "static"
10598
std::vector<std::string> free_flyer_pos_dofs_{"x", "y", "z", "qx", "qy", "qz", "qw"};
10699
std::vector<std::string> free_flyer_vel_dofs_{"x", "y", "z", "rx", "ry", "rz"};
107100

108-
// keep track of the command interfaces
109-
bool has_position_interface_{false}, has_velocity_interface_{false};
110-
std::size_t n_command_interfaces_{0};
101+
// store the names of the position and velocity interfaces
102+
// this is stored in the same order as the pinocchio model to simplify integration with the solver
103+
std::vector<std::string> position_interface_names_, velocity_interface_names_;
104+
105+
// track the interfaces used by the controller
106+
bool use_position_commands_, use_velocity_commands_, use_position_states_, use_velocity_states_;
107+
std::size_t n_command_interfaces_, n_state_interfaces_;
111108

112109
rclcpp::Logger logger_{rclcpp::get_logger("ik_controller")};
113110
};

0 commit comments

Comments
 (0)