diff --git a/app/raspberry_pi/repository/packages/t/tb6612/tb6612/include/TB6612.h b/app/raspberry_pi/repository/packages/t/tb6612/tb6612/include/TB6612.h index 8a085374..4116e71b 100644 --- a/app/raspberry_pi/repository/packages/t/tb6612/tb6612/include/TB6612.h +++ b/app/raspberry_pi/repository/packages/t/tb6612/tb6612/include/TB6612.h @@ -21,12 +21,12 @@ class TB6612 void stop(); - void setOffset(int offset); + void setOffset(bool offset); private: int motor_pin; int pwm_pin; - int offset; + bool offset = true; }; #endif \ No newline at end of file diff --git a/app/raspberry_pi/repository/packages/t/tb6612/tb6612/src/TB6612.cpp b/app/raspberry_pi/repository/packages/t/tb6612/tb6612/src/TB6612.cpp index b350f437..3e34763f 100644 --- a/app/raspberry_pi/repository/packages/t/tb6612/tb6612/src/TB6612.cpp +++ b/app/raspberry_pi/repository/packages/t/tb6612/tb6612/src/TB6612.cpp @@ -2,12 +2,12 @@ // Made with the help of ChatGPT -TB6612::TB6612(int motor_pin, int pwm_pin) : motor_pin(motor_pin), pwm_pin(pwm_pin), offset(1) +TB6612::TB6612(int motor_pin, int pwm_pin) : motor_pin(motor_pin), pwm_pin(pwm_pin) { gpioSetMode(this->motor_pin, PI_OUTPUT); gpioSetMode(this->pwm_pin, PI_OUTPUT); - gpioWrite(this->motor_pin, 0); - gpioPWM(this->pwm_pin, 0); + // gpioWrite(this->motor_pin, 0); + // gpioPWM(this->pwm_pin, 0); } void TB6612::setPWM(int value) @@ -17,12 +17,12 @@ void TB6612::setPWM(int value) void TB6612::forward() { - gpioWrite(this->motor_pin, this->offset); + gpioWrite(this->motor_pin, 1); } void TB6612::backward() { - gpioWrite(this->motor_pin, 1 - this->offset); + gpioWrite(this->motor_pin, 0); } void TB6612::stop() @@ -31,7 +31,7 @@ void TB6612::stop() gpioPWM(this->pwm_pin, 0); } -void TB6612::setOffset(int offset) +void TB6612::setOffset(bool offset) { this->offset = offset; -} \ No newline at end of file +} diff --git a/app/raspberry_pi/tests/tb6612/test_rear_wheels.cpp b/app/raspberry_pi/tests/tb6612/test_rear_wheels.cpp index 03f7fa79..51e5d220 100644 --- a/app/raspberry_pi/tests/tb6612/test_rear_wheels.cpp +++ b/app/raspberry_pi/tests/tb6612/test_rear_wheels.cpp @@ -32,6 +32,10 @@ class BackWheels void forward() { + // this->pca9685.setPWM(Motor_A, 1); + // this->pca9685.setPWM(Motor_B, 1); + // gpioWrite(Motor_A, 1); + // gpioWrite(Motor_B, 1); this->left_wheel->forward(); this->right_wheel->forward(); std::cout << "Forward" << std::endl; @@ -39,6 +43,10 @@ class BackWheels void backward() { + // this->pca9685.setPWM(Motor_A, 0); + // this->pca9685.setPWM(Motor_B, 0); + // gpioWrite(Motor_A, 0); + // gpioWrite(Motor_B, 0); this->left_wheel->backward(); this->right_wheel->backward(); std::cout << "Backward" << std::endl; @@ -48,6 +56,7 @@ class BackWheels { this->left_wheel->stop(); this->right_wheel->stop(); + this->pca9685.reset(); std::cout << "Stop" << std::endl; } @@ -106,10 +115,10 @@ class BackWheels std::cout << "CaliOK" << std::endl; } + PCA9685 pca9685; private: std::unique_ptr left_wheel; std::unique_ptr right_wheel; - PCA9685 pca9685; int forward_A; int forward_B; int cali_forward_A;