Skip to content

Commit 388682b

Browse files
committed
Initial Commit
Initial commit of the python simulation code. #TODO: Cleanup the code and add more comments
1 parent b66faa8 commit 388682b

File tree

5 files changed

+1397
-1
lines changed

5 files changed

+1397
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
# assignment-target-tracking
1+
# assignment-target-tracking
2+
3+
Target.py contains the class file generating targets
4+
5+
Robot.py contains the class file generating robots
6+
7+
Sensor.py contains the main functions for the simulation. Including EKF function, and python simulation action selection.

Robot.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import numpy as np
2+
3+
class Robot:
4+
def __init__(self, sz, id, scene):
5+
"""
6+
Input:
7+
sz - environment size
8+
id - ID of the robot
9+
type- type of the robot, 1 - range and bearing, 2 - range, 3 - bearing
10+
"""
11+
xy_loc = np.round(
12+
sz
13+
* np.random.rand(
14+
2,
15+
),
16+
1,
17+
)
18+
heading = np.round(np.random.rand(1) * 2 * np.pi - np.pi, 4)
19+
self.location = np.append(xy_loc, heading)
20+
self.id = id
21+
self.step_xy = 0.5
22+
self.step_th = 0.3
23+
self.cov_list = None
24+
self.action_num = None
25+
if scene != 4:
26+
self.type = scene
27+
else:
28+
self.type = np.random.randint(2, 4, 1)[0]
29+
self.pos_hist = None
30+
31+
def set_steps(self, num, Nt):
32+
self.action_num = num
33+
self.cov_list = np.zeros((self.action_num, Nt))
34+
return None
35+
36+
def update_cov(self, new_cov, index):
37+
self.cov_list[index] = new_cov
38+
return None
39+
40+
def update_pos(self, pos_new):
41+
self.location = pos_new
42+
return None
43+
44+
def get_cov(self):
45+
return self.cov_list
46+
47+
def get_action(self, u, dt):
48+
"""
49+
use unicycle model for the robot to perform a
50+
:param u: linear velocity, and angular
51+
:param dt: time step
52+
:return: new position
53+
"""
54+
v = u[0]
55+
w = u[1]
56+
curr_pos = self.location
57+
# new_x = curr_pos[0] + v * dt * np.cos(curr_pos[2])
58+
# new_y = curr_pos[1] + v * dt * np.sin(curr_pos[2])
59+
# new_th = curr_pos[2] + w * dt
60+
61+
new_th = curr_pos[2] + w * dt
62+
new_x = curr_pos[0] + v * dt * np.cos(new_th)
63+
new_y = curr_pos[1] + v * dt * np.sin(new_th)
64+
return np.array([new_x, new_y, new_th])
65+
66+
def __str__(self):
67+
return f"robot {self.id} has location {self.location}"

0 commit comments

Comments
 (0)