Skip to content

Commit be8b721

Browse files
aoki-rtShotaAk
andauthored
STEP/DIR add at STEP8 (#3)
* STEP/DIR add at STEP8 * Refactoring to pass clang-format check --------- Co-authored-by: ShotaAk <s.aoki@rt-net.jp>
1 parent 594018b commit be8b721

File tree

7 files changed

+516
-143
lines changed

7 files changed

+516
-143
lines changed

TMC5072_STEP8_micromouse/TMC5072.ino

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
int shadowRegister[0x80] = {0};
2121

22+
t_TMC5072Mode g_TMC5072_mode;
23+
24+
t_TMC5072Mode getTMC5072Mode(void) { return g_TMC5072_mode; }
25+
2226
unsigned int TMC5072Read_no_status(unsigned char add)
2327
{
2428
unsigned char data[5];
@@ -110,6 +114,7 @@ void TMC5072Write(unsigned char add, unsigned int writedata)
110114

111115
void TMC5072Setting(t_TMC5072Mode mode)
112116
{
117+
g_TMC5072_mode = mode;
113118
switch (mode) {
114119
case STEPDIR: //Ramp Generator velocity-modeに近い使い方
115120
TMC5072Write(TMC5072_IHOLD_IRUN1, 0x00071703); //IHOLDDELAY=7 IRUN=17/32 IHOLD=3/32

TMC5072_STEP8_micromouse/TMC5072_STEP8_micromouse.ino

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ void execByMode(int mode)
7676

7777
switch (mode) {
7878
case 1: //左手法
79+
TMC5072Setting(VELOCITY);
7980
searchLefthand();
8081
break;
8182
case 2: //足立法
83+
TMC5072Setting(VELOCITY);
8284
g_map_control.positionInit();
8385
searchAdachi(g_map_control.getGoalX(), g_map_control.getGoalY());
8486
rotate(right, 2);
@@ -92,6 +94,7 @@ void execByMode(int mode)
9294
mapWrite();
9395
break;
9496
case 3: //最短走行
97+
TMC5072Setting(VELOCITY);
9598
copyMap();
9699
g_map_control.positionInit();
97100
fastRun(g_map_control.getGoalX(), g_map_control.getGoalY());
@@ -105,10 +108,36 @@ void execByMode(int mode)
105108
g_map_control.nextDir(right);
106109
break;
107110
case 4:
111+
TMC5072Setting(STEPDIR);
112+
searchLefthand();
108113
break;
109-
case 5:
114+
case 5: //足立法
115+
TMC5072Setting(STEPDIR);
116+
g_map_control.positionInit();
117+
searchAdachi(g_map_control.getGoalX(), g_map_control.getGoalY());
118+
rotate(right, 2);
119+
g_map_control.nextDir(right);
120+
g_map_control.nextDir(right);
121+
goalAppeal();
122+
searchAdachi(0, 0);
123+
rotate(right, 2);
124+
g_map_control.nextDir(right);
125+
g_map_control.nextDir(right);
126+
mapWrite();
110127
break;
111-
case 6:
128+
case 6: //最短走行
129+
TMC5072Setting(STEPDIR);
130+
copyMap();
131+
g_map_control.positionInit();
132+
fastRun(g_map_control.getGoalX(), g_map_control.getGoalY());
133+
rotate(right, 2);
134+
g_map_control.nextDir(right);
135+
g_map_control.nextDir(right);
136+
goalAppeal();
137+
fastRun(0, 0);
138+
rotate(right, 2);
139+
g_map_control.nextDir(right);
140+
g_map_control.nextDir(right);
112141
break;
113142
case 7:
114143
break;

TMC5072_STEP8_micromouse/TMCL.ino

Lines changed: 139 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -15,175 +15,173 @@
1515
#include "TMC5072.h"
1616
#include "stdio.h"
1717

18+
// clang-format off
19+
1820
// these addresses are fixed
19-
#define SERIAL_MODULE_ADDRESS 1
20-
#define SERIAL_HOST_ADDRESS 2
21+
#define SERIAL_MODULE_ADDRESS 1
22+
#define SERIAL_HOST_ADDRESS 2
2123

2224
const int BUILD_VERSION = 30824;
23-
const char * VersionString = "0016V308";
24-
#define ID_TMC5072 7
25+
const char *VersionString = "0016V308";
26+
#define ID_TMC5072 7
2527
#define TMC_ADDRESS_MASK 0x7F
2628
#define TMC_ADDRESS(x) ((x) & (TMC_ADDRESS_MASK))
27-
#define CAST_Sn_TO_S32(value, n) \
28-
((value) | (((value) & ((uint32_t)1 << ((n)-1))) ? ~(((uint32_t)1 << (n)) - 1) : 0))
29+
#define CAST_Sn_TO_S32(value, n) ((value) | (((value) & ((uint32_t)1<<((n)-1)))? ~(((uint32_t)1<<(n))-1) : 0 ))
2930

3031
// id detection state definitions
31-
#define ID_STATE_WAIT_LOW 0 // id detection waiting for first edge (currently low)
32-
#define ID_STATE_WAIT_HIGH 1 // id detection waiting for second edge (currently high)
33-
#define ID_STATE_DONE 2 // id detection finished successfully
34-
#define ID_STATE_INVALID \
35-
3 // id detection failed - we got an answer, but no corresponding ID (invalid ID pulse length)
36-
#define ID_STATE_NO_ANSWER 4 // id detection failed - board doesn't answer
37-
#define ID_STATE_TIMEOUT 5 // id detection failed - board id pulse went high but not low
38-
#define ID_STATE_NOT_IN_FW \
39-
6 // id detection detected a valid id that is not supported in this firmware
32+
#define ID_STATE_WAIT_LOW 0 // id detection waiting for first edge (currently low)
33+
#define ID_STATE_WAIT_HIGH 1 // id detection waiting for second edge (currently high)
34+
#define ID_STATE_DONE 2 // id detection finished successfully
35+
#define ID_STATE_INVALID 3 // id detection failed - we got an answer, but no corresponding ID (invalid ID pulse length)
36+
#define ID_STATE_NO_ANSWER 4 // id detection failed - board doesn't answer
37+
#define ID_STATE_TIMEOUT 5 // id detection failed - board id pulse went high but not low
38+
#define ID_STATE_NOT_IN_FW 6 // id detection detected a valid id that is not supported in this firmware
4039

4140
// todo CHECK 2: these are unused - delete? (LH) #11
4241
// tmcl interpreter states
43-
#define TM_IDLE 0
44-
#define TM_RUN 1
45-
#define TM_STEP 2
46-
#define TM_RESET 3 // unused
47-
#define TM_DOWNLOAD 4
48-
#define TM_DEBUG 5 // wie TM_IDLE, es wird jedoch der Akku nicht modifiziert bei GAP etc.
42+
#define TM_IDLE 0
43+
#define TM_RUN 1
44+
#define TM_STEP 2
45+
#define TM_RESET 3 // unused
46+
#define TM_DOWNLOAD 4
47+
#define TM_DEBUG 5 // wie TM_IDLE, es wird jedoch der Akku nicht modifiziert bei GAP etc.
4948

5049
// todo CHECK 2: these are unused - delete? (LH) #12
51-
#define TCS_IDLE 0
52-
#define TCS_CAN7 1
53-
#define TCS_CAN8 2
54-
#define TCS_UART 3
55-
#define TCS_UART_ERROR 4
56-
#define TCS_UART_II 5
57-
#define TCS_UART_II_ERROR 6
58-
#define TCS_USB 7
59-
#define TCS_USB_ERROR 8
60-
#define TCS_MEM 9
50+
#define TCS_IDLE 0
51+
#define TCS_CAN7 1
52+
#define TCS_CAN8 2
53+
#define TCS_UART 3
54+
#define TCS_UART_ERROR 4
55+
#define TCS_UART_II 5
56+
#define TCS_UART_II_ERROR 6
57+
#define TCS_USB 7
58+
#define TCS_USB_ERROR 8
59+
#define TCS_MEM 9
6160

6261
// TMCL commands
63-
#define TMCL_ROR 1
64-
#define TMCL_ROL 2
65-
#define TMCL_MST 3
66-
#define TMCL_MVP 4
67-
#define TMCL_SAP 5
68-
#define TMCL_GAP 6
69-
#define TMCL_STAP 7
70-
#define TMCL_RSAP 8
71-
#define TMCL_SGP 9
72-
#define TMCL_GGP 10
73-
#define TMCL_STGP 11
74-
#define TMCL_RSGP 12
75-
#define TMCL_RFS 13
76-
#define TMCL_SIO 14
77-
#define TMCL_GIO 15
78-
#define TMCL_CALC 19
79-
#define TMCL_COMP 20
80-
#define TMCL_JC 21
81-
#define TMCL_JA 22
82-
#define TMCL_CSUB 23
83-
#define TMCL_RSUB 24
84-
#define TMCL_EI 25
85-
#define TMCL_DI 26
86-
#define TMCL_WAIT 27
87-
#define TMCL_STOP 28
88-
#define TMCL_SAC 29
89-
#define TMCL_SCO 30
90-
#define TMCL_GCO 31
91-
#define TMCL_CCO 32
92-
#define TMCL_CALCX 33
93-
#define TMCL_AAP 34
94-
#define TMCL_AGP 35
95-
#define TMCL_CLE 36
96-
#define TMCL_VECT 37
97-
#define TMCL_RETI 38
98-
#define TMCL_ACO 39
62+
#define TMCL_ROR 1
63+
#define TMCL_ROL 2
64+
#define TMCL_MST 3
65+
#define TMCL_MVP 4
66+
#define TMCL_SAP 5
67+
#define TMCL_GAP 6
68+
#define TMCL_STAP 7
69+
#define TMCL_RSAP 8
70+
#define TMCL_SGP 9
71+
#define TMCL_GGP 10
72+
#define TMCL_STGP 11
73+
#define TMCL_RSGP 12
74+
#define TMCL_RFS 13
75+
#define TMCL_SIO 14
76+
#define TMCL_GIO 15
77+
#define TMCL_CALC 19
78+
#define TMCL_COMP 20
79+
#define TMCL_JC 21
80+
#define TMCL_JA 22
81+
#define TMCL_CSUB 23
82+
#define TMCL_RSUB 24
83+
#define TMCL_EI 25
84+
#define TMCL_DI 26
85+
#define TMCL_WAIT 27
86+
#define TMCL_STOP 28
87+
#define TMCL_SAC 29
88+
#define TMCL_SCO 30
89+
#define TMCL_GCO 31
90+
#define TMCL_CCO 32
91+
#define TMCL_CALCX 33
92+
#define TMCL_AAP 34
93+
#define TMCL_AGP 35
94+
#define TMCL_CLE 36
95+
#define TMCL_VECT 37
96+
#define TMCL_RETI 38
97+
#define TMCL_ACO 39
9998

100-
#define TMCL_UF0 64
101-
#define TMCL_UF1 65
102-
#define TMCL_UF2 66
103-
#define TMCL_UF3 67
104-
#define TMCL_UF4 68
105-
#define TMCL_UF5 69
106-
#define TMCL_UF6 70
107-
#define TMCL_UF7 71
108-
#define TMCL_UF8 72
99+
#define TMCL_UF0 64
100+
#define TMCL_UF1 65
101+
#define TMCL_UF2 66
102+
#define TMCL_UF3 67
103+
#define TMCL_UF4 68
104+
#define TMCL_UF5 69
105+
#define TMCL_UF6 70
106+
#define TMCL_UF7 71
107+
#define TMCL_UF8 72
109108

110-
#define TMCL_ApplStop 128
111-
#define TMCL_ApplRun 129
112-
#define TMCL_ApplStep 130
113-
#define TMCL_ApplReset 131
114-
#define TMCL_DownloadStart 132
115-
#define TMCL_DownloadEnd 133
116-
#define TMCL_ReadMem 134
117-
#define TMCL_GetStatus 135
118-
#define TMCL_GetVersion 136
119-
#define TMCL_FactoryDefault 137
120-
#define TMCL_SetEvent 138
121-
#define TMCL_SetASCII 139
122-
#define TMCL_SecurityCode 140
123-
#define TMCL_Breakpoint 141
124-
#define TMCL_RamDebug 142
125-
#define TMCL_GetIds 143
126-
#define TMCL_UF_CH1 144
127-
#define TMCL_UF_CH2 145
128-
#define TMCL_writeRegisterChannel_1 146
129-
#define TMCL_writeRegisterChannel_2 147
130-
#define TMCL_readRegisterChannel_1 148
131-
#define TMCL_readRegisterChannel_2 149
109+
#define TMCL_ApplStop 128
110+
#define TMCL_ApplRun 129
111+
#define TMCL_ApplStep 130
112+
#define TMCL_ApplReset 131
113+
#define TMCL_DownloadStart 132
114+
#define TMCL_DownloadEnd 133
115+
#define TMCL_ReadMem 134
116+
#define TMCL_GetStatus 135
117+
#define TMCL_GetVersion 136
118+
#define TMCL_FactoryDefault 137
119+
#define TMCL_SetEvent 138
120+
#define TMCL_SetASCII 139
121+
#define TMCL_SecurityCode 140
122+
#define TMCL_Breakpoint 141
123+
#define TMCL_RamDebug 142
124+
#define TMCL_GetIds 143
125+
#define TMCL_UF_CH1 144
126+
#define TMCL_UF_CH2 145
127+
#define TMCL_writeRegisterChannel_1 146
128+
#define TMCL_writeRegisterChannel_2 147
129+
#define TMCL_readRegisterChannel_1 148
130+
#define TMCL_readRegisterChannel_2 149
132131

133-
#define TMCL_BoardMeasuredSpeed 150
134-
#define TMCL_BoardError 151
135-
#define TMCL_BoardReset 152
132+
#define TMCL_BoardMeasuredSpeed 150
133+
#define TMCL_BoardError 151
134+
#define TMCL_BoardReset 152
136135

137-
#define TMCL_WLAN 160
138-
#define TMCL_WLAN_CMD 160
139-
#define TMCL_WLAN_IS_RTS 161
140-
#define TMCL_WLAN_CMDMODE_EN 162
141-
#define TMCL_WLAN_IS_CMDMODE 163
136+
#define TMCL_WLAN 160
137+
#define TMCL_WLAN_CMD 160
138+
#define TMCL_WLAN_IS_RTS 161
139+
#define TMCL_WLAN_CMDMODE_EN 162
140+
#define TMCL_WLAN_IS_CMDMODE 163
142141

143-
#define TMCL_MIN 170
144-
#define TMCL_MAX 171
145-
#define TMCL_OTP 172
142+
#define TMCL_MIN 170
143+
#define TMCL_MAX 171
144+
#define TMCL_OTP 172
146145

147-
#define TMCL_Boot 242
148-
#define TMCL_SoftwareReset 255
146+
#define TMCL_Boot 242
147+
#define TMCL_SoftwareReset 255
149148

150149
// Command type variants
151-
#define MVP_ABS 0
152-
#define MVP_REL 1
153-
#define MVP_PRF 2
150+
#define MVP_ABS 0
151+
#define MVP_REL 1
152+
#define MVP_PRF 2
154153

155154
// GetVersion() Format types
156-
#define VERSION_FORMAT_ASCII 0
157-
#define VERSION_FORMAT_BINARY 1
158-
#define VERSION_BOOTLOADER \
159-
2 // todo CHECK 2: implemented this way in IDE - probably means getting the bootloader version. Not implemented in firmware (LH)
160-
#define VERSION_SIGNATURE \
161-
3 // todo CHECK 2: implemented under "Signature" in IDE. Not sure what to return for that. Not implemented in firmware (LH)
162-
#define VERSION_BOARD_DETECT_SRC \
163-
4 // todo CHECK 2: This doesn't really fit under GetVersion, but its implemented there in the IDE - change or leave this way? (LH)
164-
#define VERSION_BUILD 5
155+
#define VERSION_FORMAT_ASCII 0
156+
#define VERSION_FORMAT_BINARY 1
157+
#define VERSION_BOOTLOADER 2 // todo CHECK 2: implemented this way in IDE - probably means getting the bootloader version. Not implemented in firmware (LH)
158+
#define VERSION_SIGNATURE 3 // todo CHECK 2: implemented under "Signature" in IDE. Not sure what to return for that. Not implemented in firmware (LH)
159+
#define VERSION_BOARD_DETECT_SRC 4 // todo CHECK 2: This doesn't really fit under GetVersion, but its implemented there in the IDE - change or leave this way? (LH)
160+
#define VERSION_BUILD 5
165161

166162
//Statuscodes
167-
#define REPLY_OK 100
168-
#define REPLY_CMD_LOADED 101
169-
#define REPLY_CHKERR 1
170-
#define REPLY_INVALID_CMD 2
171-
#define REPLY_INVALID_TYPE 3
172-
#define REPLY_INVALID_VALUE 4
173-
#define REPLY_EEPROM_LOCKED 5
174-
#define REPLY_CMD_NOT_AVAILABLE 6
175-
#define REPLY_CMD_LOAD_ERROR 7
176-
#define REPLY_WRITE_PROTECTED 8
177-
#define REPLY_MAX_EXCEEDED 9
178-
#define REPLY_DOWNLOAD_NOT_POSSIBLE 10
179-
#define REPLY_CHIP_READ_FAILED 11
180-
#define REPLY_DELAYED 128
181-
#define REPLY_ACTIVE_COMM 129
163+
#define REPLY_OK 100
164+
#define REPLY_CMD_LOADED 101
165+
#define REPLY_CHKERR 1
166+
#define REPLY_INVALID_CMD 2
167+
#define REPLY_INVALID_TYPE 3
168+
#define REPLY_INVALID_VALUE 4
169+
#define REPLY_EEPROM_LOCKED 5
170+
#define REPLY_CMD_NOT_AVAILABLE 6
171+
#define REPLY_CMD_LOAD_ERROR 7
172+
#define REPLY_WRITE_PROTECTED 8
173+
#define REPLY_MAX_EXCEEDED 9
174+
#define REPLY_DOWNLOAD_NOT_POSSIBLE 10
175+
#define REPLY_CHIP_READ_FAILED 11
176+
#define REPLY_DELAYED 128
177+
#define REPLY_ACTIVE_COMM 129
182178

183179
// TMCL communication status
184-
#define TMCL_RX_ERROR_NONE 0
185-
#define TMCL_RX_ERROR_NODATA 1
186-
#define TMCL_RX_ERROR_CHECKSUM 2
180+
#define TMCL_RX_ERROR_NONE 0
181+
#define TMCL_RX_ERROR_NODATA 1
182+
#define TMCL_RX_ERROR_CHECKSUM 2
183+
184+
// clang-format on
187185

188186
uint32_t vmax_position[2];
189187

0 commit comments

Comments
 (0)