fixed slow movement of splitflaps,

integrated Move all Splitflaps to zero position into multi-splitflap.c,
added SetHardwareIdentifier methods
main
Jonas Arnold 4 years ago
parent f0b7a19d2b
commit adeece8201
  1. 19
      ADIS_tinyK22_SplitFlap/source/application.c
  2. 68
      ADIS_tinyK22_SplitFlap/source/multi-splitflap.c
  3. 9
      ADIS_tinyK22_SplitFlap/source/multi-splitflap.h
  4. 2
      ADIS_tinyK22_SplitFlap/source/platform.h
  5. 8
      ADIS_tinyK22_SplitFlap/source/splitflap.c
  6. 10
      ADIS_tinyK22_SplitFlap/source/splitflap.h

@ -53,21 +53,7 @@ void App_Init(void){
static void App_Task(void* pv){
McuLog_info("Application Task starting");
McuLog_info("Initializing split flap motors.");
SF_MoveMotorToZeroPositionAsync(splitflap0);
SF_MoveMotorToZeroPositionAsync(splitflap1);
// timeout of 35sec
bool initSuccess = false;
for (int i = 0; i < 700; ++i) {
vTaskDelay(pdMS_TO_TICKS(50));
if(SF_IS_RDY_TO_MOVE((SF_t*)splitflap0) && SF_IS_RDY_TO_MOVE((SF_t*)splitflap1)){
initSuccess = true;
break; // end loop
}
}
McuLog_info("Init of splitflaps done. success=%s\n\n", initSuccess ? "true" : "false");
bool initSuccess = MultiSplitFlap_MoveAllToZeroPosition();
#ifndef APP_DEBUG
if(initSuccess == false)
@ -81,6 +67,9 @@ static void App_Task(void* pv){
((SF_t*)splitflap1)->state = SF_STATE_READY;
#endif
// wait before moving
vTaskDelay(pdMS_TO_TICKS(2000));
/* MULTI SPLIT FLAP TESTING */
char sentences[][2] = {"HI", "IT", "IS", "ME", "!!" }; // "COLLIN!";
while(1){

@ -48,22 +48,61 @@ void MultiSplitFlap_AddFlap(SF_Handle_t splitflap){
addedFlaps++;
}
bool MultiSplitFlap_MoveAllToZeroPosition(void){
McuLog_info("MultiSplitFlap_MoveAllToZeroPosition: Initializing split flap motors.");
// start all inits
for (uint8_t num = 0; num < NUM_FLAPS; ++num) {
// get handle
SF_Handle_t sfHandle = (SF_Handle_t)(getItem(*flapDict, flapKeys[num]));
// start init
SF_MoveMotorToZeroPositionAsync(sfHandle);
}
// timeout of 35sec
bool initSuccess = false;
for (int i = 0; i < 700; ++i) {
initSuccess = true;
vTaskDelay(pdMS_TO_TICKS(50));
// check each splitflap if it is finished with init
for (uint8_t num = 0; num < NUM_FLAPS; ++num) {
// get handle
SF_Handle_t sfHandle = (SF_Handle_t)(getItem(*flapDict, flapKeys[num]));
// check if init done
if(SF_IS_RDY_TO_MOVE(sfHandle) == false){
initSuccess = false;
break; // end loop when one is not yet initialized
}
}
if(initSuccess == true){
break; // end loop when all split flaps are initialized
}
}
McuLog_info("MultiSplitFlap_MoveAllToZeroPosition: Init of splitflaps done. success=%s\n\n", initSuccess ? "true" : "false");
return initSuccess;
}
bool MultiSplitFlap_Display(char sentence[]){
// Start movements
for (uint8_t num = 0; num < NUM_FLAPS; ++num) {
// get handle
SF_Handle_t sfHandle = (SF_Handle_t)(getItem(*flapDict, flapKeys[num]));
char letter = sentence[num];
char letter_move[] = " ";
letter_move[0] = letter;
SF_MoveToFlapAsync(sfHandle, letter_move);
McuLog_info("Multi splitflap: Commanded Flap nr. %i to letter '%c'.\n", num+1, letter);
vTaskDelay(pdMS_TO_TICKS(100));
vTaskDelay(pdMS_TO_TICKS(100)); // delay loop
}
// wait until finished
bool done = false;
while(done == false){
done = true;
vTaskDelay(pdMS_TO_TICKS(100)); // delay loop
done = true; // default is successful
// go through all splitflaps
for (uint8_t num = 0; num < NUM_FLAPS; ++num) {
SF_Handle_t sfHandle = (SF_Handle_t)(getItem(*flapDict, flapKeys[num]));
if(SF_GetCurrentState(sfHandle) == SF_STATE_MOVING){
@ -73,11 +112,28 @@ bool MultiSplitFlap_Display(char sentence[]){
}
return done;
}
bool MultiSplitFlap_SetHardwareIdentifier(SetupIdentifier_t id, HardwareIdentifier_t hwId){
// number too high (not that many split flaps can be added to the combination)
if(id >= NUM_FLAPS){
return false;
}
// number too high (not that many split flaps were added added to the combination)
if(id >= MultiSplitFlap_GetAmountOfAddedSplitFlaps()){
return false;
}
// number negative
if(id < 0){
return false;
}
// get handle
SF_Handle_t sfHandle = (SF_Handle_t)(getItem(*flapDict, flapKeys[id]));
// set hardware identifier
SF_SetHardwareIdentifier(sfHandle, hwId);
// for testing purposes only
//SF_t* sf0 = (SF_t*)(SF_Handle_t)(getItem(*flapDict, flapKeys[0]));
//SF_t* sf1 = (SF_t*)(SF_Handle_t)(getItem(*flapDict, flapKeys[1]));
//int32_t test = McuULN2003_GetPos(sf1->motor);
return true;
}
uint8_t MultiSplitFlap_GetAmountOfAddedSplitFlaps(void){

@ -22,11 +22,20 @@ void MultiSplitFlap_Deinit(void);
/* add a splitflap to the combination */
void MultiSplitFlap_AddFlap(SF_Handle_t splitflap);
/* moves all split flaps to the zero position
* After a timeout of 35sec the initializtion is cancelled and the return value is false
* If all splitflaps report to be initialized before the timeout, the return value is true */
bool MultiSplitFlap_MoveAllToZeroPosition(void);
/* display a sentence on the splitflap combination
* splitflaps must be initialized to be able to display something!
* returns true when all movements finished */
bool MultiSplitFlap_Display(char sentence[]);
/* sets the hardware identifier <hwId> of a splitflap with <id> in the combination
* returns true when successful, false when not (e.g. split flap with given id not available) */
bool MultiSplitFlap_SetHardwareIdentifier(SetupIdentifier_t id, HardwareIdentifier_t hwId);
/* returns the amount of registered split flap displays in the combination */
uint8_t MultiSplitFlap_GetAmountOfAddedSplitFlaps(void);

@ -9,7 +9,7 @@
#define PLATFORM_H_
/* SETTINGS */
#define APP_DEBUG
//#define APP_DEBUG
/* Platform initialization */
void PL_Init(void);

@ -219,9 +219,9 @@ void SF_MoveSteps(SF_Handle_t instance, uint32_t steps){
steps--;
}
#ifdef McuLib_CONFIG_SDK_USE_FREERTOS
vTaskDelay(pdMS_TO_TICKS(20));
vTaskDelay(pdMS_TO_TICKS(1));
#else
McuWait_Waitms(20);
McuWait_Waitms(1);
#endif
}
McuULN2003_AccelerationEnd(((SF_t*)instance)->motor);
@ -276,6 +276,10 @@ void SF_MoveToFlapAsync(SF_Handle_t instance, Flap_t flap){
}
}
void SF_SetHardwareIdentifier(SF_Handle_t instance, HardwareIdentifier_t identifier){
((SF_t*)instance)->hwId = identifier;
}
int32_t SF_GetMotorPosition(SF_Handle_t instance){
return McuULN2003_GetPos(((SF_t*)instance)->motor);
}

@ -65,9 +65,9 @@ typedef struct {
} SF_Config_t;
/****** HELPER MACROS **/
#define SF_IS_RDY_TO_MOVE(sf) ((sf)->state == SF_STATE_READY)
#define SF_IS_MOVING(sf) ((sf)->state == SF_STATE_MOVING)
#define SF_IS_INITIALIZING(sf) ((sf)->state == SF_STATE_INITIALIZATION)
#define SF_IS_RDY_TO_MOVE(sf) (((SF_t*)sf)->state == SF_STATE_READY)
#define SF_IS_MOVING(sf) (((SF_t*)sf)->state == SF_STATE_MOVING)
#define SF_IS_INITIALIZING(sf) (((SF_t*)sf)->state == SF_STATE_INITIALIZATION)
/****** FUNCTIONS ******/
/* initializes dictonary with splitflap flaps position */
@ -109,6 +109,10 @@ void SF_MoveToFlap(SF_Handle_t instance, Flap_t flap);
/* move to specific flap asynchronously (RTOS task) */
void SF_MoveToFlapAsync(SF_Handle_t instance, Flap_t flap);
/* sets the hardware identifier of the split flap.
* on re-init the new hardware identifier is used to determine offset steps */
void SF_SetHardwareIdentifier(SF_Handle_t instance, HardwareIdentifier_t identifier);
/* get current position of motor */
int32_t SF_GetMotorPosition(SF_Handle_t instance);

Loading…
Cancel
Save