Skip to content

Commit

Permalink
Car can now move forwards
Browse files Browse the repository at this point in the history
  • Loading branch information
Chi-EEE committed Jan 10, 2024
1 parent c50e890 commit 35c7dd0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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;
}
}
11 changes: 10 additions & 1 deletion app/raspberry_pi/tests/tb6612/test_rear_wheels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,21 @@ 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;
}

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;
Expand All @@ -48,6 +56,7 @@ class BackWheels
{
this->left_wheel->stop();
this->right_wheel->stop();
this->pca9685.reset();
std::cout << "Stop" << std::endl;
}

Expand Down Expand Up @@ -106,10 +115,10 @@ class BackWheels
std::cout << "CaliOK" << std::endl;
}

PCA9685 pca9685;
private:
std::unique_ptr<TB6612> left_wheel;
std::unique_ptr<TB6612> right_wheel;
PCA9685 pca9685;
int forward_A;
int forward_B;
int cali_forward_A;
Expand Down

0 comments on commit 35c7dd0

Please sign in to comment.