mm integration + Checkliste

This commit is contained in:
fewikay committed 2026-11-05 21:03:23 +01:00
1 parent 8ca3ce7f6a
commit f736da7a1d
3 files changed
+149 -30

No files matched your search

@@ -13,6 +13,10 @@
int state = 0;
int mm_to_step(float mm){
return (int)(800 * mm);
}
static void* StepLibraryMalloc( unsigned int size ){
return malloc(size);
}
@@ -94,7 +98,7 @@ int reset_stepper(L6474_Handle_t s){
L6474_BaseParameter_t b;
L6474_SetBaseParameter(&b);
b.stepMode = smMICRO4;
b.stepMode = smMICRO16;
b.OcdTh = ocdth1125mA;
L6474_EncodePhaseCurrentParameter(&b, 700.0f);
@@ -103,22 +107,25 @@ int reset_stepper(L6474_Handle_t s){
// reset all and take all initialization steps
result |= L6474_ResetStandBy(s);
result |= L6474_Initialize(s, &b);
result |= L6474_SetPowerOutputs(s, 1);
result |= L6474_SetPowerOutputs(s, 0);
return 0;
return result;
}
int stepper_reference(L6474_Handle_t s, int flag){
L6474_SetPowerOutputs(s, 1);
//flag: 0 keiner, 1 -t, 2 -e, 3 -s
if(HAL_GPIO_ReadPin(REFERENCE_MARK_GPIO_Port, REFERENCE_MARK_Pin) == GPIO_PIN_RESET){
L6474_StepIncremental(s, 1000);
L6474_StepIncremental(s, mm_to_step(5));
int button_pressed = 0;
while(!button_pressed){
L6474_StepIncremental(s, -1);
if(L6474_StepIncremental(s, -1) != errcNONE){
return 1;
}
if(HAL_GPIO_ReadPin(REFERENCE_MARK_GPIO_Port, REFERENCE_MARK_Pin) == GPIO_PIN_RESET){
button_pressed=1;
}
@@ -130,6 +137,11 @@ int stepper_reference(L6474_Handle_t s, int flag){
if(flag == 3){
L6474_SetAbsolutePosition(s, 0);
L6474_Status_t status;
if(L6474_GetStatus(s, &status) != errcNONE){
return 1;
}
return 0;
}
@@ -157,18 +169,17 @@ int stepper_pos(L6474_Handle_t s){
int position = 0;
L6474_GetAbsolutePosition(s, &position);
printf("Stepper position: %d", position);
return 0;
}
int stepper_status(L6474_Handle_t s){
L6474_Status_t status;
if(L6474_GetStatus(s, &status) != errcNONE){
return 1;
}
L6474_GetStatus(s, &status);
printf("Stepper status: ");
return 0;
}
int stepper_move(L6474_Handle_t s, int pos){
xTaskCreate(blink_yellow_led, "blink_yellow_led", 1024, NULL, 1, NULL);
int position = 0;
if(L6474_GetAbsolutePosition(s, &position) != errcNONE){
@@ -204,18 +215,20 @@ int StepperConsoleFunction( int argc, char** argv, void* ctx )
// first decode the subcommand and all arguments
if ( argc == 0 )
{
printf("invalid number of arguments\r\nFAIL");
printf("invalid number of arguments\r\n");
printf("FAIL\r\n");
return -1;
}
else if ( strcmp(argv[0], "step") == 0 )
{
if(state != 2){
printf("Please do reference\r\nFAIL");
printf("Please do reference\r\n");
printf("FAIL\r\n");
return -1;
}
if ( argc < 2 )
{
printf("missing step value for step command\r\nFAIL");
printf("missing step value for step commandFAIL\r\n");
return -1;
}
@@ -228,74 +241,83 @@ int StepperConsoleFunction( int argc, char** argv, void* ctx )
{
if(reset_stepper(h)){
state = 0;
printf("\r\nFAIL");
printf("FAIL\r\n");
return -1;
}
state = 1;
printf("\r\nOK");
printf("OK\r\n");
return 0;
}
else if ( strcmp(argv[0], "reference") == 0 )
{
if(state < 1){
printf("Please do reset\r\nFAIL");
printf("Please do reset\r\n");
printf("FAIL\r\n");
return -1;
}
if(stepper_reference(h, 0)){
state = 0;
printf("\r\nFAIL");
printf("FAIL\r\n");
return -1;
}
state = 2;
printf("\r\nOK");
printf("OK\r\n");
return 0;
}
else if ( strcmp(argv[0], "position") == 0 )
{
if(state != 2){
printf("Please do reference\r\nFAIL");
printf("Please do reference\r\n");
printf("FAIL\r\n");
return -1;
}
if(stepper_pos(h)){
state = 0;
printf("\r\nFAIL");
printf("FAIL\r\n");
return -1;
}
printf("\r\nOK");
printf("OK\r\n");
return 0;
}
else if ( strcmp(argv[0], "move") == 0 )
{
if(state != 2){
printf("Please do reference\r\nFAIL");
printf("Please do reference\r\n");
printf("FAIL\r\n");
return -1;
}
if ( argc < 2 )
{
printf("missing position value for move command\r\nFAIL");
printf("missing position value for move command\r\n");
printf("FAIL\r\n");
return -1;
}
if(atoi(argv[1]) < 0){
printf("position value for move command cant be below 0\r\nFAIL");
float target_mm = (float)atof(argv[1]);
if (target_mm < 0.0f || target_mm > 100.0f) {
printf("position out of range\r\n");
printf("FAIL\r\n");
return -1;
}
if(stepper_move(h, atoi(argv[1]))==1){
if(stepper_move(h, mm_to_step(target_mm))==1){
state = 0;
printf("\r\nFAIL");
printf("FAIL\r\n");
return -1;
}
printf("\r\nOK");
printf("OK\r\n");
return 0;
}
else
{
printf("passed invalid sub command\r\nFAIL");
printf("passed invalid sub command\r\n");
printf("FAIL\r\n");
return -1;
}