-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from iq-motion-control/refactor-pulsing-module
Updated Vertiq2306 with new pulsing firmware. Added additional files …
- Loading branch information
Showing
9 changed files
with
287 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import os | ||
|
||
from iqmotion.iq_devices.iq_module import IqModule | ||
from iqmotion.communication.communicator import Communicator | ||
|
||
|
||
# There are 3 options when it comes to adding extra clients | ||
# | ||
# -Quick and dirty- | ||
# 1. clients_path {str: directory path}: | ||
# Points to a directory containing client entry jsons | ||
# Note: this option will add every client entry in the folder | ||
# | ||
# -More Work but Flexible- | ||
# 2. extra_clients {list: [dir path, dir path, ...]}: | ||
# Contains a list of paths to each cleint entry you want to include | ||
# Note: you need to pass in an absolute paths | ||
# | ||
# -Most Work but cleanest- | ||
# 3. custom_module_location {str: directory path}: | ||
# Commonly passed in as a cwd path, this can contain a module file | ||
# in addition to extra client files. | ||
# Note: You need to have a folder named extra_client_files hosting your | ||
# client files | ||
# Example of 3rd Option | ||
# { | ||
# "clients": [ | ||
# "brushless_drive", | ||
# "propeller_motor_control", | ||
# "anticogging", | ||
# "buzzer_control", | ||
# "esc_propeller_input_parser", | ||
# "hobby_input", | ||
# "persistent_memory", | ||
# "power_monitor", | ||
# "serial_interface", | ||
# "servo_input_parser", | ||
# "step_direction_input", | ||
# "system_control", | ||
# "temperature_estimator", | ||
# "temperature_monitor_uc" | ||
# ], | ||
# "extra_clients": [ | ||
# "extra_client" | ||
# ] | ||
# } | ||
|
||
|
||
class CustomIqModule(IqModule): | ||
_MODULE_FILE_NAME = "" | ||
|
||
def __init__( | ||
self, | ||
custom_module_location: str, | ||
com: Communicator, | ||
module_idn=0, | ||
clients_path: str=None, | ||
extra_clients: list=None, | ||
): | ||
module_file_path = os.path.join( | ||
os.path.dirname(custom_module_location), | ||
("module_files/" + self._MODULE_FILE_NAME), | ||
) | ||
|
||
super().__init__(com, | ||
module_idn, | ||
clients_path=clients_path, | ||
extra_clients=extra_clients, | ||
module_file_path=module_file_path) | ||
|
||
# This will pull clients from the Module JSON | ||
# --Refer to example Below-- | ||
if "extra_clients" in self._module_file_dict: | ||
for extra_client_name in self._module_file_dict["extra_clients"]: | ||
extra_client_file_path = os.path.join( | ||
os.path.dirname(custom_module_location), | ||
(f"extra_client_files/{extra_client_name}.json"), | ||
) | ||
self.add_client(extra_client_file_path) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"clients": [ | ||
"brushless_drive", | ||
"buzzer_control", | ||
"coil_temperature_estimator", | ||
"esc_propeller_input_parser", | ||
"iquart_flight_controller_interface", | ||
"persistent_memory", | ||
"power_monitor", | ||
"power_safety", | ||
"propeller_motor_control", | ||
"pulsing_rectangular_input_parser", | ||
"serial_interface", | ||
"system_control", | ||
"temperature_estimator", | ||
"temperature_monitor_uc", | ||
"voltage_superposition" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from iqmotion.communication.communicator import Communicator | ||
from iqmotion.iq_devices.custom_iq_module import CustomIqModule | ||
|
||
|
||
class PulsingModule(CustomIqModule): | ||
""" Creates PulsingModule object | ||
Arguments: | ||
com {Communicator} -- The communicator object to interface with the IqModule | ||
Keyword Arguments: | ||
module_idn {int} -- The idn of the module (default: {0}) | ||
extra_clients {list} -- list of file paths to extra clients you want to load in the module (default: {None}) | ||
""" | ||
|
||
_DEFAULT_CONTROL_CLIENT = "propeller_motor_control" | ||
_DEFAULT_VELOCITY_CLIENT_ENTRY = "ctrl_velocity" | ||
_DEFAULT_VOLTS_CLIENT_ENTRY = "ctrl_volts" | ||
|
||
_MODULE_FILE_NAME = "pulsing.json" | ||
|
||
def __init__( | ||
self, com: Communicator, module_idn=0, extra_clients=None, | ||
): | ||
super().__init__(__file__, com, module_idn, extra_clients) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"clients": [ | ||
"brushless_drive", | ||
"propeller_motor_control", | ||
"anticogging", | ||
"buzzer_control", | ||
"esc_propeller_input_parser", | ||
"hobby_input", | ||
"persistent_memory", | ||
"power_monitor", | ||
"serial_interface", | ||
"servo_input_parser", | ||
"step_direction_input", | ||
"system_control", | ||
"temperature_estimator", | ||
"temperature_monitor_uc" | ||
], | ||
"extra_clients": [ | ||
"extra_client" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"clients": [ | ||
"brushless_drive", | ||
"propeller_motor_control", | ||
"anticogging", | ||
"buzzer_control", | ||
"esc_propeller_input_parser", | ||
"hobby_input", | ||
"persistent_memory", | ||
"power_monitor", | ||
"serial_interface", | ||
"servo_input_parser", | ||
"step_direction_input", | ||
"system_control", | ||
"temperature_estimator", | ||
"temperature_monitor_uc" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import pytest | ||
import os | ||
|
||
from iqmotion.iq_devices.custom_iq_module import CustomIqModule | ||
|
||
from iqmotion.tests.helpers import MockCommunicator | ||
|
||
|
||
class NewModule(CustomIqModule): | ||
_DEFAULT_CONTROL_CLIENT = "CONTROL" | ||
_DEFAULT_VELOCITY_CLIENT_ENTRY = "VEL" | ||
_DEFAULT_VOLTS_CLIENT_ENTRY = "VOLTS" | ||
_MODULE_FILE_NAME = "new_module.json" | ||
|
||
def __init__( | ||
self, com, module_idn=0, extra_clients=None, | ||
): | ||
super().__init__(__file__, com, module_idn, extra_clients=extra_clients) | ||
|
||
class NonExtraModule(CustomIqModule): | ||
_DEFAULT_CONTROL_CLIENT = "CONTROL" | ||
_DEFAULT_VELOCITY_CLIENT_ENTRY = "VEL" | ||
_DEFAULT_VOLTS_CLIENT_ENTRY = "VOLTS" | ||
_MODULE_FILE_NAME = "non_extra_module.json" | ||
|
||
def __init__( | ||
self, com, module_idn=0, extra_clients=None, | ||
): | ||
super().__init__(__file__, com, module_idn, extra_clients=extra_clients) | ||
|
||
|
||
@pytest.fixture | ||
def mock_communicator(): | ||
mock_class = MockCommunicator() | ||
return mock_class | ||
|
||
|
||
# pylint: disable=redefined-outer-name | ||
def test_custom_iq_module(mock_communicator): | ||
expected_clients = set( | ||
[ | ||
"brushless_drive", | ||
"propeller_motor_control", | ||
"anticogging", | ||
"buzzer_control", | ||
"esc_propeller_input_parser", | ||
"hobby_input", | ||
"persistent_memory", | ||
"power_monitor", | ||
"serial_interface", | ||
"servo_input_parser", | ||
"step_direction_input", | ||
"system_control", | ||
"temperature_estimator", | ||
"temperature_monitor_uc", | ||
"extra_client", | ||
], | ||
) | ||
iq_module = NewModule(mock_communicator, 0) | ||
client_dict = set(iq_module._client_dict.keys()) | ||
assert client_dict == expected_clients | ||
|
||
def test_extra_clients_iq_module(mock_communicator): | ||
expected_clients = set( | ||
[ | ||
"brushless_drive", | ||
"propeller_motor_control", | ||
"anticogging", | ||
"buzzer_control", | ||
"esc_propeller_input_parser", | ||
"hobby_input", | ||
"persistent_memory", | ||
"power_monitor", | ||
"serial_interface", | ||
"servo_input_parser", | ||
"step_direction_input", | ||
"system_control", | ||
"temperature_estimator", | ||
"temperature_monitor_uc", | ||
"extra_client", | ||
], | ||
) | ||
|
||
extra_client = os.path.join(os.path.dirname(__file__), ("extra_client_files/extra_client.json")) | ||
print(extra_client) | ||
|
||
iq_module = NonExtraModule(mock_communicator, 0, extra_clients=[extra_client]) | ||
client_dict = set(iq_module._client_dict.keys()) | ||
assert client_dict == expected_clients |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters