Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pylint / black tests for pull requests #17

Merged
merged 13 commits into from
Dec 2, 2023
33 changes: 33 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Run tests

on:
pull_request:
branches:
- main

jobs:
run_tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint==3.0.2 black==23.11.0

- name: Checking formatting with black
run: |
black --check .

- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
42 changes: 20 additions & 22 deletions actuators/DCMotor.py → actuators/dcmotor.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
from machine import Pin
from leaphymicropython.utils.boards_config import pin_to_gpio


class DCMotor:
"""DC Motor class"""
in_1: Pin
in_2: Pin
en_a: Pin
in_3: Pin
in_4: Pin
en_b: Pin

def __init__(self, in_1: int, in_2: int, in_3: int, in_4: int, en_a: int, en_b: int):
def __init__(
self, in_1: int, in_2: int, in_3: int, in_4: int, en_a: int, en_b: int
):
"""
Creates a DC motor
:param in_1: int, the pin of the in1
Expand All @@ -26,14 +23,16 @@ def __init__(self, in_1: int, in_2: int, in_3: int, in_4: int, en_a: int, en_b:
in_3 = pin_to_gpio(in_3)
in_4 = pin_to_gpio(in_4)
en_b = pin_to_gpio(en_b)
self.In1 = Pin(in_1,Pin.OUT)
self.In2 = Pin(in_2,Pin.OUT)
self.EN_A = Pin(en_a,Pin.OUT)
self.In3 = Pin(in_3,Pin.OUT)
self.In4 = Pin(in_4,Pin.OUT)
self.EN_B = Pin(en_b,Pin.OUT)

def set_pins(self, in_1: int, in_2: int, in_3: int, in_4: int, en_a: int, en_b: int):
self.in_1 = Pin(in_1, Pin.OUT)
self.in_2 = Pin(in_2, Pin.OUT)
self.en_a = Pin(en_a, Pin.OUT)
self.in_3 = Pin(in_3, Pin.OUT)
self.in_4 = Pin(in_4, Pin.OUT)
self.en_b = Pin(en_b, Pin.OUT)

def set_pins(
self, in_1: int, in_2: int, in_3: int, in_4: int, en_a: int, en_b: int
):
"""
Sets the pins of the DC motor
:param in_1: int, the pin of the in1
Expand All @@ -43,12 +42,12 @@ def set_pins(self, in_1: int, in_2: int, in_3: int, in_4: int, en_a: int, en_b:
:param en_a: int, the pin of the enable pin a
:param en_b: int, the pin of the enable pin b
"""
self.In1 = Pin(in_1, Pin.OUT)
self.In2 = Pin(in_2, Pin.OUT)
self.EN_A = Pin(en_a, Pin.OUT)
self.In3 = Pin(in_3, Pin.OUT)
self.In4 = Pin(in_4, Pin.OUT)
self.EN_B = Pin(en_b, Pin.OUT)
self.in_1 = Pin(in_1, Pin.OUT)
self.in_2 = Pin(in_2, Pin.OUT)
self.en_a = Pin(en_a, Pin.OUT)
self.in_3 = Pin(in_3, Pin.OUT)
self.in_4 = Pin(in_4, Pin.OUT)
self.en_b = Pin(en_b, Pin.OUT)

def move_forward(self):
"""
Expand Down Expand Up @@ -94,4 +93,3 @@ def stop(self):
self.in_2.low()
self.in_3.low()
self.in_4.low()

4 changes: 1 addition & 3 deletions actuators/RGBLed.py → actuators/rgbled.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from machine import Pin, PWM
from leaphymicropython.utils.pins import set_pwm


Expand Down Expand Up @@ -42,7 +41,7 @@ def set_pins(self, red_pin: int, green_pin: int, blue_pin: int):

def set_color(self, r: int, g: int, b: int):
"""
Sets the color of the rgbled
Sets the color of the rgb-led
koen1711 marked this conversation as resolved.
Show resolved Hide resolved
:param r: int, the red value
:param g: int, the green value
:param b: int, the blue value
Expand All @@ -55,4 +54,3 @@ def print_base_colors(self):
"""Prints the color values of the list"""
for kleur, rgb in self.Colors.items():
print(f"{kleur}: RGB{rgb}")

12 changes: 7 additions & 5 deletions actuators/servo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from leaphymicropython.utils.boards_config import pin_to_gpio
from time import sleep

from leaphymicropython.utils.boards_config import pin_to_gpio
from machine import Pin, PWM


Expand All @@ -8,10 +9,11 @@ def servo_angle(pin: int, angle: int):
pin = pin_to_gpio(pin)
pwm = PWM(Pin(pin))
pwm.freq(50)
degrees_in_u16 = (9000-2000)/180
degrees_in_u16 = (9000 - 2000) / 180
u_16 = round(9000 - (angle * degrees_in_u16))
if not angle > -1 and not angle < 181: raise ValueError("The angle must be in between 0 and 180")
nu = pwm.duty_u16()
for pos in range(nu, u_16, 50 if nu < u_16 else -50):
if not angle > -1 and not angle < 181:
raise ValueError("The angle must be in between 0 and 180")
current_pos = pwm.duty_u16()
for pos in range(current_pos, u_16, 50 if current_pos < u_16 else -50):
pwm.duty_u16(pos)
sleep(0.01)
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
["leaphymicropython/sensors/linesensor.py", "github:leaphy-robotics/leaphy-micropython/sensors/linesensor.py"],
["leaphymicropython/sensors/dht22.py", "github:leaphy-robotics/leaphy-micropython/sensors/dht22.py"],
["leaphymicropython/actuators/buzzer.py", "github:leaphy-robotics/leaphy-micropython/actuators/buzzer.py"],
["leaphymicropython/actuators/DCMotor.py", "github:leaphy-robotics/leaphy-micropython/actuators/DCMotor.py"],
["leaphymicropython/actuators/RGBLed.py", "github:leaphy-robotics/leaphy-micropython/actuators/RGBLed.py"],
["leaphymicropython/actuators/dcmotor.py", "github:leaphy-robotics/leaphy-micropython/actuators/dcmotor.py"],
["leaphymicropython/actuators/rgbled.py", "github:leaphy-robotics/leaphy-micropython/actuators/rgbled.py"],
["leaphymicropython/actuators/servo.py", "github:leaphy-robotics/leaphy-micropython/actuators/servo.py"]
],
"deps": [],
"version": "1.0"
"version": "1.1"
}
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

[tool.pylint.format]
max-line-length = 120

[tool.pylint.MASTER]
max-line-length = 120
disable = ["missing-module-docstring", "import-error", "too-many-arguments"]
5 changes: 4 additions & 1 deletion sensors/dht22.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
import machine
from leaphymicropython.utils.boards_config import pin_to_gpio

class DHT22():

class DHT22:
"""
A class to control the dht22
"""

def __init__(self, pin: int):
"""
Sets the pins for the dht22
:param pin: sets the pin for the dht22
"""
pin = pin_to_gpio(pin)
self.sensor = dht.DHT22(machine.Pin(pin))

def read_temperature(self) -> float:
"""
:return: temperature: gives the temperature in Celsius
Expand Down
16 changes: 10 additions & 6 deletions sensors/sonar.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import utime
from leaphymicropython.utils.boards_config import pin_to_gpio
from machine import Pin
import utime


def read_distance(trigPin: int, echoPin: int):
"""Reads distance from object"""
trigger_pin = pin_to_gpio(trigPin)
echo_pin = pin_to_gpio(echoPin)
def read_distance(trig_pin: int, echo_pin: int) -> float:
"""Reads distance from object
:param trig_pin: Trigger pin
:param echo_pin: Echo pin
:return: The distance
"""
trigger_pin = pin_to_gpio(trig_pin)
echo_pin = pin_to_gpio(echo_pin)
trigger = Pin(trigger_pin, Pin.OUT)
echo = Pin(echo_pin, Pin.IN)
trigger.low()
Expand All @@ -21,4 +25,4 @@ def read_distance(trigPin: int, echoPin: int):
while echo.value() == 1:
signal_on = utime.ticks_us()
time_passed = signal_on - signal_off
return (time_passed * 0.0343) / 2
return (time_passed * 0.0343) / 2
38 changes: 20 additions & 18 deletions utils/boards_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


"""
PINS:
PINS:
Key = Physical Pin
Value = GPIO Pin
"""
Expand All @@ -36,13 +36,13 @@
17: 29,
18: 12,
19: 13,
20: 14, # A6
21: 15, # A7
20: 14, # A6
21: 15, # A7
}
}

"""
PINS:
PINS:
Key = Physical Pin
Value = GPIO Pin
"""
Expand Down Expand Up @@ -86,8 +86,7 @@
37: EN,
38: GND,
39: VSYS,
40: VBUS

40: VBUS,
}
}

Expand All @@ -96,24 +95,27 @@
"PICO_W": PICO_W,
}

id_u: str = unique_id()

decoded_id: str = ''.join(['{:02X}'.format(byte) for byte in id_u])
board = "UNKNOWN_BOARD"

if str(decoded_id).startswith("E6611C"):
board = "RP_NANO_MAKER"
elif str(decoded_id).startswith("E66164"):
board = "PICO_W"


def get_board_type():
"""
Get board type,
"""
Get board type,
:return: which board it is
"""
id_u: bytes = unique_id()
decoded_id: str = "".join([f"{byte:02X}" for byte in id_u])
board = "UNKNOWN_BOARD"

if str(decoded_id).startswith("E6611C"):
board = "RP_NANO_MAKER"
elif str(decoded_id).startswith("E66164"):
board = "PICO_W"
return board


def pin_to_gpio(pin: int):
"""
Convert physical pin to GPIO
:param pin: The pin to convert
:return: GPIO pin number
"""
return BOARDS[get_board_type()]["pins"][pin]
6 changes: 3 additions & 3 deletions utils/pins.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from machine import Pin,PWM
from machine import Pin, PWM
from leaphymicropython.utils.boards_config import pin_to_gpio


def set_pwm(pin: int, value: int, freq: int = 50):
""" Sets a pwm pin
"""Sets a pwm pin
:param pin: int, the pin to set
:param value: int, the value to set the pin to
:param freq: int, the frequency of the pwm
Expand Down Expand Up @@ -48,4 +48,4 @@ def read_pin(pin: int) -> int:
"""
pin = pin_to_gpio(pin)
pin = Pin(pin, Pin.IN)
pin.value()
return pin.value()
3 changes: 2 additions & 1 deletion utils/timeschedule.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from time import sleep


def sleep_minute(minutes: int):
"""
Sleep for minutes amount of time
:param minutes: the amount of minutes
"""
sleep(60 * minutes)
sleep(60 * minutes)
1 change: 1 addition & 0 deletions utils/wifi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from time import sleep
import network


def connect(ssid: str, password: str) -> str:
"""
Connects the pico to the Wi-Fi
Expand Down