forked from viamrobotics/rdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular_velocity.go
45 lines (37 loc) · 1.44 KB
/
angular_velocity.go
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
package spatialmath
import (
"math"
"github.com/golang/geo/r3"
)
// AngularVelocity contains angular velocity in deg/s across x/y/z axes.
type AngularVelocity r3.Vector
// OrientationToAngularVel calculates an angular velocity based on an orientation change over a time differnce.
func OrientationToAngularVel(diff Orientation, dt float64) AngularVelocity {
return EulerToAngVel(*diff.EulerAngles(), dt)
}
// EulerToAngVel calculates an angular velocity based on an orientation change expressed in euler angles over a time differnce.
func EulerToAngVel(diffEu EulerAngles, dt float64) AngularVelocity {
return AngularVelocity{
X: diffEu.Roll/dt - math.Sin(diffEu.Pitch)*diffEu.Yaw/dt,
Y: math.Cos(diffEu.Roll)*diffEu.Pitch/dt + math.Cos(diffEu.Pitch)*math.Sin(diffEu.Roll)*diffEu.Yaw/dt,
Z: -math.Sin(diffEu.Roll)*diffEu.Pitch/dt + math.Cos(diffEu.Pitch)*math.Cos(diffEu.Roll)*diffEu.Yaw/dt,
}
}
// MulAngVel scales the angular velocity by a single scalar value.
func (av *AngularVelocity) MulAngVel(t float64) AngularVelocity {
return AngularVelocity{
X: t * av.X,
Y: t * av.Y,
Z: t * av.Z,
}
}
// R3ToAngVel converts an r3Vector to an angular velocity.
func R3ToAngVel(vec r3.Vector) *AngularVelocity {
return &AngularVelocity{X: vec.X, Y: vec.Y, Z: vec.Z}
}
// PointAngVel returns the angular velocity using the defiition
// r X v / |r|.
func PointAngVel(r, v r3.Vector) AngularVelocity {
r.Normalize()
return AngularVelocity(r.Cross(v))
}