-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathexample.py
More file actions
74 lines (50 loc) · 2.15 KB
/
example.py
File metadata and controls
74 lines (50 loc) · 2.15 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
'''
@ 2025, Copyright AVIS Engine
- An Example Compatible with AVISEngine version 2.0.1 / 1.2.4 (ACL Branch) or higher
'''
import avisengine
import config
import time
import cv2
# Creating an instance of the Car class
car = avisengine.Car()
# Connecting to the server (Simulator)
car.connect(config.SIMULATOR_IP, config.SIMULATOR_PORT)
# Counter variable
counter = 0
debug_mode = False
# Sleep for 3 seconds to make sure that client connected to the simulator
time.sleep(3)
try:
while(True):
# Counting the loops
counter = counter + 1
# Set the power of the engine the car to 20, Negative number for reverse move, Range [-100,100]
car.setSpeed(20)
# Set the Steering of the car -10 degree from center, results the car to steer to the left
car.setSteering(-10)
# Set the angle between sensor rays to 45 degrees, Use this only if you want to set it from python client
# Notice: Once it is set from the client, it cannot be changed using the GUI
car.setSensorAngle(45)
# Get the data. Need to call it every time getting image and sensor data
car.getData()
# Display the FPS on the frame
# Start getting image and sensor data after 4 loops
if(counter > 4):
# Returns a list with three items which the 1st one is Left sensor data\
# the 2nd one is the Middle Sensor data, and the 3rd is the Right one.
sensors = car.getSensors()
# Returns an opencv image type array. if you use PIL you need to invert the color channels.
image = car.getImage()
# Returns an integer which is the real time car speed in KMH
carSpeed = car.getSpeed()
if(debug_mode):
print(f"Speed : {carSpeed}")
print(f'Left : {str(sensors[0])} | Middle : {str(sensors[1])} | Right : {str(sensors[2])}')
if image is not None and image.any():
# Showing the opencv type image
cv2.imshow('frames', image)
if cv2.waitKey(10) == ord('q'):
break
finally:
car.stop()