Skip to content

Commit acd4435

Browse files
committed
clang-formatで体裁を整える
1 parent acad98b commit acd4435

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+516
-458
lines changed

pico_classic_v4_STEP1_LED/pico_classic_v4_STEP1_LED.ino

100755100644
-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
1615
#define LED0 13
1716
#define LED1 14
1817
#define LED2 47

pico_classic_v4_STEP2_SWITCH/pico_classic_v4_STEP2_SWITCH.ino

100755100644
-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
1615
#define LED0 13
1716
#define LED1 14
1817
#define LED2 47
@@ -37,7 +36,6 @@ void setup()
3736
pinMode(SW_R, INPUT_PULLUP);
3837

3938
g_state_r = g_state_c = g_state_l = 0;
40-
4139
}
4240

4341
void loop()

pico_classic_v4_STEP3_Buzzer/pico_classic_v4_STEP3_Buzzer.ino

100755100644
-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
1615
#define LED0 13
1716
#define LED1 14
1817
#define LED2 47

pico_classic_v4_STEP4_Sensor/pico_classic_v4_STEP4_Sensor.ino

100755100644
+7-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
1615
#define SLED_FR 9
1716
#define SLED_FL 10
1817
#define SLED_R 11
@@ -30,10 +29,11 @@ volatile short g_sensor_value_r;
3029
volatile short g_sensor_value_l;
3130
volatile short g_battery_value;
3231

33-
hw_timer_t* g_timer1 = NULL;
32+
hw_timer_t * g_timer1 = NULL;
3433
portMUX_TYPE g_timer_mux = portMUX_INITIALIZER_UNLOCKED;
3534

36-
void IRAM_ATTR onTimer1(void) {
35+
void IRAM_ATTR onTimer1(void)
36+
{
3737
static char cnt = 0;
3838
portENTER_CRITICAL_ISR(&g_timer_mux);
3939
switch (cnt) {
@@ -79,7 +79,8 @@ void IRAM_ATTR onTimer1(void) {
7979
portEXIT_CRITICAL_ISR(&g_timer_mux);
8080
}
8181

82-
void setup() {
82+
void setup()
83+
{
8384
// put your setup code here, to run once:
8485
//Sensor 発光off
8586
pinMode(SLED_FR, OUTPUT);
@@ -99,7 +100,8 @@ void setup() {
99100
timerStart(g_timer1);
100101
}
101102

102-
void loop() {
103+
void loop()
104+
{
103105
// put your main code here, to run repeatedly:
104106
Serial.printf("r_sen is %d\n\r", g_sensor_value_r);
105107
Serial.printf("fr_sen is %d\n\r", g_sensor_value_fr);

pico_classic_v4_STEP5_Straight/TMC5240.h

+2-6
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,15 @@
104104
#define TMC5240_PULSE (TIRE_DIAMETER * PI / (200.0 * microstep))
105105
#define TMC5240_VELOCITY (TMC5240_PULSE * 0.787) //13200000/2/2^23=0.787 +50c
106106

107-
108-
class TMC5240 {
107+
class TMC5240
108+
{
109109
private:
110-
111110
public:
112111
unsigned int readXactual(void);
113112
void write(unsigned char add, unsigned int data_l, unsigned int data_r);
114113
void init(void);
115114
};
116115

117-
118116
extern TMC5240 g_tmc5240;
119117

120-
121-
122118
#endif // TMC5240_H_

pico_classic_v4_STEP5_Straight/TMC5240.ino

+28-16
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ TMC5240 g_tmc5240;
1717

1818
portMUX_TYPE timerMux2 = portMUX_INITIALIZER_UNLOCKED;
1919

20-
unsigned int TMC5240::readXactual(void) {
20+
unsigned int TMC5240::readXactual(void)
21+
{
2122
unsigned char spi_write_read_data[10];
2223

2324
unsigned int data_r, data_l;
@@ -47,7 +48,9 @@ unsigned int TMC5240::readXactual(void) {
4748
digitalWrite(SPI_CS_L, HIGH);
4849
SPI.endTransaction();
4950

50-
data_l = ((unsigned int)spi_write_read_data[1] << 24) | ((unsigned int)spi_write_read_data[2] << 16) | ((unsigned int)spi_write_read_data[3] << 8) | ((unsigned int)spi_write_read_data[4]);
51+
data_l = ((unsigned int)spi_write_read_data[1] << 24) |
52+
((unsigned int)spi_write_read_data[2] << 16) |
53+
((unsigned int)spi_write_read_data[3] << 8) | ((unsigned int)spi_write_read_data[4]);
5154

5255
for (int i = 0; i < 0xff; i++) {
5356
asm("nop \n");
@@ -78,13 +81,15 @@ unsigned int TMC5240::readXactual(void) {
7881
SPI.endTransaction();
7982
portEXIT_CRITICAL_ISR(&timerMux2);
8083

81-
data_r = ((unsigned int)spi_write_read_data[1] << 24) | ((unsigned int)spi_write_read_data[2] << 16) | ((unsigned int)spi_write_read_data[3] << 8) | ((unsigned int)spi_write_read_data[4]);
84+
data_r = ((unsigned int)spi_write_read_data[1] << 24) |
85+
((unsigned int)spi_write_read_data[2] << 16) |
86+
((unsigned int)spi_write_read_data[3] << 8) | ((unsigned int)spi_write_read_data[4]);
8287

8388
return (unsigned int)(abs((int)data_r) + abs((int)data_l));
8489
}
8590

86-
void TMC5240::write(unsigned char add, unsigned int data_l, unsigned int data_r) {
87-
91+
void TMC5240::write(unsigned char add, unsigned int data_l, unsigned int data_r)
92+
{
8893
unsigned char spi_write_data[10];
8994

9095
portENTER_CRITICAL_ISR(&timerMux2);
@@ -114,24 +119,31 @@ void TMC5240::write(unsigned char add, unsigned int data_l, unsigned int data_r)
114119
portEXIT_CRITICAL_ISR(&timerMux2);
115120
}
116121

117-
void TMC5240::init(void) {
122+
void TMC5240::init(void)
123+
{
118124
SPI.begin(SPI_CLK, SPI_MISO, SPI_MOSI);
119125

120-
pinMode(SPI_CS_L, OUTPUT); //left
126+
pinMode(SPI_CS_L, OUTPUT); //left
121127
pinMode(SPI_CS_R, OUTPUT); //right
122128
pinMode(SPI_CS_J, OUTPUT);
123129
digitalWrite(SPI_CS_L, HIGH);
124130
digitalWrite(SPI_CS_R, HIGH);
125131
digitalWrite(SPI_CS_J, HIGH);
126132

127-
g_tmc5240.write(TMC5240_DRV_CONF, 0x00000031, 0x00000031); //Current Range 2A 800V/us
128-
g_tmc5240.write(TMC5240_IHOLD_IRUN, 0x01041C03, 0x01041C03); //IHOLDDELAY=4 IRUN=28/32 IHOLD=3/32 2A設定時ピーク1.5A、実効値1.06A
129-
g_tmc5240.write(TMC5240_CHOPCONG, 0x04000001, 0x04000001); //MRES=0 1/16step TOFFTime=1 1以上でないとモータが動作しない
130-
g_tmc5240.write(TMC5240_PWMCONF, 0xC40E001D, 0xC40E001D); //PWM 48.8kHz
131-
g_tmc5240.write(TMC5240_RAMPMODE, 0x00000001, 0x00000001); //velocity mode(positive)
132-
g_tmc5240.write(TMC5240_GCONF, 0x00000000, 0x00000010); //右のみシャフトインバース
133-
g_tmc5240.write(TMC5240_AMAX, 0x3ffff, 0x3ffff); //加速度max 17..0 18bit
134-
g_tmc5240.write(TMC5240_XACTUAL, 0, 0); //初期化
135-
g_tmc5240.write(TMC5240_VSTART, (unsigned int)(MIN_SPEED / TMC5240_VELOCITY), (unsigned int)(MIN_SPEED / TMC5240_VELOCITY));
133+
g_tmc5240.write(TMC5240_DRV_CONF, 0x00000031, 0x00000031); //Current Range 2A 800V/us
134+
g_tmc5240.write(
135+
TMC5240_IHOLD_IRUN, 0x01041C03,
136+
0x01041C03); //IHOLDDELAY=4 IRUN=28/32 IHOLD=3/32 2A設定時ピーク1.5A、実効値1.06A
137+
g_tmc5240.write(
138+
TMC5240_CHOPCONG, 0x04000001,
139+
0x04000001); //MRES=0 1/16step TOFFTime=1 1以上でないとモータが動作しない
140+
g_tmc5240.write(TMC5240_PWMCONF, 0xC40E001D, 0xC40E001D); //PWM 48.8kHz
141+
g_tmc5240.write(TMC5240_RAMPMODE, 0x00000001, 0x00000001); //velocity mode(positive)
142+
g_tmc5240.write(TMC5240_GCONF, 0x00000000, 0x00000010); //右のみシャフトインバース
143+
g_tmc5240.write(TMC5240_AMAX, 0x3ffff, 0x3ffff); //加速度max 17..0 18bit
144+
g_tmc5240.write(TMC5240_XACTUAL, 0, 0); //初期化
145+
g_tmc5240.write(
146+
TMC5240_VSTART, (unsigned int)(MIN_SPEED / TMC5240_VELOCITY),
147+
(unsigned int)(MIN_SPEED / TMC5240_VELOCITY));
136148
g_tmc5240.write(TMC5240_VMAX, 0, 0);
137149
}

pico_classic_v4_STEP5_Straight/pico_classic_v4_STEP5_Straight.ino

100755100644
+8-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#define SPI_CLK 39
3131
#define SPI_MOSI 42
3232
#define SPI_MISO 41
33-
#define SPI_CS_L 40 //左モータ
33+
#define SPI_CS_L 40 //左モータ
3434
#define SPI_CS_R 3 //右モータ
3535
#define SPI_CS_J 46 //ジャイロ
3636

@@ -39,21 +39,21 @@
3939

4040
#define MIN_SPEED 30
4141

42-
hw_timer_t* g_timer0 = NULL;
42+
hw_timer_t * g_timer0 = NULL;
4343

4444
portMUX_TYPE g_timer_mux = portMUX_INITIALIZER_UNLOCKED;
4545

46-
4746
//割り込み
4847
//目標値の更新周期1kHz
49-
void IRAM_ATTR onTimer0(void) {
48+
void IRAM_ATTR onTimer0(void)
49+
{
5050
portENTER_CRITICAL_ISR(&g_timer_mux); //割り込み禁止
5151
controlInterrupt();
5252
portEXIT_CRITICAL_ISR(&g_timer_mux); //割り込み許可
5353
}
5454

55-
56-
void setup() {
55+
void setup()
56+
{
5757
// put your setup code here, to run once:
5858
pinMode(LED0, OUTPUT);
5959
pinMode(LED1, OUTPUT);
@@ -77,10 +77,10 @@ void setup() {
7777
delay(1);
7878
g_tmc5240.init();
7979
digitalWrite(MOTOR_EN, HIGH);
80-
8180
}
8281

83-
void loop() {
82+
void loop()
83+
{
8484
// put your main code here, to run repeatedly:
8585
while (digitalRead(SW_L) & digitalRead(SW_C) & digitalRead(SW_R)) {
8686
continue;

pico_classic_v4_STEP5_Straight/run.h

100755100644
+3-5
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@ typedef enum {
2020
MOT_BACK = 2
2121
} t_CW_CCW;
2222

23-
class RUN {
23+
class RUN
24+
{
2425
private:
25-
2626
public:
2727
volatile double accel;
2828
volatile double speed;
2929
volatile double max_speed;
3030
volatile double min_speed;
3131

32-
3332
RUN();
3433
void interrupt(void);
3534
void counterClear(void);
@@ -42,10 +41,9 @@ class RUN {
4241
void decelerate(int len, int init_speed);
4342

4443
private:
45-
int step_lr_len,step_lr;
44+
int step_lr_len, step_lr;
4645
};
4746

48-
4947
extern RUN g_run;
5048

5149
#endif /* SRC_RUN_H_ */

pico_classic_v4_STEP5_Straight/run.ino

100755100644
+28-22
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616

1717
RUN g_run;
1818

19-
RUN::RUN() {
19+
RUN::RUN()
20+
{
2021
speed = 0.0;
2122
accel = 0.0;
2223
}
2324

2425
//割り込み
25-
void controlInterrupt(void) {
26-
g_run.interrupt();
27-
}
26+
void controlInterrupt(void) { g_run.interrupt(); }
2827

29-
void RUN::interrupt(void) { //割り込み内からコール
28+
void RUN::interrupt(void)
29+
{ //割り込み内からコール
3030

3131
speed += accel;
3232

@@ -38,35 +38,37 @@ void RUN::interrupt(void) { //割り込み内からコール
3838
}
3939
}
4040

41-
void RUN::dirSet(t_CW_CCW dir_left, t_CW_CCW dir_right) {
41+
void RUN::dirSet(t_CW_CCW dir_left, t_CW_CCW dir_right)
42+
{
4243
g_tmc5240.write(TMC5240_RAMPMODE, dir_left, dir_right);
4344
}
4445

45-
void RUN::counterClear(void) {
46-
g_tmc5240.write(TMC5240_XACTUAL, 0, 0);
47-
}
46+
void RUN::counterClear(void) { g_tmc5240.write(TMC5240_XACTUAL, 0, 0); }
4847

49-
void RUN::speedSet(double l_speed, double r_speed) {
50-
g_tmc5240.write(TMC5240_VMAX, (unsigned int)(l_speed / TMC5240_VELOCITY), (unsigned int)(r_speed / TMC5240_VELOCITY));
48+
void RUN::speedSet(double l_speed, double r_speed)
49+
{
50+
g_tmc5240.write(
51+
TMC5240_VMAX, (unsigned int)(l_speed / TMC5240_VELOCITY),
52+
(unsigned int)(r_speed / TMC5240_VELOCITY));
5153
}
5254

53-
void RUN::stepGet(void) {
55+
void RUN::stepGet(void)
56+
{
5457
step_lr = g_tmc5240.readXactual();
5558
step_lr_len = (int)((float)step_lr / 2.0 * PULSE);
5659
}
5760

58-
void RUN::stop(void) {
59-
g_tmc5240.write(TMC5240_VMAX, 0, 0);
60-
}
61+
void RUN::stop(void) { g_tmc5240.write(TMC5240_VMAX, 0, 0); }
6162

62-
void RUN::accelerate(int len, int finish_speed) {
63+
void RUN::accelerate(int len, int finish_speed)
64+
{
6365
int obj_step;
6466

6567
accel = 1.5;
6668
speed = min_speed = MIN_SPEED;
6769
max_speed = finish_speed;
6870
counterClear();
69-
speedSet(MIN_SPEED,MIN_SPEED);
71+
speedSet(MIN_SPEED, MIN_SPEED);
7072
dirSet(MOT_FORWARD, MOT_FORWARD);
7173
obj_step = (int)((float)len * 2.0 / PULSE);
7274

@@ -79,14 +81,15 @@ void RUN::accelerate(int len, int finish_speed) {
7981
}
8082
}
8183

82-
void RUN::oneStep(int len, int init_speed) {
84+
void RUN::oneStep(int len, int init_speed)
85+
{
8386
int obj_step;
8487

8588
accel = 0.0;
8689
max_speed = init_speed;
8790
speed = min_speed = init_speed;
8891
counterClear();
89-
speedSet(init_speed,init_speed);
92+
speedSet(init_speed, init_speed);
9093
dirSet(MOT_FORWARD, MOT_FORWARD);
9194
obj_step = (int)((float)len * 2.0 / PULSE);
9295

@@ -99,21 +102,24 @@ void RUN::oneStep(int len, int init_speed) {
99102
}
100103
}
101104

102-
void RUN::decelerate(int len, int init_speed) {
105+
void RUN::decelerate(int len, int init_speed)
106+
{
103107
int obj_step;
104108

105109
accel = 1.5;
106110
max_speed = init_speed;
107111
speed = min_speed = init_speed;
108112
counterClear();
109-
speedSet(init_speed,init_speed);
113+
speedSet(init_speed, init_speed);
110114
dirSet(MOT_FORWARD, MOT_FORWARD);
111115
obj_step = (int)((float)len * 2.0 / PULSE);
112116

113117
while (1) {
114118
stepGet();
115119
speedSet(speed, speed);
116-
if ((int)(len - step_lr_len) < (int)(((speed * speed) - (MIN_SPEED * MIN_SPEED)) / (2.0 * 1000.0 * accel))) {
120+
if (
121+
(int)(len - step_lr_len) <
122+
(int)(((speed * speed) - (MIN_SPEED * MIN_SPEED)) / (2.0 * 1000.0 * accel))) {
117123
break;
118124
}
119125
}

pico_classic_v4_STEP6_rotate/TMC5240.h

+2-6
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,15 @@
104104
#define TMC5240_PULSE (TIRE_DIAMETER * PI / (200.0 * microstep))
105105
#define TMC5240_VELOCITY (TMC5240_PULSE * 0.787) //13200000/2/2^23=0.787 +50c
106106

107-
108-
class TMC5240 {
107+
class TMC5240
108+
{
109109
private:
110-
111110
public:
112111
unsigned int readXactual(void);
113112
void write(unsigned char add, unsigned int data_l, unsigned int data_r);
114113
void init(void);
115114
};
116115

117-
118116
extern TMC5240 g_tmc5240;
119117

120-
121-
122118
#endif // TMC5240_H_

0 commit comments

Comments
 (0)