-
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.
Updated Vertiq2306 with new pulsing firmware. Added additional files …
…for backwards compatibility
- Loading branch information
1 parent
1ea5bf1
commit 478ab0b
Showing
7 changed files
with
282 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,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,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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import pytest | ||
import iqmotion as iq | ||
|
||
|
||
class TestAPI: | ||
@pytest.fixture | ||
def com_port(self): | ||
return iq.SerialCommunicator("COM4") | ||
|
||
@pytest.fixture | ||
def pulsing_module(self, com_port): | ||
return iq.Vertiq2306(com_port, 0, firmware="pulsing") | ||
|
||
@pytest.fixture | ||
def client_list(self, pulsing_module): | ||
return pulsing_module.return_clients() | ||
|
||
def test_telemetry(self, pulsing_module): | ||
telemetry = pulsing_module.get("iquart_flight_controller_interface", "telemetry") | ||
print(f"\n telemetry type: {type(telemetry)}") | ||
print(telemetry) | ||
|
||
def test_brushless_drive_set(self, pulsing_module, client_list): | ||
assert client_list is not None | ||
|
||
client_name = "brushless_drive" | ||
assert client_name in client_list | ||
|
||
client_entries = pulsing_module.return_client_entries(client_name) | ||
assert client_entries is not None | ||
|
||
client_entry_name = "drive_mode" | ||
assert client_entry_name in client_entries | ||
|
||
print("\nSetting drive mode to 5 (coast)") | ||
status = pulsing_module.set_verify(client_name, client_entry_name, 5) | ||
print(f"status: {status}") | ||
assert status is True | ||
print("Getting updated drive mode") | ||
response = pulsing_module.get(client_name, client_entry_name) | ||
print(f"response: {response}") | ||
assert response is 5 | ||
|
||
def test_get_all(self, pulsing_module, client_list): | ||
print('\n') | ||
for client in client_list: | ||
print(f"\ntesting {client}") | ||
responses = pulsing_module.get_all(client) | ||
assert responses is not None | ||
|
||
for response in responses: | ||
print(f"testing {response}: {responses[response]}") | ||
# assert responses[response] is not None |
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