Skip to content

Commit 78bcb16

Browse files
Motors fixed
Remade - ledcWrite to pin, not channel
1 parent 8c7478f commit 78bcb16

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

RoboHeart.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,7 @@
1111
"ROBOHEART" // Define identifier before including DebuggerMsgs.h
1212
#include "DebuggerMsgs.h"
1313

14-
// arduino-esp32 starts assigning channel from the top (channel 7)
15-
// lower the chances of collision by starting from the bottom
16-
// TODO: Remove on the new arduino-esp32 release
17-
#define MOTOR_A_CHANNEL1 0
18-
#define MOTOR_A_CHANNEL2 1
19-
#define MOTOR_B_CHANNEL1 2
20-
#define MOTOR_B_CHANNEL2 3
21-
#define MOTOR_C_CHANNEL1 4
22-
#define MOTOR_C_CHANNEL2 5
14+
2315

2416
LSM6DS3 RoboHeart::imu;
2517
float RoboHeart::_rotationX;

RoboHeart.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
#include <math.h>
2121
#define TRESHOLD 0.1 //treshold in degrees/s
2222

23+
#define MOTOR_A_CHANNEL1 0
24+
#define MOTOR_A_CHANNEL2 1
25+
#define MOTOR_B_CHANNEL1 2
26+
#define MOTOR_B_CHANNEL2 3
27+
#define MOTOR_C_CHANNEL1 4
28+
#define MOTOR_C_CHANNEL2 5
29+
2330
#define LSM6DS3_I2C_ADDR 0x6B // or 0x6A - Address is defined in Library
2431

2532
typedef struct {

RoboHeartDRV8836.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,37 +63,37 @@ void RoboHeartDRV8836::configPWM(int freq, int resolution) {
6363
void RoboHeartDRV8836::sleep(bool sleep) {
6464
RETURN_WARN_IF_EQUAL(_in1Pin, -1)
6565

66-
ledcWrite(_in1Channel, 0);
67-
ledcWrite(_in2Channel, 0);
66+
ledcWrite(_in1Pin, 0);
67+
ledcWrite(_in2Pin, 0);
6868
digitalWrite(_nSleepPin, !sleep);
6969
}
7070

7171
void RoboHeartDRV8836::coast() {
7272
RETURN_WARN_IF_EQUAL(_in1Pin, -1)
7373

74-
ledcWrite(_in1Channel, 0);
75-
ledcWrite(_in2Channel, 0);
74+
ledcWrite(_in1Pin, 0);
75+
ledcWrite(_in2Pin, 0);
7676
}
7777

7878
void RoboHeartDRV8836::forward(int speed) {
7979
RETURN_WARN_IF_EQUAL(_in1Pin, -1)
8080
_speed = clampSpeed(speed, 0, _pwmMaxDutyCycle);
81-
ledcWrite(_in1Channel, _speed);
82-
ledcWrite(_in2Channel, 0);
81+
ledcWrite(_in1Pin, _speed);
82+
ledcWrite(_in2Pin, 0);
8383
}
8484

8585
void RoboHeartDRV8836::reverse(int speed) {
8686
RETURN_WARN_IF_EQUAL(_in1Pin, -1)
8787
_speed = clampSpeed(speed, 0, _pwmMaxDutyCycle);
88-
ledcWrite(_in1Channel, 0);
89-
ledcWrite(_in2Channel, _speed);
88+
ledcWrite(_in1Pin, 0);
89+
ledcWrite(_in2Pin, _speed);
9090
}
9191

9292
void RoboHeartDRV8836::brake() {
9393
RETURN_WARN_IF_EQUAL(_in1Pin, -1)
9494

95-
ledcWrite(_in1Channel, _pwmMaxDutyCycle);
96-
ledcWrite(_in2Channel, _pwmMaxDutyCycle);
95+
ledcWrite(_in1Pin, _pwmMaxDutyCycle);
96+
ledcWrite(_in2Pin, _pwmMaxDutyCycle);
9797
}
9898

9999
int RoboHeartDRV8836::getSpeed() { return _speed; }

RoboHeartDRV8836.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class RoboHeartDRV8836 {
3737
int _pwmResolution = -1;
3838
int _pwmMaxDutyCycle = 256;
3939

40-
int _in1Channel = 0; // TODO: Remove on the new arduino-esp32 release
40+
int _in1Channel = 0;
4141
int _in2Channel = 1;
4242
};
4343

0 commit comments

Comments
 (0)