forked from equinor/flotilla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPose.cs
140 lines (125 loc) · 3.3 KB
/
Pose.cs
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
using System.ComponentModel.DataAnnotations;
using Api.Services.Models;
using Microsoft.EntityFrameworkCore;
#nullable disable
namespace Api.Database.Models
{
[Owned]
public class Orientation
{
public float X { get; set; }
public float Y { get; set; }
public float Z { get; set; }
public float W { get; set; }
public Orientation()
{
X = 0;
Y = 0;
Z = 0;
W = 1;
}
public Orientation(float x = 0, float y = 0, float z = 0, float w = 1)
{
X = x;
Y = y;
Z = z;
W = w;
}
public override bool Equals(object obj)
{
if (obj is not Orientation)
return false;
const float Tolerance = 1e-6F;
var orientation = (Orientation)obj;
if (MathF.Abs(orientation.X - X) > Tolerance)
{
return false;
}
if (MathF.Abs(orientation.Y - Y) > Tolerance)
{
return false;
}
if (MathF.Abs(orientation.Z - Z) > Tolerance)
{
return false;
}
if (MathF.Abs(orientation.W - W) > Tolerance)
{
return false;
}
return true;
}
public override int GetHashCode()
{
throw new NotImplementedException();
}
}
[Owned]
public class Position
{
public float X { get; set; }
public float Y { get; set; }
public float Z { get; set; }
public Position()
{
X = 0;
Y = 0;
Z = 0;
}
public Position(float x = 0, float y = 0, float z = 0)
{
X = x;
Y = y;
Z = z;
}
}
[Owned]
public class Pose
{
[Required]
public Position Position { get; set; }
[Required]
public Orientation Orientation { get; set; }
// Since this is a ground robot the only quaternion vector
// that makes sense is up (0, 0, 1)
public Orientation AxisAngleToQuaternion(float angle)
{
var quaternion = new Orientation()
{
X = 0,
Y = 0,
Z = MathF.Sin(angle / 2),
W = MathF.Cos(angle / 2)
};
return quaternion;
}
public Pose()
{
Position = new Position();
Orientation = new Orientation();
}
public Pose(
float x_pos,
float y_pos,
float z_pos,
float x_ori,
float y_ori,
float z_ori,
float w
)
{
Position = new Position(x_pos, y_pos, z_pos);
Orientation = new Orientation(x_ori, y_ori, z_ori, w);
}
public Pose(EchoVector enuPosition, float angle)
{
Position = new Position(enuPosition.East, enuPosition.North, enuPosition.Up);
Orientation = AxisAngleToQuaternion(angle);
}
public Pose(Position position, Orientation orientation)
{
Position = position;
Orientation = orientation;
}
}
}