diff --git a/Firmware/MotorControl/odrive_main.h b/Firmware/MotorControl/odrive_main.h index 20b1124a..62bd4f57 100644 --- a/Firmware/MotorControl/odrive_main.h +++ b/Firmware/MotorControl/odrive_main.h @@ -214,7 +214,7 @@ enum TimingLog_t { // general system functions defined in main.cpp -class ODrive : public OdriveIntf { +class ODrive : public ODriveIntf { public: void save_configuration() override; void erase_configuration() override; diff --git a/Firmware/Tupfile.lua b/Firmware/Tupfile.lua index 2d4b7341..5f8843e9 100644 --- a/Firmware/Tupfile.lua +++ b/Firmware/Tupfile.lua @@ -3,7 +3,7 @@ tup.include('build.lua') tup.frule{inputs={'fibre/cpp/interfaces_template.j2'}, command='python3 interface_generator.py --definitions odrive-interface.yaml --template %f --output %o', outputs='autogen/interfaces.hpp'} tup.frule{inputs={'fibre/cpp/function_stubs_template.j2'}, command='python3 interface_generator.py --definitions odrive-interface.yaml --template %f --output %o', outputs='autogen/function_stubs.hpp'} -tup.frule{inputs={'fibre/cpp/endpoints_template.j2'}, command='python3 interface_generator.py --definitions odrive-interface.yaml --generate-endpoints Odrive --template %f --output %o', outputs='autogen/endpoints.hpp'} +tup.frule{inputs={'fibre/cpp/endpoints_template.j2'}, command='python3 interface_generator.py --definitions odrive-interface.yaml --generate-endpoints ODrive --template %f --output %o', outputs='autogen/endpoints.hpp'} tup.frule{inputs={'fibre/cpp/type_info_template.j2'}, command='python3 interface_generator.py --definitions odrive-interface.yaml --template %f --output %o', outputs='autogen/type_info.hpp'} tup.frule{command='python3 interface_generator.py --definitions odrive-interface.yaml --template enums_template.j2 --output ../tools/odrive/enums.py'} diff --git a/Firmware/communication/ascii_protocol.cpp b/Firmware/communication/ascii_protocol.cpp index 632ceea3..39f4d891 100644 --- a/Firmware/communication/ascii_protocol.cpp +++ b/Firmware/communication/ascii_protocol.cpp @@ -29,7 +29,7 @@ /* Private variables ---------------------------------------------------------*/ -static Introspectable root_obj = OdriveTypeInfo::make_introspectable(odrv); +static Introspectable root_obj = ODriveTypeInfo::make_introspectable(odrv); /* Private function prototypes -----------------------------------------------*/ /* Function implementations --------------------------------------------------*/ diff --git a/Firmware/communication/interface_can.hpp b/Firmware/communication/interface_can.hpp index b4864611..19855047 100644 --- a/Firmware/communication/interface_can.hpp +++ b/Firmware/communication/interface_can.hpp @@ -19,7 +19,7 @@ enum { CAN_BAUD_1M = 1000000 }; -class ODriveCAN : public OdriveIntf::CanIntf { +class ODriveCAN : public ODriveIntf::CanIntf { public: struct Config_t { uint32_t baud_rate = CAN_BAUD_250K; diff --git a/Firmware/interface_generator.py b/Firmware/interface_generator.py index e83c91d8..14184f1f 100644 --- a/Firmware/interface_generator.py +++ b/Firmware/interface_generator.py @@ -78,6 +78,7 @@ properties: ns: {type: string} version: {type: string} summary: {type: string} + dictionary: {type: array, items: {type: string}} interfaces: type: object additionalProperties: { "$ref": "#/definitions/interface" } @@ -105,13 +106,14 @@ class SafeLineLoader(yaml.SafeLoader): # #mapping['__column__'] = node.start_mark.column + 1 # return mapping - +dictionary = [] def get_words(string): """ Splits a string in PascalCase into a list of lower case words """ - return [w.lower() for w in re.findall('[a-z0-9]+|[A-Z][a-z0-9]*', string)] + regex = ''.join((re.escape(w) + '|') for w in dictionary) + '[a-z0-9]+|[A-Z][a-z0-9]*' + return [(w if w in dictionary else w.lower()) for w in re.findall(regex, string)] def join_name(*names, delimiter: str = '.'): """ @@ -128,7 +130,7 @@ def split_name(name, delimiter: str = '.'): yield c if (parenthesis_depth == 0) or (c != delimiter) else ':' return [part.replace(':', '.') for part in ''.join(replace_delimiter_in_parentheses()).split('.')] -def to_pascal_case(s): return ''.join([w.title() for w in get_words(s)]) +def to_pascal_case(s): return ''.join([(w.title() if not w in dictionary else w) for w in get_words(s)]) def to_camel_case(s): return ''.join([(c.lower() if i == 0 else c) for i, c in enumerate(''.join([w.title() for w in get_words(s)]))]) def to_macro_case(s): return '_'.join(get_words(s)).upper() def to_snake_case(s): return '_'.join(get_words(s)).lower() @@ -519,6 +521,7 @@ for definition_file in definition_files: raise Exception(err.message + '\nat ' + str(list(err.absolute_path))) interfaces = {**interfaces, **get_dict(file_content, 'interfaces')} value_types = {**value_types, **get_dict(file_content, 'valuetypes')} + dictionary += file_content.get('dictionary', None) or [] # Preprocess definitions diff --git a/Firmware/odrive-interface.yaml b/Firmware/odrive-interface.yaml index 8d319fe8..36309b82 100644 --- a/Firmware/odrive-interface.yaml +++ b/Firmware/odrive-interface.yaml @@ -3,8 +3,10 @@ version: 0.0.1 ns: com.odriverobotics summary: ODrive Interface Definitions +dictionary: [ODrive] # Prevent the word 'ODrive' from being detected as two words 'O' and 'Drive' + interfaces: - Odrive: + ODrive: c_is_class: True attributes: vbus_voltage: readonly float32 @@ -162,7 +164,7 @@ interfaces: reboot: enter_dfu_mode: - Odrive.Can: + ODrive.Can: c_is_class: True attributes: error: @@ -625,7 +627,7 @@ interfaces: valuetypes: - Odrive.Can.Protocol: + ODrive.Can.Protocol: values: {Simple: } Axis.AxisState: # TODO: remove redundant "Axis" in name diff --git a/tools/odrive/enums.py b/tools/odrive/enums.py index 55bc64e3..466f11b6 100644 --- a/tools/odrive/enums.py +++ b/tools/odrive/enums.py @@ -1,7 +1,7 @@ # TODO: This file is dangerous because the enums could potentially change between API versions. Should transmit as part of the JSON. -# Odrive.Can.Protocol +# ODrive.Can.Protocol PROTOCOL_SIMPLE = 0 # Axis.AxisState @@ -47,7 +47,7 @@ MOTOR_TYPE_HIGH_CURRENT = 0 MOTOR_TYPE_GIMBAL = 2 MOTOR_TYPE_ACIM = 3 -# Odrive.Can.Error +# ODrive.Can.Error CAN_ERROR_NONE = 0x00000000 CAN_ERROR_DUPLICATE_CAN_IDS = 0x00000001