|
|
@ -57,6 +57,26 @@ ZCanPumpCtrlModule m_pumpCtrlModule; |
|
|
|
ZCanTrigleWarningLightCtlModule m_warningLightCtlModule; |
|
|
|
HuachengPressureSensor m_huachengPressureSensor; |
|
|
|
|
|
|
|
void setmotor(TMC5130 *motor, int16_t acc_rpm2, int16_t rpm, int16_t idlepower, int16_t power) { |
|
|
|
int32_t ppm = rpm / 60.0 * 51200; |
|
|
|
int32_t acc = acc_rpm2 / 60.0 * 51200; |
|
|
|
|
|
|
|
int16_t _idlepower = 1; |
|
|
|
int16_t _power = 31; |
|
|
|
|
|
|
|
if (idlepower > 0 && idlepower < 31) { |
|
|
|
_idlepower = idlepower; |
|
|
|
} |
|
|
|
if (power > 0 && power < 31) { |
|
|
|
_power = power; |
|
|
|
} |
|
|
|
|
|
|
|
motor->setIHOLD_IRUN(_idlepower, _power, 10); // 5W
|
|
|
|
motor->setAcceleration(acc); |
|
|
|
motor->setDeceleration(acc); |
|
|
|
motor->rotate(ppm); |
|
|
|
} |
|
|
|
|
|
|
|
void Main::onRceivePacket(CanPacketRxBuffer *rxbuf, uint8_t *packet, size_t len) { |
|
|
|
ZLOGI(TAG, "onRceivePacket from %d %d", rxbuf->id, len); |
|
|
|
for (size_t i = 0; i < len; i++) { |
|
|
@ -134,7 +154,7 @@ void Main::run() { |
|
|
|
m_motor1.initialize(&cfg); |
|
|
|
int32_t chipv = m_motor1.readChipVERSION(); |
|
|
|
ZLOGI(TAG, "m_motor1:%lx", chipv); |
|
|
|
m_motor1.setIHOLD_IRUN(1, 31, 0); |
|
|
|
m_motor1.setIHOLD_IRUN(1, 20, 0); |
|
|
|
m_motor1.setMotorShaft(true); |
|
|
|
|
|
|
|
m_motor1.setAcceleration(300000); |
|
|
@ -148,7 +168,7 @@ void Main::run() { |
|
|
|
m_motor2.initialize(&cfg); |
|
|
|
int32_t chipv = m_motor2.readChipVERSION(); |
|
|
|
ZLOGI(TAG, "m_motor2:%lx", chipv); |
|
|
|
m_motor2.setIHOLD_IRUN(1, 31, 0); |
|
|
|
m_motor2.setIHOLD_IRUN(1, 20, 0); // 5W
|
|
|
|
m_motor2.setMotorShaft(true); |
|
|
|
|
|
|
|
m_motor2.setAcceleration(300000); |
|
|
@ -157,21 +177,13 @@ void Main::run() { |
|
|
|
} |
|
|
|
|
|
|
|
m_pumpCtrlModule.initialize(&m_canReceiver); |
|
|
|
m_pumpCtrlModule.regSubmodule(1, [&](int16_t acc_rpm2, int16_t rpm) { |
|
|
|
m_pumpCtrlModule.regSubmodule(1, [&](int16_t acc_rpm2, int16_t rpm, int16_t idlepower, int16_t power) { |
|
|
|
ZLOGI(TAG, "pump1 acc_rpm2:%d rpm:%d", acc_rpm2, rpm); |
|
|
|
int32_t ppm = rpm / 60.0 * 51200; |
|
|
|
int32_t acc = acc_rpm2 / 60.0 * 51200; |
|
|
|
m_motor1.setAcceleration(acc); |
|
|
|
m_motor1.setDeceleration(acc); |
|
|
|
m_motor1.rotate(ppm); |
|
|
|
setmotor(&m_motor1, acc_rpm2, rpm, idlepower, power); |
|
|
|
}); |
|
|
|
m_pumpCtrlModule.regSubmodule(2, [&](int16_t acc_rpm2, int16_t rpm) { |
|
|
|
m_pumpCtrlModule.regSubmodule(2, [&](int16_t acc_rpm2, int16_t rpm, int16_t idlepower, int16_t power) { |
|
|
|
ZLOGI(TAG, "pump2 acc:%d rpm:%d", acc_rpm2, rpm); |
|
|
|
int32_t ppm = rpm / 60.0 * 51200; |
|
|
|
int32_t acc = acc_rpm2 / 60.0 * 51200; |
|
|
|
m_motor2.setAcceleration(acc); |
|
|
|
m_motor2.setDeceleration(acc); |
|
|
|
m_motor2.rotate(ppm); |
|
|
|
setmotor(&m_motor2, acc_rpm2, rpm, idlepower, power); |
|
|
|
}); |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|