Skip to content

Commit ac0b0bf

Browse files
committed
robot class
1 parent d618685 commit ac0b0bf

File tree

7 files changed

+91
-13
lines changed

7 files changed

+91
-13
lines changed

Arduino_Robot_Firmware.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,42 @@
99
#include "dcmotor.h"
1010
#include "motor_control.h"
1111

12+
class Arduino_Robot_Firmware{
13+
private:
14+
15+
public:
16+
RGBled * led1;
17+
RGBled * led2;
18+
DCmotor * motor_left;
19+
DCmotor * motor_right;
1220

1321

22+
Arduino_Robot_Firmware(){
23+
led1 = new RGBled(LED_1_RED,LED_1_GREEN,LED_1_BLUE);
24+
led2 = new RGBled(LED_2_RED,LED_2_GREEN,LED_2_BLUE);
25+
26+
motor_left = new DCmotor(MOTOR_LEFT_A,MOTOR_LEFT_A_CH, MOTOR_LEFT_B, MOTOR_LEFT_B_CH,true);
27+
motor_right = new DCmotor(MOTOR_RIGHT_A,MOTOR_RIGHT_A_CH,MOTOR_RIGHT_B,MOTOR_RIGHT_B_CH);
28+
29+
}
30+
31+
int begin(){
32+
// setup alternate functions
33+
AF_Tim2_pwm();
34+
AF_Tim5_pins_encoder();
35+
AF_Tim3_pins_encoder();
36+
37+
// turn off leds
38+
led1->clear();
39+
led2->clear();
40+
41+
motor_left->begin();
42+
motor_right->begin();
43+
motor_left->stop();
44+
motor_right->stop();
45+
46+
return 0;
47+
}
48+
};
49+
1450
#endif

examples/motor/motor.ino

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,36 @@
33
Encoder enc_right(TIM5);
44

55
DCmotor motor_right(MOTOR_RIGHT_A,MOTOR_RIGHT_A_CH,MOTOR_RIGHT_B,MOTOR_RIGHT_B_CH);
6+
DCmotor motor_left(MOTOR_LEFT_A,MOTOR_LEFT_A_CH, MOTOR_LEFT_B, MOTOR_LEFT_B_CH);
67

7-
MotorControl right(&motor_right,0,0,0);
8+
//MotorControl right(&motor_right,&enc_right,0,0,0);
89

910
void setup(){
10-
enc_right.begin();
1111
motor_right.begin();
12+
motor_left.begin();
1213
}
1314

1415
void loop(){
15-
right.test();
16+
for (int i=0; i<4096; i++){
17+
motor_right.setSpeed(i);
18+
motor_left.setSpeed(i);
19+
delay(1);
20+
}
21+
for (int i=4095; i>0; i--){
22+
motor_right.setSpeed(i);
23+
motor_left.setSpeed(i);
24+
delay(1);
25+
}
26+
delay(1000);
27+
for (int i=0; i<4096; i++){
28+
motor_right.setSpeed(i);
29+
motor_left.setSpeed(-i);
30+
delay(1);
31+
}
32+
for (int i=4095; i>0; i--){
33+
motor_right.setSpeed(i);
34+
motor_left.setSpeed(-i);
35+
delay(1);
36+
}
37+
delay(1000);
1638
}

examples/simple/simple.ino

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "Arduino_Robot_Firmware.h"
2+
3+
Arduino_Robot_Firmware robot;
4+
5+
void setup(){
6+
robot.begin();
7+
}
8+
9+
void loop(){
10+
robot.led1->setRed(1);
11+
delay(1000);
12+
robot.led1->setRed(0);
13+
delay(1000);
14+
}

examples/test/test.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "Arduino_Robot_Firmware.h"
22

33
Encoder enc_right(TIM5);
4-
//Encoder enc_left(TIM3);
4+
Encoder enc_left(TIM3);
55

66
DCmotor motor_right(MOTOR_RIGHT_A,MOTOR_RIGHT_A_CH,MOTOR_RIGHT_B,MOTOR_RIGHT_B_CH);
77
DCmotor motor_left(MOTOR_LEFT_A,MOTOR_LEFT_A_CH,MOTOR_LEFT_B,MOTOR_LEFT_B_CH);
@@ -14,10 +14,10 @@ void setup(){
1414
AF_Tim2_pwm();
1515
Serial.println("af5");
1616
AF_Tim5_pins_encoder();
17-
//AF_Tim3_pins_encoder();
17+
AF_Tim3_pins_encoder();
1818
Serial.println("encoder");
1919
enc_right.begin();
20-
//enc_left.begin();
20+
enc_left.begin();
2121
Serial.println("motor right");
2222
motor_right.begin();
2323
Serial.println("motor left");
@@ -30,7 +30,7 @@ void loop(){
3030
while(k<4096){
3131
Serial.print(enc_right.getCount());
3232
Serial.print(" ");
33-
//Serial.print(enc_left.getCount());
33+
Serial.print(enc_left.getCount());
3434
Serial.print(" ");
3535
Serial.print(k);
3636
Serial.print("\n");

motor_control.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class MotorControl{
2525
float ctrl_d;
2626
float actuation;
2727

28+
float prev_error;
29+
2830
DCmotor * motor;
2931
Encoder * encoder;
3032
public:

pinout_definitions.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33

44

55
// Right Motor
6-
#define ENC_RIGHT_TIMER TIM2
6+
#define ENC_RIGHT_TIMER TIM5
77
#define ENC_RIGHT_A PA0
88
#define ENC_RIGHT_B PA1
99
#define MOTOR_RIGHT_A PA2
1010
#define MOTOR_RIGHT_A_CH 3
11-
#define MOTOR_RIGHT_B PA3
12-
#define MOTOR_RIGHT_B_CH 4
11+
#define MOTOR_RIGHT_B PA15
12+
#define MOTOR_RIGHT_B_CH 1
13+
1314

1415
// Left Motor
1516
#define ENC_LEFT_TIMER TIM3
1617
#define ENC_LEFT_A PC6
1718
#define ENC_LEFT_B PC7
18-
#define MOTOR_LEFT_A PA15
19-
#define MOTOR_LEFT_A_CH 1
19+
#define MOTOR_LEFT_A PA3
20+
#define MOTOR_LEFT_A_CH 4
2021
#define MOTOR_LEFT_B PB3
2122
#define MOTOR_LEFT_B_CH 2
2223

@@ -34,5 +35,9 @@
3435
#define SERVO_A PC9
3536
#define SERVO_B PA8
3637

38+
// APDS9960
39+
#define LED_APDS PB6
40+
41+
3742

3843
#endif

rgb_led.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class RGBled{
1919
digitalWrite(R,LOW);
2020
digitalWrite(G,LOW);
2121
digitalWrite(B,LOW);
22-
2322
}
2423

2524
void setRed(const uint32_t red){

0 commit comments

Comments
 (0)