Skip to content

Commit

Permalink
Merge branch 'release/v0.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
boobooboo2 committed Jan 7, 2025
2 parents 0729b7f + a3cb761 commit c505e84
Show file tree
Hide file tree
Showing 25 changed files with 155 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install Python
uses: actions/setup-python@v2
with:
python-version: '3.7'
python-version: '3.8'
architecture: 'x64'

- name: install-dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit_test_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit_test_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit_test_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include README.md
include about.py

include requirements.txt
include requirements-dev.txt

recursive-include modi_plus/assets *
recursive-include modi_plus/task/ble_task *
Expand Down
2 changes: 1 addition & 1 deletion examples/basic_usage_examples/display_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
pos = (20, 30)

for i in range(500):
display.write_variable(0, pos[0], pos[1])
display.write_variable_xy(pos[0], pos[1], 0)
pos = (pos[0] + vel[0], pos[1] + vel[1])
if pos[0] < 0 or pos[0] > 40:
vel = (-vel[0], vel[1])
Expand Down
2 changes: 1 addition & 1 deletion examples/basic_usage_examples/env_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

while True:
print(f"humidity(%): {env.humidity:<10} temperature(°C): {env.temperature:<10} "
f"intensity(%): {env.intensity:<10} Volume(%): {env.volume:<10}", end="\r")
f"illuminance(%): {env.illuminance:<10} Volume(%): {env.volume:<10}", end="\r")
time.sleep(0.02)
6 changes: 3 additions & 3 deletions examples/basic_usage_examples/imu_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
imu = bundle.imus[0]

while True:
print(f"Pitch: {imu.pitch:<10}"
f"Roll: {imu.roll:<10}"
f"Yaw: {imu.yaw:<10}"
print(f"Angle_y: {imu.angle_y:<10}"
f"Angle_x: {imu.angle_x:<10}"
f"Angle_z: {imu.angle_z:<10}"
f"Vel x: {imu.angular_vel_x:<10}"
f"Vel y: {imu.angular_vel_y:<10}"
f"Vel z: {imu.angular_vel_z:<10}"
Expand Down
4 changes: 2 additions & 2 deletions examples/creation_examples/brush.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def setup(self):

def update(self):
h, w = self.height // 2, self.width // 2
self.cursor.y = h - h * sin(radians(-self.imu.roll))
self.cursor.x = w - w * sin(radians(-self.imu.pitch))
self.cursor.y = h - h * sin(radians(-self.imu.angle_x))
self.cursor.x = w - w * sin(radians(-self.imu.angle_y))
if self.button.pressed:
self.add_object(Brush((self.cursor.x, self.cursor.y), "x"))

Expand Down
6 changes: 3 additions & 3 deletions examples/creation_examples/dodge.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def setup(self):
self.fire.x, self.fire.y = 25, 20

def update(self):
pitch = -self.imu.pitch
if pitch < -5 and self.player.x < 48:
angle_y = -self.imu.angle_y
if angle_y < -5 and self.player.x < 48:
self.player.x += 30 * self.delta_time
elif pitch > 5 and self.player.x > 0:
elif angle_y > 5 and self.player.x > 0:
self.player.x -= 30 * self.delta_time
self.fire.y -= 15 * self.delta_time
if self.fire.y < 0:
Expand Down
2 changes: 1 addition & 1 deletion modi_plus/about.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__title__ = "pymodi-plus"
__version__ = "0.3.0"
__version__ = "0.3.1"
__author__ = "LUXROBO"
__email__ = "[email protected]"
__description__ = "Python API for controlling modular electronics, MODI+."
Expand Down
10 changes: 5 additions & 5 deletions modi_plus/module/input_module/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ class Env(InputModule):

PROPERTY_ENV_STATE = 2

PROPERTY_OFFSET_INTENSICY = 0
PROPERTY_OFFSET_ILLUMINANCE = 0
PROPERTY_OFFSET_TEMPERATURE = 2
PROPERTY_OFFSET_HUMIDITY = 4
PROPERTY_OFFSET_VOLUME = 6

@property
def intensity(self) -> int:
"""Returns the value of intensity between 0 and 100
def illuminance(self) -> int:
"""Returns the value of illuminance between 0 and 100
:return: The environment's intensity.
:return: The environment's illuminance.
:rtype: int
"""

offset = Env.PROPERTY_OFFSET_INTENSICY
offset = Env.PROPERTY_OFFSET_ILLUMINANCE
raw = self._get_property(Env.PROPERTY_ENV_STATE)
data = struct.unpack("h", raw[offset:offset + 2])[0]
return data
Expand Down
26 changes: 13 additions & 13 deletions modi_plus/module/input_module/imu.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class Imu(InputModule):
PROPERTY_OFFSET_VIBRATION = 0

@property
def roll(self) -> float:
"""Returns the roll angle of the imu
def angle_x(self) -> float:
"""Returns the angle_x angle of the imu
:return: The imu's roll angle.
:return: The imu's angle_x angle.
:rtype: float
"""

Expand All @@ -37,10 +37,10 @@ def roll(self) -> float:
return data

@property
def pitch(self) -> float:
"""Returns the pitch angle of the imu
def angle_y(self) -> float:
"""Returns the angle_y angle of the imu
:return: The imu's pitch angle.
:return: The imu's angle_y angle.
:rtype: float
"""

Expand All @@ -50,10 +50,10 @@ def pitch(self) -> float:
return data

@property
def yaw(self) -> float:
"""Returns the yaw angle of the imu
def angle_z(self) -> float:
"""Returns the angle_zle_z angle of the imu
:return: The imu's yaw angle.
:return: The imu's angle_z angle.
:rtype: float
"""

Expand All @@ -64,17 +64,17 @@ def yaw(self) -> float:

@property
def angle(self) -> Tuple[float, float, float]:
"""Returns the roll, pitch and yaw angle of the imu
"""Returns the angle_x, angle_y and angle_z angle of the imu
:return: The imu's angles of roll, pitch and yaw.
:return: The imu's angles of angle_x, angle_y and angle_z.
:rtype: tuple
"""

return self.roll, self.pitch, self.yaw
return self.angle_x, self.angle_y, self.angle_z

@property
def angular_vel_x(self) -> float:
"""Returns the roll angle of the imu
"""Returns the angle_x angle of the imu
:return: The imu's angular velocity the about x-axis.
:rtype: float
Expand Down
56 changes: 31 additions & 25 deletions modi_plus/module/output_module/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def write_text(self, text: str) -> None:
self._text = text
time.sleep(0.02 + 0.003 * len(encoding_data))

def write_variable(self, x: int, y: int, variable: float) -> None:
def write_variable_xy(self, x: int, y: int, variable: float) -> None:
"""Show the input variable on the display.
:param x: X coordinate of the desired position
Expand All @@ -227,7 +227,6 @@ def write_variable(self, x: int, y: int, variable: float) -> None:
:type variable: float
:return: None
"""

self._set_property(
self._id,
Display.PROPERTY_DISPLAY_WRITE_VARIABLE,
Expand All @@ -238,7 +237,26 @@ def write_variable(self, x: int, y: int, variable: float) -> None:
self._text += str(variable)
time.sleep(0.01)

def draw_picture(self, x: int, y: int, name: int) -> None:
def write_variable_line(self, line: int, variable: float) -> None:
"""Show the input variable on the display.
:param line: display line number of the desired position
:type line: int
:param variable: Variable to display.
:type variable: float
:return: None
"""
self._set_property(
self._id,
Display.PROPERTY_DISPLAY_WRITE_VARIABLE,
property_values=(("u8", 0),
("u8", line * 20),
("float", variable), )
)
self._text += str(variable)
time.sleep(0.01)

def draw_picture(self, name: int) -> None:
"""Clears the display and show the input picture on the display.
:param x: X coordinate of the desired position
Expand All @@ -257,8 +275,8 @@ def draw_picture(self, x: int, y: int, name: int) -> None:
self._set_property(
self._id,
Display.PROPERTY_DISPLAY_DRAW_PICTURE,
property_values=(("u8", x),
("u8", y),
property_values=(("u8", 0),
("u8", 0),
("u8", Display.WIDTH),
("u8", Display.HEIGHT),
("string", file_name), )
Expand Down Expand Up @@ -308,34 +326,22 @@ def set_offset(self, x: int, y: int) -> None:
)
time.sleep(0.01)

def move_screen(self, x: int, y: int) -> None:
"""Move the screen by x and y
:param x: X-axis movement value
:type x: int
:param y: Y-axis movement value
:type y: int
:return: None
"""

self._set_property(
self.id,
Display.PROPERTY_DISPLAY_MOVE_SCREEN,
property_values=(("s8", x), ("s8", y), ),
force=True
)
time.sleep(0.01)

def reset(self) -> None:
def reset(self, mode=0) -> None:
"""Clear the screen.
:param mode: Erase mode
- mode 0 : Erase inside buffer(it looks like nothing has changed)
- mode 1 : Erase display
:return: None
"""

if mode > 1:
mode = 0

self._set_property(
self._id,
Display.PROPERTY_DISPLAY_RESET,
property_values=(("u8", 0), )
property_values=(("u8", mode), )
)
self._text = ""
time.sleep(0.01)
10 changes: 9 additions & 1 deletion modi_plus/module/output_module/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,19 @@ def set_angle(self, target_angle: int, target_speed: int = 70) -> None:
:return: None
"""

invalid_angle = (target_angle < 0 or target_angle > 360)
invalid_speed = (target_speed < 0 or target_speed > 100)

if invalid_angle or invalid_speed:
return

self._set_property(
destination_id=self._id,
property_num=Motor.PROPERTY_MOTOR_ANGLE,
property_values=(("u16", target_angle),
("u16", target_speed), )
("u16", target_speed),
("u16", 0),
("u16", 0), )
)
time.sleep(0.01)

Expand Down
16 changes: 12 additions & 4 deletions modi_plus/task/exe_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,14 @@ def __update_health(self, message):
module.last_updated_time = curr_time
module.is_connected = True

if module.module_type == "network" and message["l"] == 5:
_, dir = unpack_data(message["b"], (4, 1))
if dir == 1:
if module.module_type == "network" and message["l"] == 6:
_, dir = unpack_data(message["b"], (5, 1))

# usb로 연결된 네트워크 모듈인 경우 interpreter 삭제
if dir & 2 and module.is_usb_connected is False:
self.__request_erase_interpreter()
self.__request_reboot(BROADCAST_ID)
time.sleep(1)
module.is_usb_connected = True

# 일반 모듈의 OS 버전이 1.3.1 이상일 경우, health data에 pnp on/off 상태가 포함되어 있다.
Expand All @@ -101,7 +106,7 @@ def __update_health(self, message):

# Disconnect module with no health message for more than 2 second
for module in self._modules:
if curr_time - module.last_updated_time > 2:
if (curr_time - module.last_updated_time > 2) and (module.is_connected is True):
module.is_connected = False
module._last_set_message = None

Expand Down Expand Up @@ -206,3 +211,6 @@ def __request_find_network_id(self, id=BROADCAST_ID):

def __request_esp_version(self, id):
self._connection.send_nowait(parse_message(0xA0, 25, id, (0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF)))

def __request_erase_interpreter(self):
self._connection.send_nowait(parse_message(160, 80, 4095, (0, 0, 0, 0, 0, 0, 0, 0)))
4 changes: 2 additions & 2 deletions modi_plus/util/inspection_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ def inspect_battery(self, module, i, nb_modules):
def inspect_env(self, module, i, nb_modules):
self.print_wrap(
"""
Environment module has intensity, temperature, humidity and volume as its property.
Environment module has illuminance, temperature, humidity and volume as its property.
"""
)
input("\nIf you are ready to inspect this module, Press ENTER: ")
self.clear()

properties = ["intensity", "temperature", "humidity", "volume"]
properties = ["illuminance", "temperature", "humidity", "volume"]

for prop in properties:
self.print_module_page(module, i, nb_modules)
Expand Down
8 changes: 4 additions & 4 deletions modi_plus/util/usage_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def run_env_manual(self):
env = bundle.envs[0]
while True:
print(f"Env ({env.id}) intensity: {env.intensity}")
print(f"Env ({env.id}) illuminance: {env.illuminance}")
print(f"Env ({env.id}) temperature: {env.temperature}")
print(f"Env ({env.id}) humidity: {env.humidity}")
print(f"Env ({env.id}) volume: {env.volume}")
Expand All @@ -154,9 +154,9 @@ def run_imu_manual(self):
imu = bundle.imus[0]
while True:
print(f"Gyro ({imu.id}) roll: {imu.roll}")
print(f"Gyro ({imu.id}) pitch: {imu.pitch}")
print(f"Gyro ({imu.id}) yaw: {imu.yaw}")
print(f"Gyro ({imu.id}) angle_x: {imu.angle_x}")
print(f"Gyro ({imu.id}) angle_y: {imu.angle_y}")
print(f"Gyro ({imu.id}) angle_z: {imu.angle_z}")
print(f"Gyro ({imu.id}) angular_vel_x: {imu.angular_vel_x}")
print(f"Gyro ({imu.id}) angular_vel_y: {imu.angular_vel_y}")
print(f"Gyro ({imu.id}) angular_vel_z: {imu.angular_vel_z}")
Expand Down
Loading

0 comments on commit c505e84

Please sign in to comment.