-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
112 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 27 additions & 30 deletions
57
app/raspberry_pi/repository/packages/t/tb6612/tb6612/src/TB6612.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,35 @@ | ||
#include "TB6612.h" | ||
|
||
namespace tb6612 | ||
Motor::Motor(const int &direction_channel, const int &pwn, const bool &offset, const int &frequency) | ||
: direction_channel(direction_channel), | ||
pwm(pwm), | ||
offset(offset), | ||
forward_offset(offset), | ||
backward_offset(!offset), | ||
frequency(frequency) | ||
{ | ||
Motor::Motor(const int &direction_channel, const int &pwn, const bool &offset, const int &frequency) | ||
: direction_channel(direction_channel), | ||
pwm(pwm), | ||
offset(offset), | ||
forward_offset(offset), | ||
backward_offset(!offset), | ||
frequency(frequency) | ||
{ | ||
gpioSetMode(direction_channel, PI_OUTPUT); | ||
} | ||
gpioSetMode(direction_channel, PI_OUTPUT); | ||
} | ||
|
||
Motor::setSpeed(int speed) | ||
{ | ||
this->speed = speed; | ||
gpioHardwarePWM(pwm, 1000, speed); | ||
} | ||
Motor::setSpeed(int speed) | ||
{ | ||
this->speed = speed; | ||
gpioHardwarePWM(pwm, 1000, speed); | ||
} | ||
|
||
void Motor::forward() | ||
{ | ||
gpioWrite(direction_channel, forward_offset); | ||
this->status = FORWARD; | ||
} | ||
void Motor::forward() | ||
{ | ||
gpioWrite(direction_channel, forward_offset); | ||
this->status = FORWARD; | ||
} | ||
|
||
void Motor::backward() | ||
{ | ||
gpioWrite(direction_channel, backward_offset); | ||
this->status = BACKWARD; | ||
} | ||
void Motor::backward() | ||
{ | ||
gpioWrite(direction_channel, backward_offset); | ||
this->status = BACKWARD; | ||
} | ||
|
||
void Motor::stop() | ||
{ | ||
this->setSpeed(0); | ||
} | ||
void Motor::stop() | ||
{ | ||
this->setSpeed(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters