vex-ast 0.2.0__py3-none-any.whl → 0.2.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
vex_ast/__init__.py CHANGED
@@ -4,13 +4,25 @@ VEX AST Generator Package.
4
4
  Provides tools for parsing VEX V5 code and generating an Abstract Syntax Tree (AST).
5
5
  """
6
6
 
7
+ # Core functionality
7
8
  from .ast.core import Program
8
- from .ast.navigator import AstNavigator
9
9
  from .parser.python_parser import parse_string, parse_file
10
+
11
+ # AST Navigation
12
+ from .ast.navigator import AstNavigator, create_navigator
13
+
14
+ # Visitors
10
15
  from .visitors.printer import PrintVisitor
11
16
  from .visitors.analyzer import NodeCounter, VariableCollector
12
- from .utils.errors import ErrorHandler, ErrorType, VexSyntaxError
13
- from .registry import registry_api, initialize as initialize_registry
17
+
18
+ # Error handling
19
+ from .utils.errors import ErrorHandler, ErrorType, VexSyntaxError, VexAstError, Error
20
+
21
+ # Registry
22
+ from .registry.api import registry_api
23
+ from .registry import initialize
24
+
25
+ # Serialization
14
26
  from .serialization.json_serializer import serialize_ast_to_dict, serialize_ast_to_json
15
27
  from .serialization.json_deserializer import deserialize_ast_from_dict, deserialize_ast_from_json
16
28
  from .serialization.schema import generate_ast_schema, export_schema_to_file
@@ -18,18 +30,11 @@ from .serialization.schema import generate_ast_schema, export_schema_to_file
18
30
  __version__ = "0.2.0"
19
31
 
20
32
  # Initialize the registry with default functions
21
- initialize_registry()
22
-
23
- def create_navigator(ast: Program) -> AstNavigator:
24
- """Create an AST navigator for the given AST.
25
-
26
- Args:
27
- ast: The AST to navigate
28
-
29
- Returns:
30
- An AST navigator for traversing and querying the AST
31
- """
32
- return AstNavigator(ast)
33
+ try:
34
+ initialize()
35
+ print("VEX function registry initialized successfully")
36
+ except Exception as e:
37
+ print(f"Error initializing VEX function registry: {e}")
33
38
 
34
39
  __all__ = [
35
40
  # Core functionality
@@ -50,10 +55,12 @@ __all__ = [
50
55
  "ErrorHandler",
51
56
  "ErrorType",
52
57
  "VexSyntaxError",
58
+ "VexAstError",
59
+ "Error",
53
60
 
54
61
  # Registry
55
62
  "registry_api",
56
- "initialize_registry",
63
+ "initialize",
57
64
 
58
65
  # Serialization
59
66
  "serialize_ast_to_dict",
vex_ast/ast/__init__.py CHANGED
@@ -72,4 +72,4 @@ __all__ = [
72
72
 
73
73
  # Navigator
74
74
  'AstNavigator', 'create_navigator',
75
- ]
75
+ ]
vex_ast/ast/navigator.py CHANGED
@@ -211,3 +211,15 @@ class AstNavigator:
211
211
  if hasattr(access.object, 'name') and getattr(access.object, 'name') == object_name:
212
212
  result.append(access)
213
213
  return result
214
+
215
+
216
+ def create_navigator(ast_node: IAstNode) -> AstNavigator:
217
+ """Create a new AST navigator for the given AST node.
218
+
219
+ Args:
220
+ ast_node: The AST node to navigate
221
+
222
+ Returns:
223
+ A new AstNavigator instance
224
+ """
225
+ return AstNavigator(ast_node)
vex_ast/ast/validators.py CHANGED
@@ -81,11 +81,17 @@ class VexFunctionValidator(AstVisitor[List[Tuple[VexAPICall, str]]]):
81
81
  # Check if this is a method call on a known object type
82
82
  if '.' in function_name:
83
83
  obj_name, method_name = function_name.split('.', 1)
84
- # For method calls, we need to check if the method exists for any object type
85
- # since we don't know the actual type of the object at validation time
86
- # Just check if the method name exists in the registry API
84
+
85
+ # First check if the method exists in the registry
87
86
  if registry_api.get_function(method_name):
88
87
  is_vex_function = True
88
+ else:
89
+ # Try to check if it's a method on any known object type
90
+ from ..types.objects import MOTOR, TIMER, BRAIN, CONTROLLER
91
+ for obj_type in [MOTOR, TIMER, BRAIN, CONTROLLER]:
92
+ if registry_api.get_method(obj_type, method_name):
93
+ is_vex_function = True
94
+ break
89
95
  # Or check if it's a direct function
90
96
  elif registry_api.get_function(function_name):
91
97
  is_vex_function = True
vex_ast/ast/vex_nodes.py CHANGED
@@ -59,7 +59,20 @@ class VexAPICall(FunctionCall):
59
59
  if '.' in function_name:
60
60
  # For method calls like "motor1.spin", extract the method name
61
61
  obj_name, method_name = function_name.split('.', 1)
62
+
63
+ # First try to get the method signature directly
62
64
  self._signature = registry_api.get_function(method_name)
65
+
66
+ # If that fails, try to get it as a method of a specific object type
67
+ # This is a fallback since we don't know the actual type at parse time
68
+ if not self._signature:
69
+ # Try common object types
70
+ from ..types.objects import MOTOR, TIMER, BRAIN, CONTROLLER
71
+ for obj_type in [MOTOR, TIMER, BRAIN, CONTROLLER]:
72
+ method_sig = registry_api.get_method(obj_type, method_name)
73
+ if method_sig:
74
+ self._signature = method_sig
75
+ break
63
76
  else:
64
77
  # For direct function calls
65
78
  self._signature = registry_api.get_function(function_name)
@@ -205,7 +218,19 @@ def create_vex_api_call(function: IExpression, args: List[IExpression],
205
218
  if '.' in function_name:
206
219
  # For method calls like "motor1.spin", extract the method name
207
220
  obj_name, method_name = function_name.split('.', 1)
221
+
222
+ # First try to get the method signature directly
208
223
  signature = registry_api.get_function(method_name)
224
+
225
+ # If that fails, try to get it as a method of a specific object type
226
+ if not signature:
227
+ # Try common object types
228
+ from ..types.objects import MOTOR, TIMER, BRAIN, CONTROLLER
229
+ for obj_type in [MOTOR, TIMER, BRAIN, CONTROLLER]:
230
+ method_sig = registry_api.get_method(obj_type, method_name)
231
+ if method_sig:
232
+ signature = method_sig
233
+ break
209
234
  else:
210
235
  # For direct function calls
211
236
  signature = registry_api.get_function(function_name)
@@ -0,0 +1,27 @@
1
+ """
2
+ Parser package for VEX AST.
3
+
4
+ This package provides functionality for parsing VEX code into an Abstract Syntax Tree.
5
+ """
6
+
7
+ from .interfaces import (
8
+ IParser,
9
+ BaseParser
10
+ )
11
+ from .factory import NodeFactory, default_factory
12
+ from .python_parser import parse_string, parse_file, PythonParser
13
+
14
+ __all__ = [
15
+ # Interfaces
16
+ "IParser",
17
+ "BaseParser",
18
+
19
+ # Factory
20
+ "NodeFactory",
21
+ "default_factory",
22
+
23
+ # Python parser
24
+ "parse_string",
25
+ "parse_file",
26
+ "PythonParser"
27
+ ]
@@ -0,0 +1,11 @@
1
+ """
2
+ Registry functions package for VEX AST.
3
+
4
+ This package contains the function definitions for the VEX API registry.
5
+ """
6
+
7
+ from .initialize import initialize_registry
8
+
9
+ __all__ = [
10
+ "initialize_registry"
11
+ ]
@@ -0,0 +1,147 @@
1
+ from ..registry import registry
2
+ from ..signature import VexFunctionSignature, VexFunctionParameter, ParameterMode, SimulationCategory
3
+ from ...types.base import VOID, ANY
4
+ from ...types.primitives import INT, FLOAT, BOOL, STRING
5
+ from ...types.objects import BRAIN_SCREEN, CONTROLLER
6
+
7
+ def register_display_functions():
8
+ """Register display-related functions in the registry"""
9
+
10
+ # Brain screen functions
11
+
12
+ # Brain.Screen.print() method
13
+ print_params = [
14
+ VexFunctionParameter("text", ANY, description="Text to print")
15
+ ]
16
+
17
+ print_signature = VexFunctionSignature(
18
+ name="print",
19
+ return_type=VOID,
20
+ parameters=print_params,
21
+ description="Print text to the brain screen",
22
+ category=SimulationCategory.DISPLAY_OUTPUT,
23
+ python_name="print",
24
+ cpp_name="print",
25
+ object_type=BRAIN_SCREEN,
26
+ method_name="print"
27
+ )
28
+
29
+ registry.register_function(print_signature)
30
+
31
+ # Brain.Screen.clear_screen() method
32
+ clear_screen_signature = VexFunctionSignature(
33
+ name="clear_screen",
34
+ return_type=VOID,
35
+ parameters=[],
36
+ description="Clear the brain screen",
37
+ category=SimulationCategory.DISPLAY_OUTPUT,
38
+ python_name="clear_screen",
39
+ cpp_name="clearScreen",
40
+ object_type=BRAIN_SCREEN,
41
+ method_name="clear_screen"
42
+ )
43
+
44
+ registry.register_function(clear_screen_signature)
45
+
46
+ # Brain.Screen.set_cursor() method
47
+ set_cursor_params = [
48
+ VexFunctionParameter("row", INT, description="Row position"),
49
+ VexFunctionParameter("col", INT, description="Column position")
50
+ ]
51
+
52
+ set_cursor_signature = VexFunctionSignature(
53
+ name="set_cursor",
54
+ return_type=VOID,
55
+ parameters=set_cursor_params,
56
+ description="Set the cursor position on the brain screen",
57
+ category=SimulationCategory.DISPLAY_OUTPUT,
58
+ python_name="set_cursor",
59
+ cpp_name="setCursor",
60
+ object_type=BRAIN_SCREEN,
61
+ method_name="set_cursor"
62
+ )
63
+
64
+ registry.register_function(set_cursor_signature)
65
+
66
+ # Brain.Screen.draw_pixel() method
67
+ draw_pixel_params = [
68
+ VexFunctionParameter("x", INT, description="X coordinate"),
69
+ VexFunctionParameter("y", INT, description="Y coordinate")
70
+ ]
71
+
72
+ draw_pixel_signature = VexFunctionSignature(
73
+ name="draw_pixel",
74
+ return_type=VOID,
75
+ parameters=draw_pixel_params,
76
+ description="Draw a pixel on the brain screen",
77
+ category=SimulationCategory.DISPLAY_OUTPUT,
78
+ python_name="draw_pixel",
79
+ cpp_name="drawPixel",
80
+ object_type=BRAIN_SCREEN,
81
+ method_name="draw_pixel"
82
+ )
83
+
84
+ registry.register_function(draw_pixel_signature)
85
+
86
+ # Brain.Screen.draw_line() method
87
+ draw_line_params = [
88
+ VexFunctionParameter("x1", INT, description="Start X coordinate"),
89
+ VexFunctionParameter("y1", INT, description="Start Y coordinate"),
90
+ VexFunctionParameter("x2", INT, description="End X coordinate"),
91
+ VexFunctionParameter("y2", INT, description="End Y coordinate")
92
+ ]
93
+
94
+ draw_line_signature = VexFunctionSignature(
95
+ name="draw_line",
96
+ return_type=VOID,
97
+ parameters=draw_line_params,
98
+ description="Draw a line on the brain screen",
99
+ category=SimulationCategory.DISPLAY_OUTPUT,
100
+ python_name="draw_line",
101
+ cpp_name="drawLine",
102
+ object_type=BRAIN_SCREEN,
103
+ method_name="draw_line"
104
+ )
105
+
106
+ registry.register_function(draw_line_signature)
107
+
108
+ # Controller screen functions (V5 Controller)
109
+
110
+ # Controller.Screen.print() method
111
+ controller_print_params = [
112
+ VexFunctionParameter("text", ANY, description="Text to print")
113
+ ]
114
+
115
+ controller_print_signature = VexFunctionSignature(
116
+ name="print",
117
+ return_type=VOID,
118
+ parameters=controller_print_params,
119
+ description="Print text to the controller screen",
120
+ category=SimulationCategory.DISPLAY_OUTPUT,
121
+ python_name="print",
122
+ cpp_name="print",
123
+ object_type=CONTROLLER,
124
+ method_name="print"
125
+ )
126
+
127
+ registry.register_function(controller_print_signature)
128
+
129
+ # Controller.Screen.clear_screen() method
130
+ controller_clear_screen_signature = VexFunctionSignature(
131
+ name="clear_screen",
132
+ return_type=VOID,
133
+ parameters=[],
134
+ description="Clear the controller screen",
135
+ category=SimulationCategory.DISPLAY_OUTPUT,
136
+ python_name="clear_screen",
137
+ cpp_name="clearScreen",
138
+ object_type=CONTROLLER,
139
+ method_name="clear_screen"
140
+ )
141
+
142
+ registry.register_function(controller_clear_screen_signature)
143
+
144
+ # Add more display functions as needed...
145
+
146
+ if __name__ == "__main__":
147
+ register_display_functions()
@@ -0,0 +1,163 @@
1
+ from ..registry import registry
2
+ from ..signature import VexFunctionSignature, VexFunctionParameter, ParameterMode, SimulationCategory
3
+ from ...types.base import VOID
4
+ from ...types.primitives import INT, FLOAT, BOOL
5
+ from ...types.enums import DIRECTION_TYPE, TURN_TYPE, VELOCITY_UNITS, ROTATION_UNITS, DISTANCE_UNITS, BRAKE_TYPE
6
+ from ...types.objects import DRIVETRAIN
7
+
8
+ def register_drivetrain_functions():
9
+ """Register drivetrain-related functions in the registry"""
10
+
11
+ # Drivetrain.drive() method
12
+ drive_params = [
13
+ VexFunctionParameter("direction", DIRECTION_TYPE, description="Direction to drive"),
14
+ VexFunctionParameter("velocity", FLOAT, 50.0, description="Velocity to drive at"),
15
+ VexFunctionParameter("units", VELOCITY_UNITS, "RPM", description="Velocity units")
16
+ ]
17
+
18
+ drive_signature = VexFunctionSignature(
19
+ name="drive",
20
+ return_type=VOID,
21
+ parameters=drive_params,
22
+ description="Drive the drivetrain in the specified direction",
23
+ category=SimulationCategory.MOTOR_CONTROL,
24
+ python_name="drive",
25
+ cpp_name="drive",
26
+ object_type=DRIVETRAIN,
27
+ method_name="drive"
28
+ )
29
+
30
+ registry.register_function(drive_signature)
31
+
32
+ # Drivetrain.drive_for() method
33
+ drive_for_params = [
34
+ VexFunctionParameter("direction", DIRECTION_TYPE, description="Direction to drive"),
35
+ VexFunctionParameter("distance", FLOAT, description="Distance to drive"),
36
+ VexFunctionParameter("units", DISTANCE_UNITS, "INCHES", description="Distance units"),
37
+ VexFunctionParameter("velocity", FLOAT, 50.0, description="Velocity to drive at"),
38
+ VexFunctionParameter("units_v", VELOCITY_UNITS, "RPM", description="Velocity units"),
39
+ VexFunctionParameter("wait", BOOL, True, description="Whether to wait for completion")
40
+ ]
41
+
42
+ drive_for_signature = VexFunctionSignature(
43
+ name="drive_for",
44
+ return_type=VOID,
45
+ parameters=drive_for_params,
46
+ description="Drive the drivetrain for a specific distance",
47
+ category=SimulationCategory.MOTOR_CONTROL,
48
+ python_name="drive_for",
49
+ cpp_name="driveFor",
50
+ object_type=DRIVETRAIN,
51
+ method_name="drive_for"
52
+ )
53
+
54
+ registry.register_function(drive_for_signature)
55
+
56
+ # Drivetrain.turn() method
57
+ turn_params = [
58
+ VexFunctionParameter("direction", TURN_TYPE, description="Direction to turn"),
59
+ VexFunctionParameter("velocity", FLOAT, 50.0, description="Velocity to turn at"),
60
+ VexFunctionParameter("units", VELOCITY_UNITS, "RPM", description="Velocity units")
61
+ ]
62
+
63
+ turn_signature = VexFunctionSignature(
64
+ name="turn",
65
+ return_type=VOID,
66
+ parameters=turn_params,
67
+ description="Turn the drivetrain in the specified direction",
68
+ category=SimulationCategory.MOTOR_CONTROL,
69
+ python_name="turn",
70
+ cpp_name="turn",
71
+ object_type=DRIVETRAIN,
72
+ method_name="turn"
73
+ )
74
+
75
+ registry.register_function(turn_signature)
76
+
77
+ # Drivetrain.turn_for() method
78
+ turn_for_params = [
79
+ VexFunctionParameter("direction", TURN_TYPE, description="Direction to turn"),
80
+ VexFunctionParameter("angle", FLOAT, description="Angle to turn"),
81
+ VexFunctionParameter("units", ROTATION_UNITS, "DEGREES", description="Rotation units"),
82
+ VexFunctionParameter("velocity", FLOAT, 50.0, description="Velocity to turn at"),
83
+ VexFunctionParameter("units_v", VELOCITY_UNITS, "RPM", description="Velocity units"),
84
+ VexFunctionParameter("wait", BOOL, True, description="Whether to wait for completion")
85
+ ]
86
+
87
+ turn_for_signature = VexFunctionSignature(
88
+ name="turn_for",
89
+ return_type=VOID,
90
+ parameters=turn_for_params,
91
+ description="Turn the drivetrain for a specific angle",
92
+ category=SimulationCategory.MOTOR_CONTROL,
93
+ python_name="turn_for",
94
+ cpp_name="turnFor",
95
+ object_type=DRIVETRAIN,
96
+ method_name="turn_for"
97
+ )
98
+
99
+ registry.register_function(turn_for_signature)
100
+
101
+ # Drivetrain.stop() method
102
+ stop_params = [
103
+ VexFunctionParameter("mode", BRAKE_TYPE, "COAST", description="Stopping mode (coast, brake, hold)")
104
+ ]
105
+
106
+ stop_signature = VexFunctionSignature(
107
+ name="stop",
108
+ return_type=VOID,
109
+ parameters=stop_params,
110
+ description="Stop the drivetrain",
111
+ category=SimulationCategory.MOTOR_CONTROL,
112
+ python_name="stop",
113
+ cpp_name="stop",
114
+ object_type=DRIVETRAIN,
115
+ method_name="stop"
116
+ )
117
+
118
+ registry.register_function(stop_signature)
119
+
120
+ # Drivetrain.set_drive_velocity() method
121
+ set_drive_velocity_params = [
122
+ VexFunctionParameter("velocity", FLOAT, description="Velocity to set"),
123
+ VexFunctionParameter("units", VELOCITY_UNITS, "RPM", description="Velocity units")
124
+ ]
125
+
126
+ set_drive_velocity_signature = VexFunctionSignature(
127
+ name="set_drive_velocity",
128
+ return_type=VOID,
129
+ parameters=set_drive_velocity_params,
130
+ description="Set the drive velocity of the drivetrain",
131
+ category=SimulationCategory.MOTOR_CONTROL,
132
+ python_name="set_drive_velocity",
133
+ cpp_name="setDriveVelocity",
134
+ object_type=DRIVETRAIN,
135
+ method_name="set_drive_velocity"
136
+ )
137
+
138
+ registry.register_function(set_drive_velocity_signature)
139
+
140
+ # Drivetrain.set_turn_velocity() method
141
+ set_turn_velocity_params = [
142
+ VexFunctionParameter("velocity", FLOAT, description="Velocity to set"),
143
+ VexFunctionParameter("units", VELOCITY_UNITS, "RPM", description="Velocity units")
144
+ ]
145
+
146
+ set_turn_velocity_signature = VexFunctionSignature(
147
+ name="set_turn_velocity",
148
+ return_type=VOID,
149
+ parameters=set_turn_velocity_params,
150
+ description="Set the turn velocity of the drivetrain",
151
+ category=SimulationCategory.MOTOR_CONTROL,
152
+ python_name="set_turn_velocity",
153
+ cpp_name="setTurnVelocity",
154
+ object_type=DRIVETRAIN,
155
+ method_name="set_turn_velocity"
156
+ )
157
+
158
+ registry.register_function(set_turn_velocity_signature)
159
+
160
+ # Add more drivetrain functions as needed...
161
+
162
+ if __name__ == "__main__":
163
+ register_drivetrain_functions()
@@ -0,0 +1,28 @@
1
+ """Initialize all VEX function definitions in the registry"""
2
+
3
+ from . import motor, drivetrain, sensors, timing, display
4
+ # Import other function modules as they are added
5
+
6
+ def initialize_registry():
7
+ """Initialize the registry with all VEX functions"""
8
+ # Motor functions
9
+ motor.register_motor_functions()
10
+
11
+ # Drivetrain functions
12
+ drivetrain.register_drivetrain_functions()
13
+
14
+ # Sensor functions
15
+ sensors.register_sensor_functions()
16
+
17
+ # Timing functions
18
+ timing.register_timing_functions()
19
+
20
+ # Display functions
21
+ display.register_display_functions()
22
+
23
+ # Add other function registration calls as modules are added
24
+
25
+ print("VEX function registry initialized successfully")
26
+
27
+ if __name__ == "__main__":
28
+ initialize_registry()
@@ -0,0 +1,140 @@
1
+ from ..registry import registry
2
+ from ..signature import VexFunctionSignature, VexFunctionParameter, ParameterMode, SimulationCategory
3
+ from ...types.base import VOID
4
+ from ...types.primitives import INT, FLOAT, BOOL
5
+ from ...types.enums import DIRECTION_TYPE, VELOCITY_UNITS, ROTATION_UNITS, BRAKE_TYPE
6
+ from ...types.objects import MOTOR
7
+
8
+ def register_motor_functions():
9
+ """Register motor-related functions in the registry"""
10
+
11
+ # Motor.spin() method
12
+ spin_params = [
13
+ VexFunctionParameter("direction", DIRECTION_TYPE, description="Direction to spin the motor"),
14
+ VexFunctionParameter("velocity", FLOAT, 50.0, description="Velocity to spin at"),
15
+ VexFunctionParameter("units", VELOCITY_UNITS, "RPM", description="Velocity units")
16
+ ]
17
+
18
+ spin_signature = VexFunctionSignature(
19
+ name="spin",
20
+ return_type=VOID,
21
+ parameters=spin_params,
22
+ description="Spin the motor in the specified direction",
23
+ category=SimulationCategory.MOTOR_CONTROL,
24
+ python_name="spin",
25
+ cpp_name="spin",
26
+ object_type=MOTOR,
27
+ method_name="spin"
28
+ )
29
+
30
+ registry.register_function(spin_signature)
31
+
32
+ # Motor.stop() method
33
+ stop_params = [
34
+ VexFunctionParameter("mode", BRAKE_TYPE, "COAST", description="Stopping mode (coast, brake, hold)")
35
+ ]
36
+
37
+ stop_signature = VexFunctionSignature(
38
+ name="stop",
39
+ return_type=VOID,
40
+ parameters=stop_params,
41
+ description="Stop the motor",
42
+ category=SimulationCategory.MOTOR_CONTROL,
43
+ python_name="stop",
44
+ cpp_name="stop",
45
+ object_type=MOTOR,
46
+ method_name="stop"
47
+ )
48
+
49
+ registry.register_function(stop_signature)
50
+
51
+ # Motor.spin_to_position() method
52
+ spin_to_position_params = [
53
+ VexFunctionParameter("position", FLOAT, description="Position to spin to"),
54
+ VexFunctionParameter("units", ROTATION_UNITS, "DEGREES", description="Rotation units"),
55
+ VexFunctionParameter("velocity", FLOAT, 50.0, description="Velocity to spin at"),
56
+ VexFunctionParameter("units_v", VELOCITY_UNITS, "RPM", description="Velocity units"),
57
+ VexFunctionParameter("wait", BOOL, True, description="Whether to wait for completion")
58
+ ]
59
+
60
+ spin_to_position_signature = VexFunctionSignature(
61
+ name="spin_to_position",
62
+ return_type=VOID,
63
+ parameters=spin_to_position_params,
64
+ description="Spin the motor to an absolute position",
65
+ category=SimulationCategory.MOTOR_CONTROL,
66
+ python_name="spin_to_position",
67
+ cpp_name="spinToPosition",
68
+ object_type=MOTOR,
69
+ method_name="spin_to_position"
70
+ )
71
+
72
+ registry.register_function(spin_to_position_signature)
73
+
74
+ # Motor.spin_for() method
75
+ spin_for_params = [
76
+ VexFunctionParameter("direction", DIRECTION_TYPE, description="Direction to spin"),
77
+ VexFunctionParameter("amount", FLOAT, description="Amount to spin"),
78
+ VexFunctionParameter("units", ROTATION_UNITS, "DEGREES", description="Rotation units"),
79
+ VexFunctionParameter("velocity", FLOAT, 50.0, description="Velocity to spin at"),
80
+ VexFunctionParameter("units_v", VELOCITY_UNITS, "RPM", description="Velocity units"),
81
+ VexFunctionParameter("wait", BOOL, True, description="Whether to wait for completion")
82
+ ]
83
+
84
+ spin_for_signature = VexFunctionSignature(
85
+ name="spin_for",
86
+ return_type=VOID,
87
+ parameters=spin_for_params,
88
+ description="Spin the motor for a relative amount",
89
+ category=SimulationCategory.MOTOR_CONTROL,
90
+ python_name="spin_for",
91
+ cpp_name="spinFor",
92
+ object_type=MOTOR,
93
+ method_name="spin_for"
94
+ )
95
+
96
+ registry.register_function(spin_for_signature)
97
+
98
+ # Motor.set_velocity() method
99
+ set_velocity_params = [
100
+ VexFunctionParameter("velocity", FLOAT, description="Velocity to set"),
101
+ VexFunctionParameter("units", VELOCITY_UNITS, "RPM", description="Velocity units")
102
+ ]
103
+
104
+ set_velocity_signature = VexFunctionSignature(
105
+ name="set_velocity",
106
+ return_type=VOID,
107
+ parameters=set_velocity_params,
108
+ description="Set the velocity of the motor",
109
+ category=SimulationCategory.MOTOR_CONTROL,
110
+ python_name="set_velocity",
111
+ cpp_name="setVelocity",
112
+ object_type=MOTOR,
113
+ method_name="set_velocity"
114
+ )
115
+
116
+ registry.register_function(set_velocity_signature)
117
+
118
+ # Motor.set_stopping() method
119
+ set_stopping_params = [
120
+ VexFunctionParameter("mode", BRAKE_TYPE, description="Stopping mode (coast, brake, hold)")
121
+ ]
122
+
123
+ set_stopping_signature = VexFunctionSignature(
124
+ name="set_stopping",
125
+ return_type=VOID,
126
+ parameters=set_stopping_params,
127
+ description="Set the stopping mode of the motor",
128
+ category=SimulationCategory.MOTOR_CONTROL,
129
+ python_name="set_stopping",
130
+ cpp_name="setStopping",
131
+ object_type=MOTOR,
132
+ method_name="set_stopping"
133
+ )
134
+
135
+ registry.register_function(set_stopping_signature)
136
+
137
+ # Add more motor functions as needed...
138
+
139
+ if __name__ == "__main__":
140
+ register_motor_functions()