-
Notifications
You must be signed in to change notification settings - Fork 2
/
Sensor.java
159 lines (127 loc) · 3.34 KB
/
Sensor.java
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
150
151
152
153
154
155
156
157
158
159
/**
**********************************************************************************************************************
* @file Sensor.java
* @author Steve Ding, Colin Gallacher
* @version V1.0.0
* @date 30-July-2017
* @brief Sensor class definition
**********************************************************************************************************************
* @attention
*
*
**********************************************************************************************************************
*/
public class Sensor{
private int encoder = 0;
private int direction = 0;
private float encoder_offset = 0;
private float encoder_resolution = 0;
private float value = 0;
private int port = 0;
/**
* Constructs a Sensor set using motor port position one
*/
public Sensor(){
this(0, 0, 0, 0, 0);
}
/**
* Constructs a Sensor with the given motor port position, to be initialized with the given angular offset,
* at the specified step resoluiton (used for construction of encoder sensor)
*
* @param encoder encoder index
* @param offset initial offset in degrees that the encoder sensor should be initialized at
* @param resolution step resolution of the encoder sensor
* @param port specific motor port the encoder sensor is connect at (usually same as actuator)
*/
public Sensor(int encoder, int direction, float offset, float resolution, int port){
this.encoder = encoder;
this.direction = direction;
this.encoder_offset = offset;
this.encoder_resolution = resolution;
this.port = port;
}
/**
* Set encoder index parameter of sensor
*
* @param encoder index
*/
public void set_encoder(int encoder){
this.encoder = encoder;
}
/**
* Set encoder direction of detection
*
* @param encoder index
*/
public void set_direction(int direction){
this.direction = direction;
}
/**
* Set encoder offset parameter of sensor
*
* @param offset initial angular offset in degrees
*/
public void set_offset(float offset){
this.encoder_offset = offset;
}
/**
* Set encoder resolution parameter of sensor
*
* @param resolution step resolution of encoder sensor
*/
public void set_resolution(float resolution){
this.encoder_resolution = resolution;
}
/**
* Set motor port position to be used by sensor
*
* @param port motor port position (motor port connection on Haply board)
*/
public void set_port(int port){
this.port = port;
}
/**
* Set sensor value variable to the specified angle
*
* @param value sensor value
*/
public void set_value(float value){
this.value = value;
}
/**
* @return encoder index
*/
public int get_encoder(){
return encoder;
}
/**
* @return encoder direction
*/
public int get_direction(){
return direction;
}
/**
* @return current offset parameter
*/
public float get_offset(){
return encoder_offset;
}
/**
* @return encoder resolution of encoder sensor being used
*/
public float get_resolution(){
return encoder_resolution;
}
/**
* @return current motor port position
*/
public int get_port(){
return port;
}
/**
* @return current sensor value information
*/
public float get_value(){
return value;
}
}