Uppfærði kóðann til að virkja Fault takka
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
// Sett á 1 til að prenta CSV (time_ms,ref_rpm,actual_rpm,pwm) í Operational,
|
// Sett á 1 til að prenta CSV (time_ms,ref_rpm,actual_rpm,pwm) í Operational,
|
||||||
// t.d. fyrir step og load response. Einnig hægt með build_flags = -D LOG_CSV=1
|
// t.d. fyrir step og load response. Einnig hægt með build_flags = -D LOG_CSV=1
|
||||||
#ifndef LOG_CSV
|
#ifndef LOG_CSV
|
||||||
#define LOG_CSV 0
|
#define LOG_CSV 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+28
-6
@@ -45,6 +45,9 @@ static const struct gpio_dt_spec bin2 =
|
|||||||
static const struct gpio_dt_spec motor_flt =
|
static const struct gpio_dt_spec motor_flt =
|
||||||
GPIO_DT_SPEC_GET(DT_ALIAS(motor_flt), gpios);
|
GPIO_DT_SPEC_GET(DT_ALIAS(motor_flt), gpios);
|
||||||
|
|
||||||
|
static const struct gpio_dt_spec fault_test_button =
|
||||||
|
GPIO_DT_SPEC_GET(DT_ALIAS(fault_test_button), gpios);
|
||||||
|
|
||||||
static const struct gpio_dt_spec motor_slp =
|
static const struct gpio_dt_spec motor_slp =
|
||||||
GPIO_DT_SPEC_GET(DT_ALIAS(motor_slp), gpios);
|
GPIO_DT_SPEC_GET(DT_ALIAS(motor_slp), gpios);
|
||||||
|
|
||||||
@@ -87,12 +90,14 @@ void MotorDriver::begin()
|
|||||||
if (!pwm_is_ready_dt(&bin1_pwm) ||
|
if (!pwm_is_ready_dt(&bin1_pwm) ||
|
||||||
!gpio_is_ready_dt(&bin2) ||
|
!gpio_is_ready_dt(&bin2) ||
|
||||||
!gpio_is_ready_dt(&motor_flt) ||
|
!gpio_is_ready_dt(&motor_flt) ||
|
||||||
|
!gpio_is_ready_dt(&fault_test_button) ||
|
||||||
!gpio_is_ready_dt(&motor_slp)) {
|
!gpio_is_ready_dt(&motor_slp)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gpio_pin_configure_dt(&bin2, GPIO_OUTPUT_INACTIVE) < 0 ||
|
if (gpio_pin_configure_dt(&bin2, GPIO_OUTPUT_INACTIVE) < 0 ||
|
||||||
gpio_pin_configure_dt(&motor_flt, GPIO_INPUT) < 0 ||
|
gpio_pin_configure_dt(&motor_flt, GPIO_INPUT) < 0 ||
|
||||||
|
gpio_pin_configure_dt(&fault_test_button, GPIO_INPUT) < 0 ||
|
||||||
gpio_pin_configure_dt(&motor_slp, GPIO_OUTPUT_INACTIVE) < 0) {
|
gpio_pin_configure_dt(&motor_slp, GPIO_OUTPUT_INACTIVE) < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -206,16 +211,33 @@ void MotorDriver::set(double pwm)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// bool MotorDriver::fault_active()
|
||||||
|
// {
|
||||||
|
// //return !(PIND & (1 << PIND4));
|
||||||
|
|
||||||
|
// if (!initialized) {
|
||||||
|
// return true; // Fail safe if the driver did not initialize.
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // The overlay marks FLT as active low. gpio_pin_get_dt() returns
|
||||||
|
// // the logical active state, so 1 means a fault is active.
|
||||||
|
// const int fault = gpio_pin_get_dt(&motor_flt);
|
||||||
|
// return fault < 0 || fault != 0;
|
||||||
|
// }
|
||||||
|
|
||||||
bool MotorDriver::fault_active()
|
bool MotorDriver::fault_active()
|
||||||
{
|
{
|
||||||
//return !(PIND & (1 << PIND4));
|
|
||||||
|
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
return true; // Fail safe if the driver did not initialize.
|
return true; // Fail safe if the driver did not initialize.
|
||||||
}
|
}
|
||||||
|
|
||||||
// The overlay marks FLT as active low. gpio_pin_get_dt() returns
|
const int driver_fault = gpio_pin_get_dt(&motor_flt);
|
||||||
// the logical active state, so 1 means a fault is active.
|
const int button_fault = gpio_pin_get_dt(&fault_test_button);
|
||||||
const int fault = gpio_pin_get_dt(&motor_flt);
|
|
||||||
return fault < 0 || fault != 0;
|
// Negative values indicate a GPIO read error, so treat them as a fault.
|
||||||
|
// With GPIO_ACTIVE_LOW, a pressed button reads as logical 1.
|
||||||
|
return driver_fault < 0 ||
|
||||||
|
button_fault < 0 ||
|
||||||
|
driver_fault != 0 ||
|
||||||
|
button_fault != 0;
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
motor-bin2 = &motor_bin2;
|
motor-bin2 = &motor_bin2;
|
||||||
motor-flt = &motor_flt;
|
motor-flt = &motor_flt;
|
||||||
motor-slp = &motor_slp;
|
motor-slp = &motor_slp;
|
||||||
|
fault-test-button = &fault_test_button;
|
||||||
};
|
};
|
||||||
|
|
||||||
buttons {
|
buttons {
|
||||||
@@ -29,6 +30,11 @@
|
|||||||
gpios = <&gpioa 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; /* A0, PA0 */
|
gpios = <&gpioa 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; /* A0, PA0 */
|
||||||
label = "Motor fault";
|
label = "Motor fault";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
fault_test_button: fault_test_button {
|
||||||
|
gpios = <&gpiob 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; /* D3, PB0 */
|
||||||
|
label = "Fault test button";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
motor_gpio_outputs {
|
motor_gpio_outputs {
|
||||||
|
|||||||
Reference in New Issue
Block a user