@@ -1152,6 +1152,66 @@ Motor_run_for_degrees(PyObject *self, PyObject *args, PyObject *kwds)
1152
1152
}
1153
1153
1154
1154
1155
+ static PyObject *
1156
+ Motor_run_for_rotations (PyObject * self , PyObject * args , PyObject * kwds )
1157
+ {
1158
+ MotorObject * motor = (MotorObject * )self ;
1159
+ static char * kwlist [] = {
1160
+ "rotations" , "speed" , "max_power" , "stop" ,
1161
+ "acceleration" , "deceleration" , "stall" ,
1162
+ "blocking" , NULL
1163
+ };
1164
+ int32_t rotations ;
1165
+ int32_t speed ;
1166
+ uint32_t power = motor -> default_max_power ;
1167
+ uint32_t accel = motor -> default_acceleration ;
1168
+ uint32_t decel = motor -> default_deceleration ;
1169
+ int stall = motor -> default_stall ;
1170
+ uint32_t stop = MOTOR_STOP_USE_DEFAULT ;
1171
+ uint8_t use_profile = 0 ;
1172
+ int parsed_stop ;
1173
+ int blocking = 1 ;
1174
+
1175
+ if (motor -> is_detached )
1176
+ {
1177
+ PyErr_SetString (cmd_get_exception (), "Motor is detached" );
1178
+ return NULL ;
1179
+ }
1180
+
1181
+ if (PyArg_ParseTupleAndKeywords (args , kwds ,
1182
+ "ii|IIIIpp:run_for_rotations" , kwlist ,
1183
+ & rotations , & speed , & power , & stop ,
1184
+ & accel , & decel , & stall , & blocking ) == 0 )
1185
+ return NULL ;
1186
+
1187
+ if (device_ensure_mode_info (motor -> device ) < 0 )
1188
+ return NULL ;
1189
+
1190
+ speed = CLIP (speed , SPEED_MIN , SPEED_MAX );
1191
+ power = CLIP (power , POWER_MIN , POWER_MAX );
1192
+ accel = CLIP (accel , ACCEL_MIN , ACCEL_MAX );
1193
+ decel = CLIP (decel , DECEL_MIN , DECEL_MAX );
1194
+ if ((parsed_stop = parse_stop (motor , stop )) < 0 )
1195
+ {
1196
+ PyErr_Format (PyExc_ValueError , "Invalid stop state: %d" , stop );
1197
+ return NULL ;
1198
+ }
1199
+
1200
+ if (set_acceleration (motor , accel , & use_profile ) < 0 ||
1201
+ set_deceleration (motor , decel , & use_profile ) < 0 ||
1202
+ set_stall (motor , stall ) < 0 )
1203
+ return NULL ;
1204
+
1205
+ if (cmd_start_speed_for_degrees (port_get_id (motor -> port ),
1206
+ rotations * 360 , speed , power ,
1207
+ (uint8_t )parsed_stop , use_profile ,
1208
+ blocking ) < 0 )
1209
+ return NULL ;
1210
+
1211
+ Py_RETURN_NONE ;
1212
+ }
1213
+
1214
+
1155
1215
static PyObject *
1156
1216
Motor_run_to_position (PyObject * self , PyObject * args , PyObject * kwds )
1157
1217
{
@@ -1352,6 +1412,11 @@ static PyMethodDef Motor_methods[] = {
1352
1412
METH_VARARGS | METH_KEYWORDS ,
1353
1413
"Run the motor for the given angle"
1354
1414
},
1415
+ {
1416
+ "run_for_rotations" , (PyCFunction )Motor_run_for_rotations ,
1417
+ METH_VARARGS | METH_KEYWORDS ,
1418
+ "Run the motor for rotations"
1419
+ },
1355
1420
{
1356
1421
"run_to_position" , (PyCFunction )Motor_run_to_position ,
1357
1422
METH_VARARGS | METH_KEYWORDS ,
0 commit comments