def spawn_shell(): """ Spawns the Tinymovr Studio IPython shell. """ version: str = pkg_resources.require("tinymovr")[0].version arguments: Dict[str, str] = docopt(__doc__, version=shell_name + " " + str(version)) logger = configure_logging() num_parser = pynumparser.NumberSequence(limits=(0, 16)) node_ids = num_parser(arguments["--ids"]) bustype: str = arguments["--bustype"] channel: str = arguments["--chan"] bitrate: int = int(arguments["--bitrate"]) do_version_check: bool = not arguments["--no-version-check"] if channel == "auto": channel = guess_channel(bustype_hint=bustype) can_bus: can.Bus = can.Bus(bustype=bustype, channel=channel, bitrate=bitrate) iface: IFace = CANBus(can_bus) tms: Dict = {} for node_id in node_ids: try: tm: UserWrapper = UserWrapper(node_id=node_id, iface=iface, version_check=do_version_check) tm_name: str = base_name + str(node_id) logger.info("Connected to " + tm_name) tms[tm_name] = tm except TimeoutError: logger.info("Node " + str(node_id) + " timed out") except IOError: logger.error("Node " + str(node_id) + " received abnormal message (possibly wrong ID?)") if len(tms) == 0: logger.error("No Tinymovr instances detected. Exiting shell...") else: tms_discovered: str = ", ".join(list(tms.keys())) user_ns: Dict = {} user_ns.update(tms) user_ns["tms"] = list(tms.values()) user_ns["plot"] = plot user_ns["ureg"] = get_registry() print(shell_name + " " + str(version)) print("Discovered instances: " + tms_discovered) print("Access Tinymovr instances as tmx, where x \ is the index starting from 1") print("e.g. the first Tinymovr instance will be tm1.") print("Instances are also available by index in the tms list.") c = Config() c.InteractiveShellApp.gui = "tk" c.TerminalIPythonApp.display_banner = False IPython.start_ipython(argv=[], config=c, user_ns=user_ns) logger.debug("Exiting shell...")
This unit test suite tests functionality of Tinymovr boards. ''' import random import time import statistics as st import tinymovr from tinymovr import Tinymovr from tinymovr.constants import ErrorIDs from tinymovr.units import get_registry import unittest from tests import TMTestCase ureg = get_registry() A = ureg.ampere ticks = ureg.ticks s = ureg.second class TestBoard(TMTestCase): def test_a_encoder(self): ''' Test encoder readings ''' pos_estimates = [] for _ in range(500): pos_estimates.append(self.tm.encoder_estimates.position) time.sleep(0.001) # apparently the statistics lib works with quantities only