1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
use crate::geometry::{Frame, Twist, Introspection, new_ref_point, invert_frame};
use crate::joint::{Joint, JointType};
pub type RigidBodyInertia = f64;
#[derive(Copy,Clone)]
pub struct Segment {
joint: Joint,
f_tip: Frame,
inertia: RigidBodyInertia,
}
impl Segment {
pub fn default() -> Segment {
Segment {
joint: Joint::default(),
f_tip: Frame::identity(),
inertia: 0.0,
}
}
pub fn new(joint: Joint, f_tip: Frame, inertia: RigidBodyInertia) -> Segment {
let frame = invert_frame(joint.pose(0.0)) * f_tip;
Segment {
joint: joint, f_tip: frame, inertia: inertia
}
}
pub fn set_joint(&self, new_joint: Joint) -> Segment {
Segment {
joint: new_joint,
f_tip: self.f_tip,
inertia: self.inertia,
}
}
pub fn set_tip_frame(&self, new_f_tip: Frame) -> Segment {
let frame = invert_frame(self.joint.pose(0.0)) * new_f_tip;
Segment {
joint: self.joint,
f_tip: frame,
inertia: self.inertia,
}
}
pub fn set_inertia(&self, new_inertia: RigidBodyInertia) -> Segment {
Segment {
joint: self.joint,
f_tip: self.f_tip,
inertia: new_inertia,
}
}
pub fn get_joint_type(&self) -> JointType {
self.joint.get_joint_type()
}
pub fn pose(&self, joint_state: f64) -> Frame {
self.joint.pose(joint_state) * self.f_tip
}
pub fn twist(&self, joint_state: f64, qdot: f64) -> Twist {
new_ref_point(
self.joint.twist(qdot),
self.joint.pose(joint_state).get_rotation() *
self.f_tip.get_translation())
}
}
#[cfg(test)]
mod tests {
use nalgebra::geometry::{Isometry3, Translation3, UnitQuaternion};
use crate::joint::{Joint, JointType};
use crate::geometry::{Frame, Twist, get_twist_error, get_frame_error};
use crate::segment::{Segment};
#[test]
fn calculate_pose() {
let joint = Joint::default().set_type(JointType::RotZ).set_offset(2.36)
.set_scale(3.5);
let f_tip = Isometry3::from_parts(
Translation3::new(0.1, -2.0, 0.5),
UnitQuaternion::from_euler_angles(1.0, 0.5, -0.4))
.to_homogeneous();
let joint_state = 2.1;
let segment = Segment::new(joint, f_tip, 0.0);
let result = Frame::new(
0.689601, -0.0171617, 0.723987, 1.79963,
0.542773, 0.674079, -0.501015, -0.878265,
-0.479426, 0.73846, 0.47416, 0.5,
0.0, 0.0, 0.0, 1.0);
let error = get_frame_error(result, segment.pose(joint_state));
assert!(error < 0.00001);
}
#[test]
fn calculate_twist() {
let joint = Joint::default().set_type(JointType::RotZ).set_offset(2.36)
.set_scale(3.5);
let f_tip = Isometry3::from_parts(
Translation3::new(0.1, -2.0, 0.5),
UnitQuaternion::from_euler_angles(1.0, 0.5, -0.4))
.to_homogeneous();
let joint_state = 2.1;
let qdot = 0.3;
let segment = Segment::new(joint, f_tip, 0.0);
let result = Twist::new(0.92217, 1.88961, 0.0, 0.0, 0.0, 1.05);
let error = get_twist_error(result, segment.twist(joint_state, qdot));
assert!(error < 0.001);
}
}