tricodex commited on
Commit
2fca4ce
·
1 Parent(s): 3458983
learning_machines_robobo/examples/full_project_setup/catkin_ws/src/learning_machines/src/learning_machines/__init__.py CHANGED
@@ -1,7 +1,7 @@
1
- # from .task0_g6 import run_all_actions
2
 
3
- # __all__ = ("run_all_actions",)
4
 
5
- from .ppo_train import run
6
 
7
- __all__ = ("run",)
 
1
+ from .task0_g6 import run_all_actions
2
 
3
+ __all__ = ("run_all_actions",)
4
 
5
+ # from .ppo_train import run
6
 
7
+ # __all__ = ("run",)
learning_machines_robobo/examples/full_project_setup/catkin_ws/src/learning_machines/src/learning_machines/robobo.txt DELETED
@@ -1 +0,0 @@
1
- # good turn irl (25 -25 1100)
 
 
learning_machines_robobo/examples/full_project_setup/catkin_ws/src/learning_machines/src/learning_machines/task0.py DELETED
@@ -1,91 +0,0 @@
1
- import cv2
2
- import matplotlib.pyplot as plt
3
- import csv
4
- from data_files import FIGRURES_DIR
5
- from robobo_interface import (
6
- IRobobo,
7
- SimulationRobobo,
8
- HardwareRobobo,
9
- )
10
- from datetime import datetime
11
- current_datetime = datetime.now().strftime("%Y%m%d-%H%M%S")
12
-
13
- def plot_sensor_data(irs, title):
14
- plt.figure()
15
- for sensor_index in range(len(irs[0])):
16
- sensor_values = [data[sensor_index] for data in irs]
17
- plt.plot(sensor_values, label=f'Sensor {sensor_index + 1}')
18
- plt.xlabel('Steps')
19
- plt.ylabel('IR Sensor Values')
20
- plt.title(title)
21
- plt.legend()
22
- plt.savefig(str(FIGRURES_DIR / f"{title}_sensor_plot{current_datetime}.png"))
23
-
24
- def save_to_csv(sensor_readings, filename):
25
- with open(filename, 'w', newline='') as csvfile:
26
- writer = csv.writer(csvfile)
27
- writer.writerow(['BackL', 'BackR', 'FrontL', 'FrontR', 'FrontC', 'FrontRR', 'BackC', 'FrontLL'])
28
- for data in sensor_readings:
29
- writer.writerow(data)
30
-
31
- def task_example_1(rob: IRobobo, steps: int = 100):
32
- """Task: Go straight until an object is near, then turn right without touching it."""
33
- sensor_readings = []
34
- rob.play_simulation()
35
- try:
36
- for step in range(steps):
37
- irs = rob.read_irs()
38
- sensor_readings.append(irs)
39
- if irs[4] > 40 or irs[5] > 40 or irs[7] > 40: # All front sensors
40
- rob.move(0, 0, 0) # Stop
41
- rob.sleep(0.1)
42
- rob.move(50, -50, 500) # Turn right
43
- rob.sleep(0.1)
44
- rob.move(50, 50, 1000)
45
- rob.sleep(10)
46
- print(f"Steps run: {step + 1}")
47
- break
48
- else:
49
- rob.move(50, 50, 100) # Go straight
50
- rob.sleep(0.1)
51
- finally:
52
- rob.stop_simulation()
53
- plot_sensor_data(sensor_readings, "taske_1")
54
- save_to_csv(sensor_readings, str(FIGRURES_DIR / f"1_{current_datetime}.csv"))
55
-
56
- def task_example_2(rob: IRobobo, steps: int = 100):
57
- """Task: Go straight until it touches the wall, then go backward."""
58
- sensor_readings = []
59
- rob.play_simulation()
60
- try:
61
- for step in range(steps):
62
- irs = rob.read_irs()
63
- sensor_readings.append(irs)
64
- if irs[4] > 50: # Front center sensor
65
- rob.move(0, 0, 0) # Stop
66
- rob.sleep(0.1)
67
- rob.move(50, -50, 500) # Turn right
68
- rob.sleep(0.5)
69
- if irs[4] < 0.5:
70
- rob.move(-50, -50, 1000) # Move backward
71
- rob.sleep(5)
72
- rob.move(0, 0, 0) # Stop
73
- print(f"Steps run: {step + 1}")
74
- break
75
- else:
76
- rob.move(50, 50, 100) # Go straight
77
- rob.sleep(0.1)
78
- finally:
79
- rob.stop_simulation()
80
- plot_sensor_data(sensor_readings, "task_2")
81
- save_to_csv(sensor_readings, str(FIGRURES_DIR / f"2_{current_datetime}.csv"))
82
-
83
- def run_all_actions(rob: IRobobo):
84
- if isinstance(rob, SimulationRobobo):
85
- rob.play_simulation()
86
- print("task 1")
87
- task_example_1(rob, steps=250)
88
- print("task 2")
89
- task_example_2(rob, steps=250)
90
- if isinstance(rob, SimulationRobobo):
91
- rob.stop_simulation()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
learning_machines_robobo/examples/full_project_setup/catkin_ws/src/learning_machines/src/learning_machines/test_actions_share.py DELETED
@@ -1,123 +0,0 @@
1
- import cv2
2
- import matplotlib.pyplot as plt
3
- import csv
4
- from data_files import FIGRURES_DIR
5
- from robobo_interface import (
6
- IRobobo,
7
- SimulationRobobo,
8
- HardwareRobobo,
9
- )
10
- from datetime import datetime
11
- current_datetime = datetime.now().strftime("%Y%m%d-%H%M%S")
12
-
13
- def plot_sensor_data(irs, title):
14
- plt.figure()
15
- for sensor_index in range(len(irs[0])):
16
- sensor_values = [data[sensor_index] for data in irs]
17
- plt.plot(sensor_values, label=f'Sensor {sensor_index + 1}')
18
- plt.xlabel('Steps')
19
- plt.ylabel('IR Sensor Values')
20
- plt.title(title)
21
- plt.legend()
22
- plt.savefig(str(FIGRURES_DIR / f"{title}_sensor_plot{current_datetime}.png"))
23
-
24
- def save_to_csv(sensor_readings, filename):
25
- with open(filename, 'w', newline='') as csvfile:
26
- writer = csv.writer(csvfile)
27
- writer.writerow(['BackL', 'BackR', 'FrontL', 'FrontR', 'FrontC', 'FrontRR', 'BackC', 'FrontLL'])
28
- for data in sensor_readings:
29
- writer.writerow(data)
30
-
31
- def task_example_1(rob: IRobobo, steps: int = 100):
32
- """Task: Go straight until an object is near, then turn right without touching it."""
33
- sensor_readings = []
34
- #rob.play_simulation()
35
- try:
36
- for step in range(steps):
37
- irs = rob.read_irs()
38
- sensor_readings.append(irs)
39
- if irs[4] > 40 or irs[5] > 40 or irs[7] > 40: # All front sensors
40
- rob.move(0, 0, 0) # Stop
41
- rob.sleep(0.1)
42
- rob.move(50, -50, 500) # Turn right
43
- rob.sleep(0.1)
44
- rob.move(50, 50, 1000)
45
- rob.sleep(10)
46
- print(f"Steps run: {step + 1}")
47
- break
48
- else:
49
- rob.move(50, 50, 100) # Go straight
50
- rob.sleep(0.1)
51
- finally:
52
- #rob.stop_simulation()
53
- pass
54
- plot_sensor_data(sensor_readings, "taske_1")
55
- save_to_csv(sensor_readings, str(FIGRURES_DIR / f"1_{current_datetime}.csv"))
56
-
57
- def task_example_2(rob: IRobobo, steps: int = 100):
58
- """Task: Go straight until it touches the wall, then go backward."""
59
- sensor_readings = []
60
- turns = 0
61
- obstacle_sensor_threshold = 10
62
- wall_sensor_threshold = 50
63
- #rob.play_simulation()
64
- try:
65
- for step in range(steps):
66
- irs = rob.read_irs()
67
- sensor_readings.append(irs)
68
-
69
-
70
- if irs[4] > 10 or irs[5] > 10 or irs[7] > 10:
71
- rob.move(-50, -50, 150) # Move backward
72
- # rob.sleep(0.3)
73
- # rob.move(0, 0, 0) # Stop
74
- if irs[5] > 10:
75
- rob.move(50, -50, 850) # turn right 90 degrees
76
- elif irs[7] > 10:
77
- rob.move(-50, 50, 850)
78
- else:
79
- rob.move(50, -50, 850)
80
- # rob.sleep(0.85)
81
- print("Obstacle Dodge")
82
- else:
83
- rob.move(75, 75, 250) # Go straight
84
- # rob.sleep(0.250)
85
-
86
- # print(irs[4])
87
- # 'BackL', 'BackR', 'FrontL', 'FrontR', 'FrontC', 'FrontRR'5 'BackC', 'FrontLL'7
88
-
89
- if irs[4] > 40 or irs[2] > 70 or irs[3] > 70:
90
- # if irs[4] > 60:
91
- # rob.move(-50, -50, 1000)
92
- rob.move(-50, -50, 1000) # Move backward
93
- # rob.sleep(1)
94
- rob.move(0, 0, 0) # Stop
95
- rob.move(50, -50, 600) # turn right 90 degrees
96
- # rob.sleep(0.6)
97
- print("Wall Dodge")
98
- turns += 1 # Turn
99
- print(f"Steps run: {step + 1} for turn: {turns}")
100
-
101
-
102
- else:
103
- rob.move(75, 75, 250) # Go straight
104
- rob.sleep(0.25)
105
-
106
- if turns == 4:
107
- print("Done")
108
- break
109
- finally:
110
- #rob.stop_simulation()
111
- pass
112
- plot_sensor_data(sensor_readings, "task_2")
113
- save_to_csv(sensor_readings, str(FIGRURES_DIR / f"2_o{obstacle_sensor_threshold}_w{wall_sensor_threshold}_{current_datetime}.csv"))
114
-
115
- def run_all_actions(rob: IRobobo):
116
- if isinstance(rob, SimulationRobobo):
117
- rob.play_simulation()
118
- # print("task 1")
119
- # task_example_1(rob, steps=1000)
120
- print("task 2")
121
- task_example_2(rob, steps=300)
122
- if isinstance(rob, SimulationRobobo):
123
- rob.stop_simulation()