-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_init.py
More file actions
94 lines (73 loc) · 2.79 KB
/
Copy pathrun_init.py
File metadata and controls
94 lines (73 loc) · 2.79 KB
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
"""
"""
from __future__ import print_function
from src.env import VrepEnvironment
from src.agents import Pioneer
from src.disp import Display
import settings
import time, argparse
import matplotlib.pyplot as plt
""" Motors:
1. agent.change_velocity([ speed_left: float, speed_right: float ])
Set the target angular velocities of left
and right motors with a LIST of values:
e.g. [1., 1.] in radians/s.
Values in range [-5:5] (above these
values the control accuracy decreases)
2. agent.current_velocity()
----
Returns a LIST of current angular velocities
of the motors
[speed_left: float, speed_right: float] in radians/s.
Lidar:
3. agent.read_lidar()
----
Returns a list of floating point numbers that you can
indicate the distance towards the closest object at a particular angle.
Basic configuration of the lidar:
Angle: [-135:135] Starting with the
leftmost lidar point -> clockwise
Agent:
You can access these attributes to get information about the agent's positions
4. agent.pos
----
Current x,y position of the agent (derived from
SLAM data)
5. agent.position_history
A deque containing N last positions of the agent
(200 by default, can be changed in settings.py)
"""
###########
###########
def loop(agent):
"""
Robot control loop
Your code goes here
"""
# Example:
agent.change_velocity([2, 2])
##########
##########
if __name__ == "__main__":
plt.ion()
# Initialize and start the environment
environment = VrepEnvironment(settings.SCENES + '/room_static.ttt') # Open the file containing our scene (robot and its environment)
environment.connect() # Connect python to the simulator's remote API
agent = Pioneer(environment)
display = Display(agent, False)
print('\nDemonstration of Simultaneous Localization and Mapping using CoppeliaSim robot simulation software. \nPress "CTRL+C" to exit.\n')
start = time.time()
step = 0
done = False
environment.start_simulation()
time.sleep(1)
try:
while step < settings.simulation_steps and not done:
display.update() # Update the SLAM display
loop(agent) # Control loop
step += 1
except KeyboardInterrupt:
print('\n\nInterrupted! Time: {}s'.format(time.time()-start))
display.close()
environment.stop_simulation()
environment.disconnect()