|
1 | 1 | '''
|
2 |
| -@ 2022, Copyright AVIS Engine |
3 |
| -Example Compatible with AVISEngine version 2.0.1 or higher |
| 2 | +@ 2023, Copyright AVIS Engine |
| 3 | +- An Example Compatible with AVISEngine version 2.0.1 or higher |
4 | 4 | '''
|
5 |
| -import AVISEngine |
| 5 | +import avisengine |
6 | 6 | import config
|
7 | 7 | import time
|
8 | 8 | import cv2
|
9 | 9 |
|
10 |
| -#Calling the class |
11 |
| -car = AVISEngine.Car() |
| 10 | +# Creating an instance of the Car class |
| 11 | +car = avisengine.Car() |
12 | 12 |
|
13 |
| -#connecting to the server (Simulator) |
| 13 | +# Connecting to the server (Simulator) |
14 | 14 | car.connect(config.SIMULATOR_IP, config.SIMULATOR_PORT)
|
15 | 15 |
|
16 |
| -#Counter variable |
| 16 | +# Counter variable |
17 | 17 | counter = 0
|
18 | 18 |
|
19 | 19 | debug_mode = False
|
20 | 20 |
|
21 |
| -#Sleep for 3 seconds to make sure that client connected to the simulator |
| 21 | +# Sleep for 3 seconds to make sure that client connected to the simulator |
22 | 22 | time.sleep(3)
|
23 | 23 |
|
24 | 24 | try:
|
25 | 25 | while(True):
|
26 |
| - #Counting the loops |
27 |
| - |
| 26 | + # Counting the loops |
28 | 27 | counter = counter + 1
|
29 | 28 |
|
30 |
| - #Set the power of the engine the car to 20, Negative number for reverse move, Range [-100,100] |
| 29 | + # Set the power of the engine the car to 20, Negative number for reverse move, Range [-100,100] |
31 | 30 | car.setSpeed(20)
|
32 | 31 |
|
33 |
| - #Set the Steering of the car -10 degree from center |
| 32 | + # Set the Steering of the car -10 degree from center, results the car to steer to the left |
34 | 33 | car.setSteering(-10)
|
35 | 34 |
|
36 |
| - #Set the angle between sensor rays to 30 degrees, Use this only if you want to set it from python client |
| 35 | + # Set the angle between sensor rays to 30 degrees, Use this only if you want to set it from python client |
37 | 36 | car.setSensorAngle(40)
|
38 | 37 |
|
39 |
| - #Get the data. Need to call it every time getting image and sensor data |
| 38 | + # Get the data. Need to call it every time getting image and sensor data |
40 | 39 | car.getData()
|
41 | 40 |
|
42 |
| - #Start getting image and sensor data after 4 loops. for unclear some reason it's really important |
| 41 | + # Start getting image and sensor data after 4 loops |
43 | 42 | if(counter > 4):
|
44 | 43 |
|
45 |
| - #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. |
| 44 | + # Returns a list with three items which the 1st one is Left sensor data\ |
| 45 | + # the 2nd one is the Middle Sensor data, and the 3rd is the Right one. |
46 | 46 | sensors = car.getSensors()
|
47 |
| - #EX) sensors[0] returns an int for left sensor data in cm |
48 | 47 |
|
49 |
| - #returns an opencv image type array. if you use PIL you need to invert the color channels. |
| 48 | + # Returns an opencv image type array. if you use PIL you need to invert the color channels. |
50 | 49 | image = car.getImage()
|
51 | 50 |
|
52 |
| - #returns an integer which is the real time car speed in KMH |
| 51 | + # Returns an integer which is the real time car speed in KMH |
53 | 52 | carSpeed = car.getSpeed()
|
54 | 53 |
|
55 |
| - #Don't print data for better performance |
56 | 54 | if(debug_mode):
|
57 |
| - print("Speed : ",carSpeed) |
58 |
| - print("Left : " + str(sensors[0]) + " | " + "Middle : " + str(sensors[1]) +" | " + "Right : " + str(sensors[2])) |
59 |
| - |
60 |
| - #Showing the opencv type image |
| 55 | + print(f"Speed : {carSpeed}") |
| 56 | + print(f'Left : {str(sensors[0])} | Middle : {str(sensors[1])} | Right : {str(sensors[2])}') |
| 57 | + |
| 58 | + # Showing the opencv type image |
61 | 59 | cv2.imshow('frames', image)
|
62 |
| - #Break the loop when q pressed |
| 60 | + |
| 61 | + |
63 | 62 | if cv2.waitKey(10) == ord('q'):
|
64 | 63 | break
|
| 64 | + |
65 | 65 | time.sleep(0.001)
|
66 | 66 |
|
67 | 67 | finally:
|
|
0 commit comments