Revision ed37d345
ID | ed37d34575cf1b74380aa5880a4f338d8ff11f1b |
Finished adding gpio control to motors node
I changed the Motor constructor to take pin numbers instead of file
names, and construct the file names itself. All that remains in testing.
scout/motors/src/motors.cpp | ||
---|---|---|
54 | 54 |
* |
55 | 55 |
* @param filename The name of the PWM device file |
56 | 56 |
*/ |
57 |
Motor::Motor(const char* pwmfile, const char* in1file, const char* in2file) |
|
58 |
: fpwm(pwmfile), fin1(in1file), fin2(in2file) |
|
57 |
Motor::Motor(int pwm_gpt, int in1_gpio, int in2_gpio) |
|
59 | 58 |
{ |
59 |
char buf[60]; |
|
60 | 60 |
int pwm, in1, in2; |
61 | 61 |
|
62 |
// open device files |
|
63 |
sprintf(buf, "/dev/pwm%d", pwm_gpt); |
|
64 |
fpwm.open(buf); |
|
65 |
sprintf(buf, "/sys/class/gpio/gpio%d/value", in1_gpio); |
|
66 |
fin1.open(buf); |
|
67 |
sprintf(buf, "/sys/class/gpio/gpio%d/value", in2_gpio); |
|
68 |
fin2.open(buf); |
|
69 |
|
|
62 | 70 |
// read current values from device files |
63 | 71 |
fpwm >> pwm; |
64 | 72 |
fin1 >> in1; |
... | ... | |
148 | 156 |
fin2 << in2; |
149 | 157 |
} |
150 | 158 |
|
151 |
/// @todo change these to the correct files |
|
152 |
/// @todo also, a problem: gpio can only be done as root! |
|
159 |
/// @todo change these to the correct motor locations |
|
153 | 160 |
// Motor state variables |
154 |
static Motor motor_fl("/dev/pwm8", "/dev/null", "/dev/null");
|
|
155 |
static Motor motor_fr("/dev/pwm9", "/dev/null", "/dev/null");
|
|
156 |
static Motor motor_bl("/dev/pwm10", "/dev/null", "/dev/null");
|
|
157 |
static Motor motor_br("/dev/pwm11", "/dev/null", "/dev/null");
|
|
161 |
static Motor motor_fl( 8, 70, 71);
|
|
162 |
static Motor motor_fr( 9, 72, 73);
|
|
163 |
static Motor motor_bl(11, 74, 75);
|
|
164 |
static Motor motor_br(10, 76, 77);
|
|
158 | 165 |
|
159 | 166 |
/** |
160 | 167 |
* @brief Sets motor speed |
scout/motors/src/motors.h | ||
---|---|---|
58 | 58 |
class Motor |
59 | 59 |
{ |
60 | 60 |
public: |
61 |
Motor(const char* pwmfile, const char* in1file, const char* in2file);
|
|
61 |
Motor(int pwm_gpt, int in1_gpio, int in2_gpio);
|
|
62 | 62 |
int get_speed(); |
63 | 63 |
void set_speed(int speed); |
64 | 64 |
private: |
Also available in: Unified diff