Skip to content

Commit

Permalink
Rudder bug fix
Browse files Browse the repository at this point in the history
1. Add the check for ESP32S3_master availability. From now, rudder will only work when ESP32S3_master is available.
  • Loading branch information
tcfshcrw committed Aug 9, 2024
1 parent db22a01 commit 8bad762
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 37 deletions.
15 changes: 14 additions & 1 deletion ESP32/include/ESPNOW_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct_message myData;

ESPNow_Send_Struct _ESPNow_Recv;
ESPNow_Send_Struct _ESPNow_Send;
void sendMessageToMaster(int32_t controllerValue)
bool sendMessageToMaster(int32_t controllerValue)
{

myData.cycleCnt_u64++;
Expand All @@ -62,7 +62,20 @@ void sendMessageToMaster(int32_t controllerValue)
if(ESPNOW_status)
{
esp_err_t result = esp_now_send(esp_master, (uint8_t *) &myData, sizeof(myData));
if(result == ESP_OK)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}


//esp_now_send(esp_master, (uint8_t *) &myData, sizeof(myData));
/*
Expand Down
75 changes: 39 additions & 36 deletions ESP32/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1138,10 +1138,11 @@ void pedalUpdateTask( void * pvParameters )


// compute controller output
dap_calculationVariables_st.StepperPos_setback();
dap_calculationVariables_st.reset_maxforce();
dap_calculationVariables_st.dynamic_update();
dap_calculationVariables_st.updateStiffness();
dap_calculationVariables_st.StepperPos_setback();

if(semaphore_updateJoystick!=NULL)
{
if(xSemaphoreTake(semaphore_updateJoystick, (TickType_t)1)==pdTRUE) {
Expand Down Expand Up @@ -1833,51 +1834,53 @@ void ESPNOW_SyncTask( void * pvParameters )
for(;;)
{
//if(ESPNOW_status)
{

if(ESPNow_initial_status==false)
{
ESPNow_initialize();
}
else
{
bool espnow_result= sendMessageToMaster(joystickNormalizedToInt32);

if(espnow_result)
{
//rudder sync
if(dap_calculationVariables_st.Rudder_status)
{
dap_calculationVariables_st.current_pedal_position_ratio=((float)(dap_calculationVariables_st.current_pedal_position-dap_calculationVariables_st.stepperPosMin_default))/((float)dap_calculationVariables_st.stepperPosRange_default);
_ESPNow_Send.pedal_position_ratio=dap_calculationVariables_st.current_pedal_position_ratio;
_ESPNow_Send.pedal_position=dap_calculationVariables_st.current_pedal_position;
//ESPNow_send=dap_calculationVariables_st.current_pedal_position;
esp_err_t result =ESPNow.send_message(Recv_mac,(uint8_t *) &_ESPNow_Send,sizeof(_ESPNow_Send));
//if (result == ESP_OK)
//{
// Serial.println("Error sending the data");
//}
if(ESPNow_update)
{
//dap_calculationVariables_st.sync_pedal_position=ESPNow_recieve;
dap_calculationVariables_st.sync_pedal_position=_ESPNow_Recv.pedal_position;
dap_calculationVariables_st.Sync_pedal_position_ratio=_ESPNow_Recv.pedal_position_ratio;
ESPNow_update=false;
}
}
}
}
//ESPNOW_count=0;
//send the data to master
//if(dap_config_st.payLoadPedalConfig_.Joystick_ESPsync_to_ESP==1)
//always send message to ESP reciever
//{
sendMessageToMaster(joystickNormalizedToInt32);




//}

//rudder sync
if(dap_calculationVariables_st.Rudder_status)
{
if(ESPNow_initial_status==false)
{
ESPNow_initialize();
}
else
{
dap_calculationVariables_st.current_pedal_position_ratio=((float)(dap_calculationVariables_st.current_pedal_position-dap_calculationVariables_st.stepperPosMin_default))/((float)dap_calculationVariables_st.stepperPosRange_default);
_ESPNow_Send.pedal_position_ratio=dap_calculationVariables_st.current_pedal_position_ratio;
_ESPNow_Send.pedal_position=dap_calculationVariables_st.current_pedal_position;
//ESPNow_send=dap_calculationVariables_st.current_pedal_position;
esp_err_t result = ESPNow.send_message(Recv_mac,(uint8_t *) &_ESPNow_Send,sizeof(_ESPNow_Send));
/*
if (result != ESP_OK)
{
Serial.println("Error sending the data");
}
*/

if(ESPNow_update)
{
//dap_calculationVariables_st.sync_pedal_position=ESPNow_recieve;
dap_calculationVariables_st.sync_pedal_position=_ESPNow_Recv.pedal_position;
dap_calculationVariables_st.Sync_pedal_position_ratio=_ESPNow_Recv.pedal_position_ratio;
ESPNow_update=false;
}

}
}
ESPNOW_count=0;
}



//else
//{
//ESPNOW_count++;
Expand Down

0 comments on commit 8bad762

Please sign in to comment.