rs_opw_kinematics/parameters.rs
1//! Defines the OPW parameter data structure
2
3pub mod opw_kinematics {
4 use crate::utils::deg;
5
6 /// Parameters for the robot. See [parameters_robots.rs](parameters_robots.rs) for examples of concrete robot models.
7 #[derive(Debug, Clone, Copy)]
8 /// Parameters for the kinematic model of the robot.
9 pub struct Parameters {
10 /// The length of the first link of the robot (distance between joint 1 and joint 2).
11 pub a1: f64,
12
13 /// The length of the second link of the robot (distance between joint 2 and joint 3).
14 pub a2: f64,
15
16 /// The offset in the y-direction between joint 1 and joint 2.
17 /// This can be 0 for robots without a lateral offset that is very common.
18 pub b: f64,
19
20 /// The vertical distance from the base (joint 1) to joint 2 along the z-axis.
21 pub c1: f64,
22
23 /// The vertical distance between joints 2 and 3 along the z-axis.
24 pub c2: f64,
25
26 /// The offset between joint 3 and joint 4, typically along the x-axis.
27 pub c3: f64,
28
29 /// The distance from the wrist center (last joint) to the end-effector mount
30 /// In 5-DOF robots, this defines the offset between joint 5 and the end-effector mount
31 pub c4: f64,
32
33 /// Offsets applied to each joint angle to adjust the reference zero position.
34 /// There are 6 values corresponding to each joint in a 6-DOF robot.
35 pub offsets: [f64; 6],
36
37 /// Specifies the direction of positive rotation from the zero angle for each joint.
38 /// A value of `-1` reverses the default rotation direction for that joint.
39 pub sign_corrections: [i8; 6],
40
41 /// Degrees of freedom for the robot.
42 /// This can either be 5 for 5-DOF robots or 6 for 6-DOF robots.
43 pub dof: i8
44 }
45
46
47 impl Parameters {
48 /// Convert to string yaml representation (quick viewing, etc).
49 pub fn to_yaml(&self) -> String {
50 format!(
51 "opw_kinematics_geometric_parameters:\n \
52 a1: {}\n \
53 a2: {}\n \
54 b: {}\n \
55 c1: {}\n \
56 c2: {}\n \
57 c3: {}\n \
58 c4: {}\n\
59 opw_kinematics_joint_offsets: [{}]\n\
60 opw_kinematics_joint_sign_corrections: [{}]\n\
61 dof: {}\n",
62 self.a1,
63 self.a2,
64 self.b,
65 self.c1,
66 self.c2,
67 self.c3,
68 self.c4,
69 self.offsets.iter().map(|x| deg(x))
70 .collect::<Vec<_>>().join(","),
71 self.sign_corrections.iter().map(|x| x.to_string())
72 .collect::<Vec<_>>().join(","),
73 self.dof
74 )
75 }
76 }
77}