Basebot modules: Difference between revisions

From Rsewiki
Line 16: Line 16:
  PWM = motorVoltage * MAX_PWM/(battery_voltage - voltageLoss)
  PWM = motorVoltage * MAX_PWM/(battery_voltage - voltageLoss)


The motor controller has a minimum pulse width. If the motor voltage is not zero, a minimum PWM is added to compensate.
The motor controller has a minimum pulse width. A minimum PWM is added to compensate if the motor voltage is not zero.
The minimum corresponds to 0.4V motor voltage.
The minimum corresponds to 0.4V motor voltage.


The motor current uses a HAL sensor ACS714; the zero is about 3.3V/2. Other nearby components may influence the values and should be used with caution.
The motor current uses a HAL sensor ACS714; the zero is about 3.3V/2. Other nearby components may influence the values and should be used with caution.


(implemented in ''umotor.cpp'' in function ''motorSetAnchorVoltage()'')
The encoder uses an interrupt for every value edge. The velocity is estimated based on the timing difference from the last sample period to the newest edge.
 
Encoder values are available as
 
encoder.encoder[0..1]  A, unsigned 32 bit, counter of all edges detected. Positive is counterclockwise.
encoder.motorVelocity[0..1] Motor velocity in radians per second. Positive is counterclockwise.
encoder.gear is the gearbox ratio (9.68)
encoder.pulsPerRev is the number of edges on a motor revolution (48)
 
If no edge is detected in a sample period, then the time since the last edge is used, but only if this time gives a slower estimate.
 
The motor action is implemented in ''src/umotor.cpp'' in function ''motorSetAnchorVoltage()''.
The encoder estimate is implementer in ''src/uencoder.cpp''.


==== Gyro and accelerometer ====
==== Gyro and accelerometer ====

Revision as of 10:40, 2 September 2024

Back to Basebot

Module description

Main code

Support modules

Motor

Motor voltage is translated to a PWM at 65kHz where the average value corresponds to the set motor voltage. Current battery voltage is taken into consideration.

PWM = motorVoltage * MAX_PWM/(battery_voltage - voltageLoss)

The motor controller has a minimum pulse width. A minimum PWM is added to compensate if the motor voltage is not zero. The minimum corresponds to 0.4V motor voltage.

The motor current uses a HAL sensor ACS714; the zero is about 3.3V/2. Other nearby components may influence the values and should be used with caution.

The encoder uses an interrupt for every value edge. The velocity is estimated based on the timing difference from the last sample period to the newest edge.

Encoder values are available as

encoder.encoder[0..1]  A, unsigned 32 bit, counter of all edges detected. Positive is counterclockwise.
encoder.motorVelocity[0..1] Motor velocity in radians per second. Positive is counterclockwise.
encoder.gear is the gearbox ratio (9.68)
encoder.pulsPerRev is the number of edges on a motor revolution (48)

If no edge is detected in a sample period, then the time since the last edge is used, but only if this time gives a slower estimate.

The motor action is implemented in src/umotor.cpp in function motorSetAnchorVoltage(). The encoder estimate is implementer in src/uencoder.cpp.

Gyro and accelerometer

The sensor chip is an MPU9250. Sensor values are extracted from the chip at every sample time, but if the sample time is faster than 1ms, values may be repeated.

The values are available as

imu2.gyro[0..2] for rotation velocity around axis x,y,z in degrees per second.
imu2.acc[0..2]  for acceleration along x,y,z. X is forward, Y is left, and Z is up.

(implemented in uimu2.cpp)