-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
185 lines (134 loc) · 3.98 KB
/
main.py
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
'''
code.py
SeaHawk Vertical Profiling Float Code
Copyright (C) 2022-2023 Cabrillo Robotics Club
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Cabrillo Robotics Club
6500 Soquel Drive Aptos, CA 95003
cabrillorobotics@gmail.com
'''
# # # # # # # #
# CONSTANTS
# # # # # # # #
# team number as defined by MATE
TEAM_NUM = "PN03"
# LoRa Device ID for the Float Transceiver
FLOAT_LORA_ID = 18
# LoRa Device ID for the Deck Transceiver
DECK_LORA_ID = 28
# number of seconds to wait on the surface transmitting before diving again
TRANSMIT_DURATION = 30
# number of seconds it takes for the pump to fill the tank
BILGE_FILL_DURATION = 15
# number of seconds it takes for the float to sink to the bottom
DIVE_DURATION = 45
# number of seconds it takes for the pump to empty the tank
BILGE_EMPTY_DURATION = 15
# number of seconds it takes for the float to rise to the surface
SURFACE_DURATION = 15
# # # # # # # #
# IMPORTS
# # # # # # # #
import time
import board
import busio
import digitalio
from adafruit_motorkit import MotorKit
# lora radio library
import adafruit_rfm9x
# neopixel
import neopixel
# # # # # # # # #
# BUS SETUP
# # # # # # # # #
# instantiate the spi interface
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
# LoRa Module Chip Select on Digital Pin 5
CS = digitalio.DigitalInOut(board.D5)
# LoRa Module Reset on Digital Pin 6
RESET = digitalio.DigitalInOut(board.D6)
# set the radio frequency to 915mhz (NOT 868)
RADIO_FREQ_MHZ = 915.0
# # # # # # # #
# neopixel setup
# # # # # # # #
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1)
pixel.brightness = 1
# # # # # # # #
# LoRa Radio Wing SETUP
# # # # # # # #
# instantiate the lora radio in 915mhz mode
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ)
# set my lora node ID
# I am the float
rfm9x.node = FLOAT_LORA_ID
# set the destination lora node ID
# destination is deck
rfm9x.destination = DECK_LORA_ID
# # # # # # # #
# MotorKit SETUP
# # # # # # # #
# Set up the motor kit
kit = MotorKit()
# stop motors on init
# incase a power cycle happens while motors are running
kit.motor1.throttle = 0.0
kit.motor2.throttle = 0.0
# # # # # # # #
# Functions
# # # # # # # #
# transmit the time in seconds
def transmit():
# set the neopixel yellow
pixel.fill((255, 255, 0))
rfm9x.send(bytes(TEAM_NUM + " " + str(int(time.monotonic())), "utf-8"))
time.sleep(.5)
# fill the ballast with water to make the float dive
def dive():
# set the neopixel blue
pixel.fill((0, 0, 255))
# motor1 is the motor that fills the reservoir with water
kit.motor1.throttle = 1.0
time.sleep(BILGE_FILL_DURATION)
kit.motor1.throttle = 0.0
# empty the ballast to make the float surface
def surface():
# set the neopixel green
pixel.fill((0, 255, 0))
# motor2 is the motor that empties the reservoir
kit.motor2.throttle = 1.0
time.sleep(BILGE_EMPTY_DURATION)
kit.motor2.throttle = 0.0
# set led white
# hardware init complete
pixel.fill((255,255,255))
# # # # # # # #
# Main Loop
# # # # # # # #
# wait for receive to start
while True:
packet = rfm9x.receive()
if packet is None:
pass
elif str(packet, "utf-8") == "CABRILLO VPF DIVE":
break
else:
pass
# profiling cycle
while True:
start_time = time.time()
while time.time() - start_time < TRANSMIT_DURATION:
transmit()
dive()
time.sleep(DIVE_DURATION)
surface()
time.sleep(SURFACE_DURATION)