Skip to content

Commit f12a2c8

Browse files
committed
refactor<correct import names for common folder
1 parent 1f826e3 commit f12a2c8

File tree

45 files changed

+2073
-76
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2073
-76
lines changed

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"cSpell.words": [
3+
"BYODR",
34
"GPIO",
5+
"Jetson",
46
"teleop"
57
],
68
"python.analysis.typeCheckingMode": "off",

BYODR_utils/JETSON_specific/gpio_relay.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import threading
44

5-
import Jetson.GPIO as GPIO
5+
import Jetson.GPIO as GPIO # type: ignore
66

77

8-
class ThreadSafeGpioRelay(object):
8+
class ThreadSafeJetsonGpioRelay(object):
99
"""
1010
Thread-safe class for managing a GPIO relay on a Jetson Nano.
1111
"""

jetson_runtime/pilot/pilot/tests.py renamed to archived/PIL/tests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
from app import CommandProcessor
1010
from app import PilotApplication
11-
from byodr.utils import timestamp
12-
from byodr.utils.navigate import ReloadableDataSource, FileSystemRouteDataSource
13-
from byodr.utils.testing import CollectPublisher, QueueReceiver, CollectServer
11+
from BYODR_utils.common import timestamp
12+
from BYODR_utils.common.navigate import ReloadableDataSource, FileSystemRouteDataSource
13+
from BYODR_utils.common.testing import CollectPublisher, QueueReceiver, CollectServer
1414

1515

1616
def test_create_and_setup(tmpdir):

jetson_runtime/pilot/pilot/tests_relay.py renamed to archived/PIL/tests_relay.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
from six.moves import range
99
from six.moves.configparser import SafeConfigParser
1010

11-
from byodr.utils import timestamp
12-
from byodr.utils.testing import QueueReceiver, CollectServer, CollectJSONClient
13-
from byodr.utils.usbrelay import SearchUsbRelayFactory
11+
from BYODR_utils.common import timestamp
12+
from BYODR_utils.common.testing import QueueReceiver, CollectServer, CollectJSONClient
13+
from BYODR_utils.common.usbrelay import SearchUsbRelayFactory
1414
from relay import MonitorApplication
1515

1616

archived/exr/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
from can import CanError
1919
from pyueye import ueye
2020

21-
from byodr.utils import timestamp
22-
from byodr.utils.ipc import ReceiverThread, JSONPublisher, ImagePublisher
21+
from BYODR_utils.common import timestamp
22+
from BYODR_utils.common.ipc import ReceiverThread, JSONPublisher, ImagePublisher
2323
from camera import Camera, FrameThread
2424

2525
logger = logging.getLogger(__name__)

archived/odometry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
from gpiozero import DigitalInputDevice
77

8-
from byodr.utils import timestamp
9-
from byodr.utils.ipc import JSONPublisher
8+
from BYODR_utils.common import timestamp
9+
from BYODR_utils.common.ipc import JSONPublisher
1010

1111
logger = logging.getLogger(__name__)
1212
log_format = "%(levelname)s: %(filename)s %(funcName)s %(message)s"

archived/tests_rover.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from ConfigParser import SafeConfigParser
44

55
from app import RoverApplication
6-
from byodr.utils.testing import CollectPublisher, QueueReceiver, CollectServer
6+
from BYODR_utils.common.testing import CollectPublisher, QueueReceiver, CollectServer
77

88

99
def test_rover_create_and_setup(tmpdir):
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from __future__ import absolute_import
2+
3+
import threading
4+
5+
import Jetson.GPIO as GPIO # type: ignore
6+
7+
8+
class ThreadSafeJetsonGpioRelay(object):
9+
"""
10+
Thread-safe class for managing a GPIO relay on a Jetson Nano.
11+
"""
12+
13+
def __init__(self, pin=15):
14+
self.pin = pin
15+
self.state = False # False for OFF, True for ON
16+
self.lock = threading.Lock()
17+
GPIO.setmode(GPIO.BOARD) # Set the pin numbering system to BOARD
18+
GPIO.setup(self.pin, GPIO.OUT, initial=GPIO.LOW)
19+
20+
def open(self):
21+
"""Turns the relay ON (sets the GPIO pin LOW)."""
22+
with self.lock:
23+
GPIO.output(self.pin, GPIO.LOW)
24+
self.state = False
25+
26+
def close(self):
27+
"""Turns the relay OFF (sets the GPIO pin HIGH)."""
28+
with self.lock:
29+
GPIO.output(self.pin, GPIO.HIGH)
30+
self.state = True
31+
32+
def toggle(self):
33+
"""Toggles the relay state."""
34+
with self.lock:
35+
self.state = not self.state
36+
GPIO.output(self.pin, GPIO.LOW if self.state else GPIO.HIGH)
37+
38+
def states(self):
39+
"""Returns the current state of the relay."""
40+
with self.lock:
41+
return self.state
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import subprocess
2+
3+
4+
class Nano:
5+
@staticmethod
6+
def get_ip_address():
7+
try:
8+
ip_addresses = (
9+
subprocess.check_output(
10+
"hostname -I | awk '{for (i=1; i<=NF; i++) if ($i ~ /^192\\.168\\./) print $i}'",
11+
shell=True,
12+
)
13+
.decode()
14+
.strip()
15+
)
16+
# Split in case there are multiple local IP addresses
17+
return ip_addresses
18+
except subprocess.CalledProcessError as e:
19+
print(f"An error occurred: {e}")
20+
return None
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from __future__ import absolute_import
2+
3+
import threading
4+
5+
import RPi.GPIO as GPIO # type: ignore
6+
7+
8+
class ThreadSafePi4GpioRelay:
9+
"""Thread-safe class for managing a GPIO relay on a Raspberry Pi."""
10+
11+
def __init__(self, pin=15):
12+
self.pin = pin
13+
self.state = False # False for OFF, True for ON
14+
self.lock = threading.Lock()
15+
GPIO.setmode(GPIO.BOARD) # Set the pin numbering system to BOARD
16+
GPIO.setwarnings(False)
17+
GPIO.setup(self.pin, GPIO.OUT, initial=GPIO.LOW)
18+
19+
def open(self):
20+
"""Turns the relay ON (sets the GPIO pin LOW)."""
21+
with self.lock:
22+
print("opened the relay")
23+
GPIO.output(self.pin, GPIO.LOW)
24+
self.state = False
25+
26+
def close(self):
27+
"""Turns the relay OFF (sets the GPIO pin HIGH)."""
28+
with self.lock:
29+
GPIO.output(self.pin, GPIO.HIGH)
30+
current_state = GPIO.input(self.pin)
31+
print(f"closed the relay, current state: {current_state}")
32+
self.state = True
33+
34+
def toggle(self):
35+
"""Toggles the relay state."""
36+
with self.lock:
37+
self.state = not self.state
38+
GPIO.output(self.pin, GPIO.LOW if self.state else GPIO.HIGH)
39+
40+
def get_state(self):
41+
"""Returns the current state of the relay."""
42+
with self.lock:
43+
return self.state
44+
45+
def cleanup(self):
46+
"""Cleans up the GPIO state."""
47+
GPIO.cleanup(self.pin) # Reset the specific pin before setup
48+
GPIO.setup(self.pin, GPIO.OUT, initial=GPIO.LOW)

0 commit comments

Comments
 (0)