-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest_robotcrawler.py
More file actions
284 lines (248 loc) · 11.5 KB
/
test_robotcrawler.py
File metadata and controls
284 lines (248 loc) · 11.5 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
import unittest
from typing_extensions import override
from edg import *
from .util import run_test_board
class ServoFeedbackConnector(Connector, Block):
"""4-pin connector modeling the FS90-FB micro servo with positional feedback,
https://www.pololu.com/product/3436
"""
def __init__(self) -> None:
super().__init__()
self.gnd = self.Port(Ground(), [Common])
self.pwr = self.Port(VoltageSink(current_draw=(5, 800) * mAmp), [Power]) # idle @ 4.8v to stall @ 6v
self.pwm = self.Port(DigitalSink(), [Input]) # no specs given
self.fb = self.Port(
AnalogSource( # no specs given
voltage_out=(0.9, 2.1)
* Volt, # from https://www.pololu.com/blog/814/new-products-special-servos-with-position-feedback
signal_out=(0.9, 2.1) * Volt,
)
)
self.conn = self.Block(PinHeader254(4)).connected({"3": self.gnd, "2": self.pwr, "1": self.pwm, "4": self.fb})
@abstract_block
class RobotCrawlerSpec(BoardTop):
"""Example spec for a robot crawler, that defines the needed interface blocks but no connections
or infrastructure parts"""
SERVO_COUNT = 12
SERVO_CAM_COUNT = 2
def __init__(self) -> None:
super().__init__()
self.batt = self.Block(LipoConnector(actual_voltage=(3.7, 4.2) * Volt))
self.servos = ElementDict[ServoFeedbackConnector]()
for i in range(self.SERVO_COUNT):
self.servos[str(i)] = self.Block(ServoFeedbackConnector())
self.imu = self.Block(Lsm6ds3trc())
self.servos_cam = ElementDict[ServoFeedbackConnector]()
for i in range(self.SERVO_CAM_COUNT):
self.servos_cam[str(i)] = self.Block(ServoFeedbackConnector())
class RobotCrawler(RobotCrawlerSpec, JlcBoardTop):
"""Implementation of the crawler robot, that implements what is needed to connect the interface blocks
as well as optional additional blocks.
"""
@override
def contents(self) -> None:
super().contents()
self.vbatt = self.connect(self.batt.pwr)
self.gnd = self.connect(self.batt.gnd)
self.tp_vbatt = self.Block(VoltageTestPoint()).connected(self.batt.pwr)
self.tp_gnd = self.Block(GroundTestPoint()).connected(self.batt.gnd)
# POWER
with self.implicit_connect(
ImplicitConnect(self.gnd, [Common]),
) as imp:
(self.reg_3v3, self.tp_3v3), _ = self.chain(
self.vbatt,
imp.Block(VoltageRegulator(output_voltage=3.3 * Volt(tol=0.05))),
self.Block(VoltageTestPoint()),
)
self.v3v3 = self.connect(self.reg_3v3.pwr_out)
(self.reg_14v, self.tp_14v), _ = self.chain(
self.vbatt, imp.Block(VoltageRegulator(output_voltage=(13, 16) * Volt)), self.Block(VoltageTestPoint())
)
self.v14 = self.connect(self.reg_14v.pwr_out)
(self.reg_2v5,), _ = self.chain(
self.vbatt, imp.Block(VoltageRegulator(output_voltage=2.5 * Volt(tol=0.05)))
)
self.v2v5 = self.connect(self.reg_2v5.pwr_out)
(self.reg_1v2,), _ = self.chain(
self.vbatt, imp.Block(VoltageRegulator(output_voltage=1.2 * Volt(tol=0.05)))
)
self.v1v2 = self.connect(self.reg_1v2.pwr_out)
# 3V3 DOMAIN
with self.implicit_connect(
ImplicitConnect(self.v3v3, [Power]),
ImplicitConnect(self.gnd, [Common]),
) as imp:
self.mcu = imp.Block(IoController())
self.mcu_servo = imp.Block(IoController())
self.connect(self.mcu.gpio.request("srv_rst"), self.mcu_servo.with_mixin(Resettable()).reset)
self.mcu_test = imp.Block(IoController()) # test revised subcircuit only
self.i2c = self.mcu.i2c.request("i2c")
(self.i2c_pull, self.i2c_tp), self.i2c_chain = self.chain(
self.i2c, imp.Block(I2cPullup()), imp.Block(I2cTestPoint())
)
self.connect(
self.i2c,
self.imu.i2c,
self.mcu_servo.with_mixin(IoControllerI2cTarget()).i2c_target.request("i2c"),
self.mcu_test.with_mixin(IoControllerI2cTarget()).i2c_target.request("i2c"),
)
self.connect(self.v3v3, self.imu.pwr)
self.connect(self.gnd, self.imu.gnd)
(self.led,), _ = self.chain(self.mcu.gpio.request("led"), imp.Block(IndicatorLed(Led.Yellow)))
(self.servo_led,), _ = self.chain(self.mcu_servo.gpio.request("led"), imp.Block(IndicatorLed(Led.Yellow)))
(self.test_led,), _ = self.chain(
self.mcu_test.gpio.request_vector("led"), imp.Block(IndicatorLedArray(4, Led.Yellow))
)
# OLED MULTI DOMAIN
with self.implicit_connect(
ImplicitConnect(self.gnd, [Common]),
) as imp:
self.oled = imp.Block(Er_Oled_096_1c())
self.connect(self.oled.vcc, self.v14)
self.connect(self.oled.pwr, self.v3v3)
self.connect(self.i2c, self.oled.i2c)
self.connect(self.mcu.gpio.request("oled_reset"), self.oled.reset)
# CAMERA MULTI DOMAIN
with self.implicit_connect(
ImplicitConnect(self.gnd, [Common]),
) as imp:
self.cam = imp.Block(Ov2640_Fpc24())
self.connect(self.cam.pwr, self.v3v3)
self.connect(self.cam.pwr_analog, self.v2v5)
self.connect(self.cam.pwr_digital, self.v1v2)
self.connect(self.mcu.with_mixin(IoControllerDvp8()).dvp8.request("cam"), self.cam.dvp8)
self.connect(self.cam.sio, self.i2c)
# VBATT DOMAIN
with self.implicit_connect(
ImplicitConnect(self.vbatt, [Power]),
ImplicitConnect(self.gnd, [Common]),
) as imp:
for i, servo in self.servos.items():
self.connect(self.vbatt, servo.pwr)
self.connect(self.gnd, servo.gnd)
if int(i) < 4: # 0-3 connected to ESP directly
self.connect(self.mcu.gpio.request(f"servo{i}"), servo.pwm)
self.connect(self.mcu.adc.request(f"servo{i}_fb"), servo.fb)
else: # rest connected to STM as IO expander
self.connect(self.mcu_servo.gpio.request(f"servo{i}"), servo.pwm)
self.connect(self.mcu_servo.adc.request(f"servo{i}_fb"), servo.fb)
for i, servo in self.servos_cam.items():
self.connect(self.vbatt, servo.pwr)
self.connect(self.gnd, servo.gnd)
self.connect(self.mcu_servo.gpio.request(f"servo_cam{i}"), servo.pwm)
self.connect(self.mcu_servo.adc.request(f"servo_cam{i}_fb"), servo.fb)
(self.rgbs,), _ = self.chain(self.mcu.gpio.request("rgb"), imp.Block(NeopixelArray(10)))
@override
def refinements(self) -> Refinements:
return super().refinements() + Refinements(
instance_refinements=[
(["mcu"], Esp32s3_Wroom_1),
(["mcu_servo"], Stm32f103_48),
(["mcu_test"], Rp2040),
(["reg_3v3"], Ap7215),
(["reg_2v5"], Xc6206p),
(["reg_1v2"], Xc6206p),
(["reg_14v"], Tps61040),
(["batt", "conn"], JstPhKVertical),
(["mcu_servo", "swd", "conn"], TagConnectNonLegged),
(["mcu_test", "swd", "conn"], TagConnectNonLegged),
],
instance_values=[
(["refdes_prefix"], "R"), # unique refdes for panelization
(
["mcu", "pin_assigns"],
[
"servo0=34",
"servo0_fb=38",
"servo1=35",
"servo1_fb=39",
"servo2=4",
"servo2_fb=5",
"servo3=6",
"servo3_fb=7",
"i2c.scl=10",
"i2c.sda=9",
"rgb=32",
"led=33",
"cam.y2=25",
"cam.y1=24",
"cam.y3=23",
"cam.y0=22",
"cam.y4=21",
"cam.pclk=20",
"cam.y5=19",
"cam.y6=18",
"cam.xclk=17",
"cam.y7=15",
"cam.href=14",
"cam.vsync=13",
"oled_reset=8",
],
),
(["mcu_servo", "swd_connect_swo"], True),
(
["mcu_servo", "pin_assigns"],
[
"servo4=41",
"servo4_fb=10",
"servo5=43",
"servo5_fb=11",
"servo6=45",
"servo6_fb=12",
"servo_cam0=46",
"servo_cam0_fb=13",
"servo7=26",
"servo7_fb=14",
"servo8=32",
"servo8_fb=19",
"servo9=31",
"servo9_fb=18",
"servo10=30",
"servo10_fb=17",
"servo_cam1=29",
"servo_cam1_fb=16",
"servo11=28",
"servo11_fb=15",
"led=33",
"i2c.scl=21",
"i2c.sda=22",
"swd_swo=PB6", # USART1_TX
],
),
(["mcu_test", "swd_connect_swo"], True),
(
["mcu_test", "pin_assigns"],
[
"led_0=4",
"led_1=12",
"led_2=14",
"led_3=16",
"i2c.scl=37",
"i2c.sda=36",
"swd_swo=GPIO16", # UART0 TX
],
),
(["mcu", "programming"], "uart-auto"),
(["reg_14v", "inductor", "part"], "CBC3225T220KR"),
(["reg_14v", "inductor", "manual_frequency_rating"], Range(0, 17e6)), # 17MHz self-resonant
(["reg_14v", "out_cap", "cap", "voltage_margin"], 1.1),
],
class_refinements=[
(EspProgrammingHeader, EspProgrammingTc2030),
(SwdCortexTargetHeader, SwdCortexTargetTagConnect),
(Neopixel, Sk6812_Side_A),
(TestPoint, CompactKeystone5015),
],
class_values=[
(CompactKeystone5015, ["lcsc_part"], "C5199798"), # RH-5015, which is actually in stock
# the camera recommended specs are excessively tight, so loosen them a bit
(Ov2640_Fpc24, ["device", "avdd", "voltage_limits"], Range(2.3, 3.0)), # allow 2v5
(Er_Oled_096_1c, ["device", "vcc", "voltage_limits"], Range(8, 19)), # abs maximum ratings
(ServoFeedbackConnector, ["pwr", "current_draw"], Range(0.005, 0.005)), # ignore non-static draw
(Nonstrict3v3Compatible, ["nonstrict_3v3_compatible"], True),
],
)
class RobotCrawlerTestCase(unittest.TestCase):
def test_design(self) -> None:
run_test_board(RobotCrawler)