2222
2323static pbio_dcmotor_t dcmotors [PBDRV_CONFIG_NUM_MOTOR_CONTROLLER ];
2424
25- // Stop all motors and their parent objects.
25+ /**
26+ * Stops all motors and all higher level parent objects that use them.
27+ *
28+ * @param [in] clear_parents Whether to not only stop the parent object
29+ * physically, but also clear the dcmotor's
30+ * knowledge about that object. Choosing true frees
31+ * up all motors to be used again by new parent
32+ * objects.
33+ */
2634void pbio_dcmotor_stop_all (bool clear_parents ) {
2735
2836 // Go through all ports.
@@ -119,25 +127,63 @@ pbio_error_t pbio_dcmotor_get_dcmotor(pbio_port_id_t port, pbio_dcmotor_t **dcmo
119127 return PBIO_SUCCESS ;
120128}
121129
130+ /**
131+ * Gets the actuation type that is currently being applied to the motor.
132+ *
133+ * @param [in] dcmotor The dcmotor instance.
134+ * @param [out] actuation Actuation type, ::PBIO_DCMOTOR_ACTUATION_COAST
135+ * or ::PBIO_DCMOTOR_ACTUATION_VOLTAGE.
136+ * @param [out] voltage_now Voltage in mV if @ actuation is voltage. Else 0.
137+ */
122138void pbio_dcmotor_get_state (pbio_dcmotor_t * dcmotor , pbio_dcmotor_actuation_t * actuation , int32_t * voltage_now ) {
123139 * actuation = dcmotor -> actuation_now ;
124140 * voltage_now = dcmotor -> voltage_now ;
125141}
126142
143+ /**
144+ * Gets the maximum allowed voltage for a motor.
145+ *
146+ * @param [in] id Device type id.
147+ * @return Maximum voltage (mV) for the given motor type.
148+ */
127149int32_t pbio_dcmotor_get_max_voltage (pbio_iodev_type_id_t id ) {
128150 if (id == PBIO_IODEV_TYPE_ID_SPIKE_S_MOTOR ) {
129151 return 6000 ;
130152 }
131153 return 9000 ;
132154}
133155
156+ /**
157+ * Coasts the dc motor.
158+ *
159+ * This just sets the physical state and does not stop parent objects. It
160+ * should only be used by higher level objects. Users should use
161+ * ::pbio_dcmotor_user_command instead.
162+ *
163+ * @param [in] dcmotor The motor instance.
164+ * @return Error code.
165+ */
134166pbio_error_t pbio_dcmotor_coast (pbio_dcmotor_t * dcmotor ) {
135167 // Stop the motor and set the passivity state value for data logging.
136168 dcmotor -> actuation_now = PBIO_DCMOTOR_ACTUATION_COAST ;
137169 dcmotor -> voltage_now = 0 ;
138170 return pbdrv_motor_driver_coast (dcmotor -> motor_driver );
139171}
140172
173+ /**
174+ * Sets the dc motor voltage.
175+ *
176+ * A positive voltage will cause a rotation in the direction configured in
177+ * ::pbio_dcmotor_setup. A negative voltage makes it turn in the other way.
178+ *
179+ * This just sets the physical state and does not stop parent objects. It
180+ * should only be used by higher level objects. Users should use
181+ * ::pbio_dcmotor_user_command instead.
182+ *
183+ * @param [in] dcmotor The motor instance.
184+ * @param [in] voltage The voltage in mV.
185+ * @return Error code.
186+ */
141187pbio_error_t pbio_dcmotor_set_voltage (pbio_dcmotor_t * dcmotor , int32_t voltage ) {
142188 // Cap voltage at the configured limit.
143189 if (voltage > dcmotor -> max_voltage ) {
@@ -167,6 +213,18 @@ pbio_error_t pbio_dcmotor_set_voltage(pbio_dcmotor_t *dcmotor, int32_t voltage)
167213 return PBIO_SUCCESS ;
168214}
169215
216+ /**
217+ * Sets a voltage or coasts the motor, and stops higher level objects.
218+ *
219+ * A positive voltage will cause a rotation in the direction configured in
220+ * ::pbio_dcmotor_setup. A negative voltage makes it turn in the other way.
221+ *
222+ * @param [in] dcmotor The motor instance.
223+ * @param [in] coast If true, the motor coasts. If false, applies the
224+ * given voltage.
225+ * @param [in] voltage The voltage in mV.
226+ * @return Error code.
227+ */
170228pbio_error_t pbio_dcmotor_user_command (pbio_dcmotor_t * dcmotor , bool coast , int32_t voltage ) {
171229 // Stop parent object that uses this motor, if any.
172230 pbio_error_t err = pbio_parent_stop (& dcmotor -> parent , false);
@@ -181,11 +239,23 @@ pbio_error_t pbio_dcmotor_user_command(pbio_dcmotor_t *dcmotor, bool coast, int3
181239 return pbio_dcmotor_set_voltage (dcmotor , voltage );
182240}
183241
184-
242+ /**
243+ * Gets the settings for this motor.
244+ *
245+ * @param [in] dcmotor The motor instance.
246+ * @param [out] max_voltage The configured maximum voltage for this motor.
247+ */
185248void pbio_dcmotor_get_settings (pbio_dcmotor_t * dcmotor , int32_t * max_voltage ) {
186249 * max_voltage = dcmotor -> max_voltage ;
187250}
188251
252+ /**
253+ * Sets the settings for this motor.
254+ *
255+ * @param [in] dcmotor The motor instance.
256+ * @param [in] max_voltage Maximum voltage (mV) for this motor.
257+ * @return Error code.
258+ */
189259pbio_error_t pbio_dcmotor_set_settings (pbio_dcmotor_t * dcmotor , int32_t max_voltage ) {
190260
191261 // Get the device type.
0 commit comments