Skip to content

Commit

Permalink
Merge pull request #33 from iq-motion-control/sync-with-bitbucket
Browse files Browse the repository at this point in the history
Sync with bitbucket
  • Loading branch information
Vertiq-Ben committed Jun 20, 2023
2 parents 30e973b + cf6f914 commit aa0f476
Show file tree
Hide file tree
Showing 26 changed files with 418 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changes/0.11.10.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "remove the local toml file",
"type": "patch"
}
]
6 changes: 6 additions & 0 deletions .changes/0.11.11.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "compress rd module code",
"type": "patch"
}
]
6 changes: 6 additions & 0 deletions .changes/0.11.12.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "Updated Vertiq8108 Files",
"type": "patch"
}
]
6 changes: 6 additions & 0 deletions .changes/0.11.13.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "Patched RD module to work with Windows",
"type": "patch"
}
]
6 changes: 6 additions & 0 deletions .changes/0.11.2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "Restored CustomIQModule",
"type": "patch"
}
]
6 changes: 6 additions & 0 deletions .changes/0.11.3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "Exposes CustomIQModule through iq import",
"type": "patch"
}
]
6 changes: 6 additions & 0 deletions .changes/0.11.4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "Internal Update",
"type": "patch"
}
]
6 changes: 6 additions & 0 deletions .changes/0.11.5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "internal update 2",
"type": "patch"
}
]
6 changes: 6 additions & 0 deletions .changes/0.11.6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "Added Anticogging_ft client to main code base",
"type": "patch"
}
]
6 changes: 6 additions & 0 deletions .changes/0.11.7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "You can now change the baudrate from within the module using .update_baudrate",
"type": "patch"
}
]
6 changes: 6 additions & 0 deletions .changes/0.11.8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "modified anticogging_pro",
"type": "patch"
}
]
6 changes: 6 additions & 0 deletions .changes/0.11.9.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "get_all_retry bug fix",
"type": "patch"
}
]
6 changes: 6 additions & 0 deletions .changes/0.12.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "Update persistent_memory client file",
"type": "minor"
}
]
6 changes: 6 additions & 0 deletions .changes/0.13.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "Update anticogging_pro, brushless_drive, hobby_input, persistent_memory, power_monitor, serial_interface, servo_input_parser, system_control, temperature_esimator, and uavcan_node",
"type": "minor"
}
]
6 changes: 6 additions & 0 deletions .changes/0.13.1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "Undo derate name change in brushless_drive",
"type": "patch"
}
]
6 changes: 6 additions & 0 deletions .changes/0.14.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "Added power_safety client",
"type": "minor"
}
]
6 changes: 6 additions & 0 deletions .changes/0.14.1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "Fix param_idn fields in power_safety",
"type": "patch"
}
]
6 changes: 6 additions & 0 deletions .changes/0.14.2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "Fix unit fields for power_safety",
"type": "patch"
}
]
6 changes: 6 additions & 0 deletions .changes/0.15.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "Added new clients for 81-08 speed, fortiq, and pulsing",
"type": "minor"
}
]
6 changes: 6 additions & 0 deletions .changes/0.15.1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "Update client files for 8108 servo",
"type": "patch"
}
]
6 changes: 6 additions & 0 deletions .changes/0.16.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "Added new 4006 module and updated endpoints for system_control",
"type": "minor"
}
]
84 changes: 84 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,90 @@
# Changelog
Note: version releases in the 0.x.y range may introduce breaking changes.

## 0.16.0

- minor: Added new 4006 module and updated endpoints for system_control

## 0.15.1

- patch: Update client files for 8108 servo

## 0.15.0

- minor: Added new clients for 81-08 speed, fortiq, and pulsing

## 0.14.2

- patch: Fix unit fields for power_safety

## 0.14.1

- patch: Fix param_idn fields in power_safety

## 0.14.0

- minor: Added power_safety client

## 0.13.1

- patch: Undo derate name change in brushless_drive

## 0.13.0

- minor: Update anticogging_pro, brushless_drive, hobby_input, persistent_memory, power_monitor, serial_interface, servo_input_parser, system_control, temperature_esimator, and uavcan_node

## 0.12.0

- minor: Update persistent_memory client file

## 0.11.13

- patch: Patched RD module to work with Windows

## 0.11.12

- patch: Updated Vertiq8108 Files

## 0.11.11

- patch: compress rd module code

## 0.11.10

- patch: remove the local toml file

## 0.11.9

- patch: get_all_retry bug fix

## 0.11.8

- patch: modified anticogging_pro

## 0.11.7

- patch: You can now change the baudrate from within the module using .update_baudrate

## 0.11.6

- patch: Added Anticogging_ft client to main code base

## 0.11.5

- patch: internal update 2

## 0.11.4

- patch: Internal Update

## 0.11.3

- patch: Exposes CustomIQModule through iq import

## 0.11.2

- patch: Restored CustomIQModule

## 0.11.1

- patch: Updated Coverage tests for the New Vertiq's, Fortiq's, and Base Modules
Expand Down
124 changes: 124 additions & 0 deletions iqmotion/iq_devices/rd_iq_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
from iqmotion.iq_devices.iq_module import IqModule
from iqmotion.communication.serial_communicator import SerialCommunicator
from iqmotion.custom_errors import CommunicationError, IqModuleError
from iqmotion.iq_devices.utils import get_parent_dir, load_all_clients

import os
import sys
import glob
import serial

SPEED = '1'
SERVO = '2'
STEPDIR = '4'

class RdModule(IqModule):
""" Creates R&D Object with every publicly available json
The R&D Module does a few things different than other modules:
1. Creates dynamic json that contains all the public facing clients
2. Automatically connects to serial com port
Will throw an error if more than one serial port exists and one wasn't provided
Optional Arguments:
com {Communicator} -- The communicator object to interface with the IqModule
port {str} -- will connect to this port if more than one port is detected
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})
"""

def __init__(
self,
port: str=None,
baudrate: int=115200,
module_idn: int = 0,
style: str = None,
clients_path: str = None
):

self._DEFAULT_VELOCITY_CLIENT_ENTRY = "ctrl_velocity"
self._DEFAULT_VOLTS_CLIENT_ENTRY = "ctrl_volts"
self._MODULE_FILE_NAME = "rd.json"


# Dynamically Load all clients into one module file
path = os.path.join(get_parent_dir(__file__, 2), "clients/client_files")
rd = os.path.join(os.path.dirname(__file__), "module_files/rd.json")
clients = load_all_clients(path)

# Load them into a RD Module file
with open(rd, 'w') as f:
f.write(clients)

# Pull all the available ports into a list
ports_avail = self._find_serial_ports()

# Let user decide which port they want
if port is not None:
com = SerialCommunicator(port, baudrate)
# Otherwise allow RdModule auto-connect if it's only 1 port open
elif len(ports_avail) == 1:
port = ports_avail[0]
com = SerialCommunicator(port, baudrate)
# If too many ports are available, you should pass one in
elif len(ports_avail) > 1:
err_msg = "Too many ports available to choose from, "
err_msg += "Please choose one of the following:\n\n"
err_msg += f"{ports_avail}\n"
err_msg += "ex: motor = iq.RdModule(port='COM1', baudrate=115200)"
raise CommunicationError(err_msg)
# No ports available
else:
err_msg = "No available ports detected"
raise CommunicationError(err_msg)


super().__init__(com, module_idn, clients_path)

# Try to automagically figure out the firmware style
firmware_version = self.get("system_control", "firmware_version")
firmware_style = str(0xFFFF & (firmware_version >> 20))
if (style=="speed" or firmware_style == SPEED):
self._DEFAULT_CONTROL_CLIENT = "propeller_motor_control"
elif(style=="position" or firmware_style == SERVO or firmware_style == STEPDIR):
self._DEFAULT_CONTROL_CLIENT = "multi_turn_angle_control"
else:
err_msg = "Please select the motor firmware style:\n\n"
err_msg += "'speed' or 'position'"
raise IqModuleError(err_msg)


def _find_serial_ports(self):
""" Finds a list of open serial ports
Raises:
EnvironmentError: Unsupported platform
Returns:
list: List of str of open serial ports
"""

if sys.platform.startswith("win"):
ports = ["COM%s" % (i + 1) for i in range(256)]
elif sys.platform.startswith("linux") or sys.platform.startswith("cygwin"):
# this excludes your current terminal "/dev/tty"
# this excludes everything but the /dev/ttyUSB
ports = glob.glob("/dev/tty[U-Z]*")
elif sys.platform.startswith("darwin"):
ports = glob.glob("/dev/tty.*")
else:
raise EnvironmentError("Unsupported platform")

working_ports = []
for port in ports:
try:
s = serial.Serial(port)
s.close()
working_ports.append(port)
except (OSError, serial.SerialException):
pass

return working_ports

0 comments on commit aa0f476

Please sign in to comment.