diff --git a/external_samples/color_range_sensor.py b/external_samples/color_range_sensor.py index d05ea0c3..1534347d 100644 --- a/external_samples/color_range_sensor.py +++ b/external_samples/color_range_sensor.py @@ -51,10 +51,6 @@ def get_url(self) -> str: def get_version(self) -> tuple[int, int, int]: return (1, 0, 0) - def stop(self) -> None: - # send stop command to sensor - pass - def reset(self) -> None: pass diff --git a/external_samples/component.py b/external_samples/component.py index 82245081..e6992a4d 100644 --- a/external_samples/component.py +++ b/external_samples/component.py @@ -71,8 +71,13 @@ def get_url(self) -> str: def get_version(self) -> tuple[int, int, int]: pass + def start(self) -> None: + pass + + def update(self) -> None: + pass + # This stops all movement (if any) for the component - @abstractmethod def stop(self) -> None: pass diff --git a/external_samples/expansion_hub_motor.py b/external_samples/expansion_hub_motor.py new file mode 100644 index 00000000..50fb03e2 --- /dev/null +++ b/external_samples/expansion_hub_motor.py @@ -0,0 +1,123 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""This is the expansion_hub_motor module. + +This component wraps the expansion_hub.ExpansionHubMotor class, providing +support for a motor connected to a REV Expansion Hub. +""" + +__author__ = "lizlooney@google.com (Liz Looney)" + +from typing import Self +from component import Component, PortType, InvalidPortException +import expansion_hub +import wpimath + +# TODO(lizlooney): Update port types. + +class ExpansionHubMotor(Component): + def __init__(self, ports : list[tuple[PortType, int]]): + port_type, hub_number = ports[0] + if port_type != PortType.USB_PORT: + raise InvalidPortException + port_type, motor_number = ports[1] + if port_type != PortType.USB_PORT: + raise InvalidPortException + self.expansion_hub_motor = expansion_hub.ExpansionHubMotor(hub_number, motor_number) + + def get_manufacturer(self) -> str: + return "REV Robotics" + + def get_name(self) -> str: + return "Expansion Hub Motor" + + def get_part_number(self) -> str: + return "" + + def get_url(self) -> str: + return "" + + def get_version(self) -> tuple[int, int, int]: + return (1, 0, 0) + + def start(self) -> None: + self.expansion_hub_motor.setEnabled(True) + + def stop(self) -> None: + # TODO: Send stop command to motor. + pass + + def reset(self) -> None: + pass + + def get_connection_port_type(self) -> list[PortType]: + return [PortType.USB_PORT, PortType.USB_PORT] + + def periodic(self) -> None: + pass + + # Alternative constructor to create an instance from a hub number and a motor port. + @classmethod + def from_hub_number_and_motor_number(cls: type[Self], hub_number: int, motor_number: int) -> Self: + return cls([(PortType.USB_PORT, hub_number), (PortType.USB_PORT, motor_number)]) + + # Component specific methods + + # Methods from expansion_hub.ExpansionHubMotor + + def setPercentagePower(self, power: float): + self.expansion_hub_motor.setPercentagePower(power) + + def setVoltage(self, voltage: wpimath.units.volts): + self.expansion_hub_motor.setVoltage(voltage) + + def setPositionSetpoint(self, setpoint: float): + self.expansion_hub_motor.setPositionSetpoint(setpoint) + + def setVelocitySetpoint(self, setpoint: float): + self.expansion_hub_motor.setVelocitySetpoint(setpoint) + + def setEnabled(self, enabled: bool): + self.expansion_hub_motor.setEnabled(enabled) + + def setFloatOn0(self, floatOn0: bool): + self.expansion_hub_motor.setFloatOn0(floatOn0) + + def getCurrent(self) -> float: + return self.expansion_hub_motor.getCurrent() + + def setDistancePerCount(self, perCount: float): + self.expansion_hub_motor.setDistancePerCount(perCount) + + def isHubConnected(self) -> bool: + return self.expansion_hub_motor.isHubConnected() + + def getEncoder(self) -> float: + return self.expansion_hub_motor.getEncoder() + + def getEncoderVelocity(self) -> float: + return self.expansion_hub_motor.getEncoderVelocity() + + def setReversed(self, reversed: bool): + self.expansion_hub_motor.setReversed(reversed) + + def resetEncoder(self): + self.expansion_hub_motor.resetEncoder() + + def getVelocityPidConstants(self) -> expansion_hub.ExpansionHubPidConstants: + return self.expansion_hub_motor.getVelocityPidConstants() + + def getPositionPidConstants(self) -> expansion_hub.ExpansionHubPidConstants: + return self.expansion_hub_motor.getPositionPidConstants() diff --git a/external_samples/expansion_hub_servo.py b/external_samples/expansion_hub_servo.py new file mode 100644 index 00000000..5f7d6c64 --- /dev/null +++ b/external_samples/expansion_hub_servo.py @@ -0,0 +1,96 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""This is the expansion_hub_servo module. + +This component wraps the expansion_hub.ExpansionHubServo class, providing +support for a servo connected to a REV Expansion Hub. +""" + +__author__ = "lizlooney@google.com (Liz Looney)" + +from typing import Self +from component import Component, PortType, InvalidPortException +import expansion_hub + +# TODO(lizlooney): Update port types. + +class ExpansionHubServo(Component): + def __init__(self, ports : list[tuple[PortType, int]]): + port_type, hub_number = ports[0] + if port_type != PortType.USB_PORT: + raise InvalidPortException + port_type, servo_number = ports[1] + if port_type != PortType.USB_PORT: + raise InvalidPortException + self.expansion_hub_servo = expansion_hub.ExpansionHubServo(hub_number, servo_number) + + def get_manufacturer(self) -> str: + return "REV Robotics" + + def get_name(self) -> str: + return "Expansion Hub Servo" + + def get_part_number(self) -> str: + return "" + + def get_url(self) -> str: + return "" + + def get_version(self) -> tuple[int, int, int]: + return (1, 0, 0) + + def start(self) -> None: + self.expansion_hub_servo.setEnabled(True) + pass + + def stop(self) -> None: + # TODO: Send stop command to servo. + pass + + def reset(self) -> None: + pass + + def get_connection_port_type(self) -> list[PortType]: + return [PortType.USB_PORT, PortType.USB_PORT] + + def periodic(self) -> None: + pass + + # Alternative constructor to create an instance from a hub number and a servo port. + @classmethod + def from_hub_number_and_servo_number(cls: type[Self], hub_number: int, servo_number: int) -> Self: + return cls([(PortType.USB_PORT, hub_number), (PortType.USB_PORT, servo_number)]) + + # Component specific methods + + # Methods from expansion_hub.ExpansionHubServo + + def set(self, value: float): + self.expansion_hub_servo.set(value) + + def setAngle(self, degrees: float): + self.expansion_hub_servo.setAngle(degrees) + + def setEnabled(self, enabled: bool): + self.expansion_hub_servo.setEnabled(enabled) + + def isHubConnected(self) -> bool: + return self.expansion_hub_servo.isHubConnected() + + def setFramePeriod(self, framePeriod: int): + self.expansion_hub_servo.setFramePeriod(framePeriod) + + def setPulseWidth(self, pulseWidth: int): + self.expansion_hub_servo.setPulseWidth(pulseWidth) diff --git a/external_samples/rev_touch_sensor.py b/external_samples/rev_touch_sensor.py index 7ffe2646..9f9ab179 100644 --- a/external_samples/rev_touch_sensor.py +++ b/external_samples/rev_touch_sensor.py @@ -42,9 +42,6 @@ def get_url(self) -> str: def get_version(self) -> tuple[int, int, int]: return (1, 0, 0) - def stop(self) -> None: - pass - def reset(self) -> None: self.pressed_callback = None self.released_callback = None diff --git a/external_samples/servo.py b/external_samples/servo.py index 35a1ccbe..d5683660 100644 --- a/external_samples/servo.py +++ b/external_samples/servo.py @@ -42,7 +42,7 @@ def get_version(self) -> tuple[int, int, int]: return (1, 0, 0) def stop(self) -> None: - # De-energize servo port + # TODO: De-energize servo port pass def reset(self) -> None: diff --git a/external_samples/smart_motor.py b/external_samples/smart_motor.py index 79c5981d..db153979 100644 --- a/external_samples/smart_motor.py +++ b/external_samples/smart_motor.py @@ -42,7 +42,7 @@ def get_version(self) -> tuple[int, int, int]: return (1, 0, 0) def stop(self) -> None: - # send stop command to motor + # TODO: send stop command to motor pass def reset(self) -> None: diff --git a/external_samples/spark_mini.py b/external_samples/spark_mini.py index aa1b3897..1e3790fd 100644 --- a/external_samples/spark_mini.py +++ b/external_samples/spark_mini.py @@ -50,7 +50,7 @@ def get_version(self) -> tuple[int, int, int]: return (1, 0, 0) def stop(self) -> None: - # send stop command to motor + # TODO: send stop command to motor pass def reset(self) -> None: diff --git a/python_tools/generate_json.py b/python_tools/generate_json.py index 2173adcc..e2ffbc93 100644 --- a/python_tools/generate_json.py +++ b/python_tools/generate_json.py @@ -59,6 +59,8 @@ sys.path.append("../external_samples") import color_range_sensor import component +import expansion_hub_motor +import expansion_hub_servo import rev_touch_sensor import servo import smart_motor @@ -119,6 +121,8 @@ def main(argv): external_samples_modules = [ color_range_sensor, component, + expansion_hub_motor, + expansion_hub_servo, rev_touch_sensor, servo, smart_motor, diff --git a/server_python_scripts/run_opmode.py b/server_python_scripts/run_opmode.py index fd79eafe..4b42ee4a 100755 --- a/server_python_scripts/run_opmode.py +++ b/server_python_scripts/run_opmode.py @@ -13,6 +13,7 @@ import importlib.util import inspect import argparse +import traceback from pathlib import Path from blocks_base_classes import OpMode @@ -151,6 +152,7 @@ def run_opmode(opmode_file, duration=None, loop_frequency=50): except Exception as e: print(f"Error running opmode: {e}") + traceback.print_exc() sys.exit(1) @@ -206,4 +208,4 @@ def main(): if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/src/blocks/utils/generated/external_samples_data.json b/src/blocks/utils/generated/external_samples_data.json index 1443c640..08c503d3 100644 --- a/src/blocks/utils/generated/external_samples_data.json +++ b/src/blocks/utils/generated/external_samples_data.json @@ -253,6 +253,19 @@ "returnType": "None", "tooltip": "" }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "color_range_sensor.ColorRangeSensor" + } + ], + "declaringClassName": "color_range_sensor.ColorRangeSensor", + "functionName": "start", + "returnType": "None", + "tooltip": "" + }, { "args": [ { @@ -265,6 +278,19 @@ "functionName": "stop", "returnType": "None", "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "color_range_sensor.ColorRangeSensor" + } + ], + "declaringClassName": "color_range_sensor.ColorRangeSensor", + "functionName": "update", + "returnType": "None", + "tooltip": "" } ], "instanceVariables": [], @@ -303,29 +329,749 @@ "args": [ { "defaultValue": "", - "name": "ports", - "type": "list[tuple[component.PortType, int]]" + "name": "ports", + "type": "list[tuple[component.PortType, int]]" + } + ], + "declaringClassName": "component.Component", + "functionName": "__init__", + "returnType": "component.Component", + "tooltip": "" + } + ], + "enums": [], + "instanceMethods": [ + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "component.Component" + } + ], + "declaringClassName": "component.Component", + "functionName": "get_connection_port_type", + "returnType": "list[component.PortType]", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "component.Component" + } + ], + "declaringClassName": "component.Component", + "functionName": "get_manufacturer", + "returnType": "str", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "component.Component" + } + ], + "declaringClassName": "component.Component", + "functionName": "get_name", + "returnType": "str", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "component.Component" + } + ], + "declaringClassName": "component.Component", + "functionName": "get_part_number", + "returnType": "str", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "component.Component" + } + ], + "declaringClassName": "component.Component", + "functionName": "get_url", + "returnType": "str", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "component.Component" + } + ], + "declaringClassName": "component.Component", + "functionName": "get_version", + "returnType": "tuple[int, int, int]", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "component.Component" + } + ], + "declaringClassName": "component.Component", + "functionName": "periodic", + "returnType": "None", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "component.Component" + } + ], + "declaringClassName": "component.Component", + "functionName": "reset", + "returnType": "None", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "component.Component" + } + ], + "declaringClassName": "component.Component", + "functionName": "start", + "returnType": "None", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "component.Component" + } + ], + "declaringClassName": "component.Component", + "functionName": "stop", + "returnType": "None", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "component.Component" + } + ], + "declaringClassName": "component.Component", + "functionName": "update", + "returnType": "None", + "tooltip": "" + } + ], + "instanceVariables": [], + "moduleName": "component", + "staticMethods": [] + }, + { + "className": "component.EmptyCallable", + "classVariables": [], + "constructors": [], + "enums": [], + "instanceMethods": [], + "instanceVariables": [], + "moduleName": "component", + "staticMethods": [] + }, + { + "className": "component.InvalidPortException", + "classVariables": [], + "constructors": [ + { + "args": [ + { + "defaultValue": "", + "name": "args", + "type": "tuple" + }, + { + "defaultValue": "", + "name": "kwargs", + "type": "dict" + } + ], + "declaringClassName": "component.InvalidPortException", + "functionName": "__init__", + "returnType": "component.InvalidPortException", + "tooltip": "Initialize self. See help(type(self)) for accurate signature." + } + ], + "enums": [], + "instanceMethods": [], + "instanceVariables": [], + "moduleName": "component", + "staticMethods": [] + }, + { + "className": "expansion_hub_motor.ExpansionHubMotor", + "classVariables": [], + "constructors": [ + { + "args": [ + { + "defaultValue": "", + "name": "ports", + "type": "list[tuple[component.PortType, int]]" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "__init__", + "returnType": "expansion_hub_motor.ExpansionHubMotor", + "tooltip": "" + } + ], + "enums": [], + "instanceMethods": [ + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "getCurrent", + "returnType": "float", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "getEncoder", + "returnType": "float", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "getEncoderVelocity", + "returnType": "float", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "getPositionPidConstants", + "returnType": "expansion_hub.ExpansionHubPidConstants", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "getVelocityPidConstants", + "returnType": "expansion_hub.ExpansionHubPidConstants", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "get_connection_port_type", + "returnType": "list[component.PortType]", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "get_manufacturer", + "returnType": "str", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "get_name", + "returnType": "str", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "get_part_number", + "returnType": "str", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "get_url", + "returnType": "str", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "get_version", + "returnType": "tuple[int, int, int]", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "isHubConnected", + "returnType": "bool", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "periodic", + "returnType": "None", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "reset", + "returnType": "None", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "resetEncoder", + "returnType": "None", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + }, + { + "defaultValue": "", + "name": "perCount", + "type": "float" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "setDistancePerCount", + "returnType": "None", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + }, + { + "defaultValue": "", + "name": "enabled", + "type": "bool" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "setEnabled", + "returnType": "None", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + }, + { + "defaultValue": "", + "name": "floatOn0", + "type": "bool" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "setFloatOn0", + "returnType": "None", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + }, + { + "defaultValue": "", + "name": "power", + "type": "float" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "setPercentagePower", + "returnType": "None", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + }, + { + "defaultValue": "", + "name": "setpoint", + "type": "float" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "setPositionSetpoint", + "returnType": "None", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + }, + { + "defaultValue": "", + "name": "reversed", + "type": "bool" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "setReversed", + "returnType": "None", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + }, + { + "defaultValue": "", + "name": "setpoint", + "type": "float" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "setVelocitySetpoint", + "returnType": "None", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + }, + { + "defaultValue": "", + "name": "voltage", + "type": "float" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "setVoltage", + "returnType": "None", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "start", + "returnType": "None", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "stop", + "returnType": "None", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_motor.ExpansionHubMotor" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "update", + "returnType": "None", + "tooltip": "" + } + ], + "instanceVariables": [], + "moduleName": "expansion_hub_motor", + "staticMethods": [ + { + "args": [ + { + "defaultValue": "", + "name": "hub_number", + "type": "int" + }, + { + "defaultValue": "", + "name": "motor_number", + "type": "int" + } + ], + "declaringClassName": "expansion_hub_motor.ExpansionHubMotor", + "functionName": "from_hub_number_and_motor_number", + "returnType": "expansion_hub_motor.ExpansionHubMotor", + "tooltip": "" + } + ] + }, + { + "className": "expansion_hub_servo.ExpansionHubServo", + "classVariables": [], + "constructors": [ + { + "args": [ + { + "defaultValue": "", + "name": "ports", + "type": "list[tuple[component.PortType, int]]" + } + ], + "declaringClassName": "expansion_hub_servo.ExpansionHubServo", + "functionName": "__init__", + "returnType": "expansion_hub_servo.ExpansionHubServo", + "tooltip": "" + } + ], + "enums": [], + "instanceMethods": [ + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_servo.ExpansionHubServo" + } + ], + "declaringClassName": "expansion_hub_servo.ExpansionHubServo", + "functionName": "get_connection_port_type", + "returnType": "list[component.PortType]", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_servo.ExpansionHubServo" + } + ], + "declaringClassName": "expansion_hub_servo.ExpansionHubServo", + "functionName": "get_manufacturer", + "returnType": "str", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_servo.ExpansionHubServo" + } + ], + "declaringClassName": "expansion_hub_servo.ExpansionHubServo", + "functionName": "get_name", + "returnType": "str", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_servo.ExpansionHubServo" + } + ], + "declaringClassName": "expansion_hub_servo.ExpansionHubServo", + "functionName": "get_part_number", + "returnType": "str", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_servo.ExpansionHubServo" + } + ], + "declaringClassName": "expansion_hub_servo.ExpansionHubServo", + "functionName": "get_url", + "returnType": "str", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_servo.ExpansionHubServo" + } + ], + "declaringClassName": "expansion_hub_servo.ExpansionHubServo", + "functionName": "get_version", + "returnType": "tuple[int, int, int]", + "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_servo.ExpansionHubServo" } ], - "declaringClassName": "component.Component", - "functionName": "__init__", - "returnType": "component.Component", + "declaringClassName": "expansion_hub_servo.ExpansionHubServo", + "functionName": "isHubConnected", + "returnType": "bool", "tooltip": "" - } - ], - "enums": [], - "instanceMethods": [ + }, { "args": [ { "defaultValue": "", "name": "self", - "type": "component.Component" + "type": "expansion_hub_servo.ExpansionHubServo" } ], - "declaringClassName": "component.Component", - "functionName": "get_connection_port_type", - "returnType": "list[component.PortType]", + "declaringClassName": "expansion_hub_servo.ExpansionHubServo", + "functionName": "periodic", + "returnType": "None", "tooltip": "" }, { @@ -333,12 +1079,12 @@ { "defaultValue": "", "name": "self", - "type": "component.Component" + "type": "expansion_hub_servo.ExpansionHubServo" } ], - "declaringClassName": "component.Component", - "functionName": "get_manufacturer", - "returnType": "str", + "declaringClassName": "expansion_hub_servo.ExpansionHubServo", + "functionName": "reset", + "returnType": "None", "tooltip": "" }, { @@ -346,12 +1092,17 @@ { "defaultValue": "", "name": "self", - "type": "component.Component" + "type": "expansion_hub_servo.ExpansionHubServo" + }, + { + "defaultValue": "", + "name": "value", + "type": "float" } ], - "declaringClassName": "component.Component", - "functionName": "get_name", - "returnType": "str", + "declaringClassName": "expansion_hub_servo.ExpansionHubServo", + "functionName": "set", + "returnType": "None", "tooltip": "" }, { @@ -359,12 +1110,17 @@ { "defaultValue": "", "name": "self", - "type": "component.Component" + "type": "expansion_hub_servo.ExpansionHubServo" + }, + { + "defaultValue": "", + "name": "degrees", + "type": "float" } ], - "declaringClassName": "component.Component", - "functionName": "get_part_number", - "returnType": "str", + "declaringClassName": "expansion_hub_servo.ExpansionHubServo", + "functionName": "setAngle", + "returnType": "None", "tooltip": "" }, { @@ -372,12 +1128,17 @@ { "defaultValue": "", "name": "self", - "type": "component.Component" + "type": "expansion_hub_servo.ExpansionHubServo" + }, + { + "defaultValue": "", + "name": "enabled", + "type": "bool" } ], - "declaringClassName": "component.Component", - "functionName": "get_url", - "returnType": "str", + "declaringClassName": "expansion_hub_servo.ExpansionHubServo", + "functionName": "setEnabled", + "returnType": "None", "tooltip": "" }, { @@ -385,12 +1146,17 @@ { "defaultValue": "", "name": "self", - "type": "component.Component" + "type": "expansion_hub_servo.ExpansionHubServo" + }, + { + "defaultValue": "", + "name": "framePeriod", + "type": "int" } ], - "declaringClassName": "component.Component", - "functionName": "get_version", - "returnType": "tuple[int, int, int]", + "declaringClassName": "expansion_hub_servo.ExpansionHubServo", + "functionName": "setFramePeriod", + "returnType": "None", "tooltip": "" }, { @@ -398,11 +1164,16 @@ { "defaultValue": "", "name": "self", - "type": "component.Component" + "type": "expansion_hub_servo.ExpansionHubServo" + }, + { + "defaultValue": "", + "name": "pulseWidth", + "type": "int" } ], - "declaringClassName": "component.Component", - "functionName": "periodic", + "declaringClassName": "expansion_hub_servo.ExpansionHubServo", + "functionName": "setPulseWidth", "returnType": "None", "tooltip": "" }, @@ -411,11 +1182,11 @@ { "defaultValue": "", "name": "self", - "type": "component.Component" + "type": "expansion_hub_servo.ExpansionHubServo" } ], - "declaringClassName": "component.Component", - "functionName": "reset", + "declaringClassName": "expansion_hub_servo.ExpansionHubServo", + "functionName": "start", "returnType": "None", "tooltip": "" }, @@ -424,57 +1195,50 @@ { "defaultValue": "", "name": "self", - "type": "component.Component" + "type": "expansion_hub_servo.ExpansionHubServo" } ], - "declaringClassName": "component.Component", + "declaringClassName": "expansion_hub_servo.ExpansionHubServo", "functionName": "stop", "returnType": "None", "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "expansion_hub_servo.ExpansionHubServo" + } + ], + "declaringClassName": "expansion_hub_servo.ExpansionHubServo", + "functionName": "update", + "returnType": "None", + "tooltip": "" } ], "instanceVariables": [], - "moduleName": "component", - "staticMethods": [] - }, - { - "className": "component.EmptyCallable", - "classVariables": [], - "constructors": [], - "enums": [], - "instanceMethods": [], - "instanceVariables": [], - "moduleName": "component", - "staticMethods": [] - }, - { - "className": "component.InvalidPortException", - "classVariables": [], - "constructors": [ + "moduleName": "expansion_hub_servo", + "staticMethods": [ { "args": [ { "defaultValue": "", - "name": "args", - "type": "tuple" + "name": "hub_number", + "type": "int" }, { "defaultValue": "", - "name": "kwargs", - "type": "dict" + "name": "servo_number", + "type": "int" } ], - "declaringClassName": "component.InvalidPortException", - "functionName": "__init__", - "returnType": "component.InvalidPortException", - "tooltip": "Initialize self. See help(type(self)) for accurate signature." + "declaringClassName": "expansion_hub_servo.ExpansionHubServo", + "functionName": "from_hub_number_and_servo_number", + "returnType": "expansion_hub_servo.ExpansionHubServo", + "tooltip": "" } - ], - "enums": [], - "instanceMethods": [], - "instanceVariables": [], - "moduleName": "component", - "staticMethods": [] + ] }, { "className": "rev_touch_sensor.RevTouchSensor", @@ -649,6 +1413,19 @@ "returnType": "None", "tooltip": "" }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "rev_touch_sensor.RevTouchSensor" + } + ], + "declaringClassName": "rev_touch_sensor.RevTouchSensor", + "functionName": "start", + "returnType": "None", + "tooltip": "" + }, { "args": [ { @@ -661,6 +1438,19 @@ "functionName": "stop", "returnType": "None", "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "rev_touch_sensor.RevTouchSensor" + } + ], + "declaringClassName": "rev_touch_sensor.RevTouchSensor", + "functionName": "update", + "returnType": "None", + "tooltip": "" } ], "instanceVariables": [], @@ -841,6 +1631,19 @@ "returnType": "None", "tooltip": "Set the servo to a position between 0 and 1" }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "servo.Servo" + } + ], + "declaringClassName": "servo.Servo", + "functionName": "start", + "returnType": "None", + "tooltip": "" + }, { "args": [ { @@ -853,6 +1656,19 @@ "functionName": "stop", "returnType": "None", "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "servo.Servo" + } + ], + "declaringClassName": "servo.Servo", + "functionName": "update", + "returnType": "None", + "tooltip": "" } ], "instanceVariables": [], @@ -1072,6 +1888,19 @@ "returnType": "None", "tooltip": "Set the motor to a speed between -1 and 1" }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "smart_motor.SmartMotor" + } + ], + "declaringClassName": "smart_motor.SmartMotor", + "functionName": "start", + "returnType": "None", + "tooltip": "" + }, { "args": [ { @@ -1084,6 +1913,19 @@ "functionName": "stop", "returnType": "None", "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "smart_motor.SmartMotor" + } + ], + "declaringClassName": "smart_motor.SmartMotor", + "functionName": "update", + "returnType": "None", + "tooltip": "" } ], "instanceVariables": [], @@ -1515,6 +2357,19 @@ "returnType": "None", "tooltip": "Sets the voltage output of the PWMMotorController. Compensates for\nthe current bus voltage to ensure that the desired voltage is output even\nif the battery voltage is below 12V - highly useful when the voltage\noutputs are \"meaningful\" (e.g. they come from a feedforward calculation).\n\nNOTE: This function *must* be called regularly in order for voltage\ncompensation to work properly - unlike the ordinary set function, it is not\n\"set it and forget it.\"\n\n:param output: The voltage to output." }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "spark_mini.SparkMini" + } + ], + "declaringClassName": "spark_mini.SparkMini", + "functionName": "start", + "returnType": "None", + "tooltip": "" + }, { "args": [ { @@ -1540,6 +2395,19 @@ "functionName": "stop_motor", "returnType": "None", "tooltip": "" + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "spark_mini.SparkMini" + } + ], + "declaringClassName": "spark_mini.SparkMini", + "functionName": "update", + "returnType": "None", + "tooltip": "" } ], "instanceVariables": [], @@ -1745,6 +2613,19 @@ "returnType": "None", "tooltip": "Change the color of all LEDs using a list." }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "sparkfun_led_stick.SparkFunLEDStick" + } + ], + "declaringClassName": "sparkfun_led_stick.SparkFunLEDStick", + "functionName": "start", + "returnType": "None", + "tooltip": "" + }, { "args": [ { @@ -1770,6 +2651,19 @@ "functionName": "turn_all_off", "returnType": "None", "tooltip": "Turn all LEDs off." + }, + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "sparkfun_led_stick.SparkFunLEDStick" + } + ], + "declaringClassName": "sparkfun_led_stick.SparkFunLEDStick", + "functionName": "update", + "returnType": "None", + "tooltip": "" } ], "instanceVariables": [], @@ -1818,6 +2712,18 @@ "moduleName": "component", "moduleVariables": [] }, + { + "enums": [], + "functions": [], + "moduleName": "expansion_hub_motor", + "moduleVariables": [] + }, + { + "enums": [], + "functions": [], + "moduleName": "expansion_hub_servo", + "moduleVariables": [] + }, { "enums": [], "functions": [], @@ -1852,6 +2758,8 @@ "subclasses": { "component.Component": [ "color_range_sensor.ColorRangeSensor", + "expansion_hub_motor.ExpansionHubMotor", + "expansion_hub_servo.ExpansionHubServo", "rev_touch_sensor.RevTouchSensor", "servo.Servo", "smart_motor.SmartMotor", diff --git a/src/blocks/utils/generated/server_python_scripts.json b/src/blocks/utils/generated/server_python_scripts.json index a71338a3..820d87f4 100644 --- a/src/blocks/utils/generated/server_python_scripts.json +++ b/src/blocks/utils/generated/server_python_scripts.json @@ -137,6 +137,19 @@ ], "enums": [], "instanceMethods": [ + { + "args": [ + { + "defaultValue": "", + "name": "self", + "type": "blocks_base_classes.RobotBase" + } + ], + "declaringClassName": "blocks_base_classes.RobotBase", + "functionName": "define_hardware", + "returnType": "None", + "tooltip": "" + }, { "args": [ { diff --git a/src/toolbox/methods_category.ts b/src/toolbox/methods_category.ts index 02a54fdc..258e1912 100644 --- a/src/toolbox/methods_category.ts +++ b/src/toolbox/methods_category.ts @@ -63,12 +63,14 @@ export class MethodsCategory { switch (editor.getCurrentModuleType()) { case commonStorage.MODULE_TYPE_ROBOT: // TODO(lizlooney): We need a way to mark a method in python as not overridable. - // For example, in RobotBase, register_event_handler, unregister_event_handler, - // and fire_event should not be overridden in a user's robot. + // For example, in RobotBase, define_hardware, register_event_handler, + // unregister_event_handler, and fire_event should not be overridden in a user's robot. const methodNamesNotOverrideable: string[] = [ + 'define_hardware', + 'fire_event', + 'register_event_handler', 'register_event_handler', 'unregister_event_handler', - 'fire_event', ]; // Add the methods for a Robot. this.addClassBlocksForCurrentModule(