13
13
14
14
class Simulator (Node ):
15
15
# simulator constants:
16
+ UTM_EAST_ZERO = 589702.87
17
+ UTM_NORTH_ZERO = 4477172.947
18
+ UTM_ZONE_NUM = 17
19
+ UTM_ZONE_LETTER = "T"
20
+ #TODO: make these values accurate
21
+ WHEELBASE_SC = 1.17
22
+ WHEELBASE_NAND = 1.17
16
23
17
24
def __init__ (self ):
18
25
super ().__init__ ('sim_single' )
19
- UTM_EAST_ZERO = 589702.87
20
- UTM_NORTH_ZERO = 4477172.947
21
- UTM_ZONE_NUM = 17
22
- UTM_ZONE_LETTER = "T"
23
- #TODO: make these values accurate
24
- WHEELBASE_SC = 1.17
25
- WHEELBASE_NAND = 1.17
26
+ self .get_logger ().info ('INITIALIZED.' )
26
27
27
28
self .starting_poses = {
28
29
"Hill1_NAND" : (Simulator .UTM_EAST_ZERO + 0 , Simulator .UTM_NORTH_ZERO + 0 , - 110 ),
@@ -60,19 +61,22 @@ def __init__(self):
60
61
)
61
62
if (self .get_namespace () == "/SC" ):
62
63
self .buggy_name = "SC"
63
- init_pose = self .starting_poses ["Hill_1SC " ]
64
-
64
+ init_pose = self .starting_poses ["Hill1_SC " ]
65
+ self . wheelbase = Simulator . WHEELBASE_SC
65
66
66
67
if (self .get_namespace () == "/NAND" ):
67
68
self .buggy_name = "NAND"
68
- init_pose = self .starting_poses ["Hill_1NAND" ]
69
+ init_pose = self .starting_poses ["Hill1_NAND" ]
70
+ self .wheelbase = Simulator .WHEELBASE_NAND
71
+
69
72
70
73
self .e_utm , self .n_utm , self .heading = init_pose
71
74
# TODO: do we want to not hard code this
72
75
self .velocity = 12 # m/s
73
76
self .steering_angle = 0 # degrees
74
77
self .rate = 200 # Hz
75
78
self .pub_skip = 2 # publish every pub_skip ticks
79
+ self .pub_tick_count = 0
76
80
77
81
self .lock = threading .Lock ()
78
82
@@ -97,7 +101,7 @@ def get_steering_arc(self):
97
101
return Simulator .WHEELBASE / np .tan (np .deg2rad (steering_angle ))
98
102
99
103
def dynamics (self , state , v ):
100
- l = Simulator . WHEELBASE
104
+ l = self . wheelbase
101
105
_ , _ , theta , delta = state
102
106
103
107
return np .array ([v * np .cos (theta ),
@@ -151,49 +155,50 @@ def publish(self):
151
155
nsf = NavSatFix ()
152
156
nsf .latitude = lat
153
157
nsf .longitude = long
154
- nsf .altitude = 260
158
+ nsf .altitude = float ( 260 )
155
159
nsf .header .stamp = time_stamp
156
- self .navsatfix_publisher .publish (nsf )
157
160
158
- if Simulator .NOISE :
159
- lat_noisy = lat + np .random .normal (0 , 1e-6 )
160
- long_noisy = long + np .random .normal (0 , 1e-6 )
161
- nsf_noisy = NavSatFix ()
162
- nsf_noisy .latitude = lat_noisy
163
- nsf_noisy .longitude = long_noisy
164
- nsf_noisy .header .stamp = time_stamp
165
- self .navsatfix_noisy_publisher .publish (nsf_noisy )
161
+ lat_noisy = lat + np .random .normal (0 , 1e-6 )
162
+ long_noisy = long + np .random .normal (0 , 1e-6 )
163
+ nsf_noisy = NavSatFix ()
164
+ nsf_noisy .latitude = lat_noisy
165
+ nsf_noisy .longitude = long_noisy
166
+ nsf_noisy .header .stamp = time_stamp
167
+ self .navsatfix_noisy_publisher .publish (nsf_noisy )
166
168
167
169
odom = Odometry ()
168
170
odom .header .stamp = time_stamp
169
171
170
172
odom_pose = Pose ()
171
- odom_pose .position .x = long
172
- odom_pose .position .y = lat
173
- odom_pose .position .z = 260
173
+ odom_pose .position .x = float ( long )
174
+ odom_pose .position .y = float ( lat )
175
+ odom_pose .position .z = float ( 260 )
174
176
175
177
odom_pose .orientation .z = np .sin (np .deg2rad (self .heading ) / 2 )
176
178
odom_pose .orientation .w = np .cos (np .deg2rad (self .heading ) / 2 )
177
179
178
180
odom_twist = Twist ()
179
- odom_twist .linear .x = velocity
181
+ odom_twist .linear .x = float ( velocity )
180
182
181
183
odom .pose = PoseWithCovariance (pose = odom_pose )
182
184
odom .twist = TwistWithCovariance (twist = odom_twist )
183
185
184
186
self .pose_publisher .publish (odom )
185
187
186
188
def loop (self ):
187
- rate = self . create_rate ( self . rate )
188
- pub_tick_count = 0
189
+ msg = Float64 ( )
190
+ msg . data = float ( self . i )
189
191
190
- self .step ()
192
+ self .number_publisher .publish (msg )
193
+ self .i += 1
191
194
192
- if pub_tick_count == self .pub_skip :
195
+ self .step ()
196
+ if self .pub_tick_count == self .pub_skip :
193
197
self .publish ()
194
- pub_tick_count = 0
198
+ self . pub_tick_count = 0
195
199
else :
196
- pub_tick_count += 1
200
+ self .pub_tick_count += 1
201
+
197
202
198
203
199
204
0 commit comments