diff --git a/ESP32/include/ABSOscillation.h b/ESP32/include/ABSOscillation.h index 4ec39552..e41e725a 100644 --- a/ESP32/include/ABSOscillation.h +++ b/ESP32/include/ABSOscillation.h @@ -431,67 +431,4 @@ class Custom_vibration { } -}; -MovingAverageFilter movingAverageFilter_rudder(70); -class Rudder{ -public: - float force_offset; - float force_offset_filter; - float Force_Range; - float _rudder_value; - float basic_support_force; - bool rudder_status; - float min_force; - void offset_calculate(DAP_calculationVariables_st* calcVars_st, uint8_t pedaltype) - { - force_offset=0; - Force_Range=calcVars_st->Force_Range; - basic_support_force=0; - rudder_status=calcVars_st->rudder_status; - min_force=calcVars_st->Force_Min; - if(rudder_status) - { - _rudder_value=calcVars_st->rudder; - basic_support_force=0.5*Force_Range+min_force; - if(pedaltype==1) - { - // if brake - if(calcVars_st->rudder>50) - { - //offset=-1*(calcVars_st->rudder/100*calcVars_st->stepperPosRange-0.5*calcVars_st->stepperPosRange); - //offset=calcVars_st->stepperPosRange-calcVars_st->rudder/100*calcVars_st->stepperPosRange; - force_offset=-1*(_rudder_value-50)/100.0f*Force_Range; - } - if(calcVars_st->rudder<=50) - { - force_offset=0; - } - - } - if(pedaltype==2) - { - //if gas - if(calcVars_st->rudder<50) - { - //offset=-1*(0.5*calcVars_st->stepperPosRange-calcVars_st->rudder/100*calcVars_st->stepperPosRange); - //force_offset=calcVars_st->rudder/100*calcVars_st->stepperPosRange; - force_offset=-1*(50-_rudder_value)/100.0f*Force_Range; - } - if(calcVars_st->rudder>=50) - { - force_offset=0; - } - } - force_offset_filter=movingAverageFilter_rudder.process(force_offset+basic_support_force); - } - else - { - force_offset_filter=0; - - //rudder_status=false; - } - - } - - }; \ No newline at end of file diff --git a/ESP32/include/DiyActivePedal_types.h b/ESP32/include/DiyActivePedal_types.h index df6bb086..88d483fb 100644 --- a/ESP32/include/DiyActivePedal_types.h +++ b/ESP32/include/DiyActivePedal_types.h @@ -3,7 +3,7 @@ #include // define the payload revision -#define DAP_VERSION_CONFIG 138 +#define DAP_VERSION_CONFIG 137 // define the payload types #define DAP_PAYLOAD_TYPE_CONFIG 100 @@ -35,7 +35,6 @@ struct payloadPedalAction { uint8_t impact_value_u8; uint8_t Trigger_CV_1; uint8_t Trigger_CV_2; - uint8_t rudder_value; }; @@ -127,8 +126,6 @@ struct payloadPedalConfig { //Custom Vibration 2 uint8_t CV_amp_2; uint8_t CV_freq_2; - //rudder - uint8_t rudder_flag; // cubic spline parameters float cubic_spline_param_a_array[5]; float cubic_spline_param_b_array[5]; @@ -248,8 +245,6 @@ struct DAP_calculationVariables_st float Force_Max_default; float WS_amp; float WS_freq; - uint8_t rudder=255; - bool rudder_status=false; void updateFromConfig(DAP_config_st& config_st); void updateEndstops(long newMinEndstop, long newMaxEndstop); diff --git a/ESP32/src/DiyActivePedal_types.cpp b/ESP32/src/DiyActivePedal_types.cpp index 493f4190..58fa00c6 100644 --- a/ESP32/src/DiyActivePedal_types.cpp +++ b/ESP32/src/DiyActivePedal_types.cpp @@ -59,7 +59,6 @@ void DAP_config_st::initialiseDefaults() { payLoadPedalConfig_.WS_freq=15; payLoadPedalConfig_.Road_multi = 50; payLoadPedalConfig_.Road_window=60; - payLoadPedalConfig_.rudder_flag=0; payLoadPedalConfig_.cubic_spline_param_a_array[0] = 0; payLoadPedalConfig_.cubic_spline_param_a_array[1] = 0; payLoadPedalConfig_.cubic_spline_param_a_array[2] = 0; diff --git a/ESP32/src/Main.cpp b/ESP32/src/Main.cpp index 26440558..c347dd11 100644 --- a/ESP32/src/Main.cpp +++ b/ESP32/src/Main.cpp @@ -93,7 +93,6 @@ WSOscillation _WSOscillation; Road_impact_effect _Road_impact_effect; Custom_vibration CV1; Custom_vibration CV2; -Rudder _rudder; #define ABS_OSCILLATION @@ -766,32 +765,26 @@ void pedalUpdateTask( void * pvParameters ) float absForceOffset = 0; float absPosOffset = 0; #ifdef ABS_OSCILLATION - - _rudder.offset_calculate(&dap_calculationVariables_st,dap_config_st.payLoadPedalConfig_.pedal_type); - - - absOscillation.forceOffset(&dap_calculationVariables_st, dap_config_st.payLoadPedalConfig_.absPattern, dap_config_st.payLoadPedalConfig_.absForceOrTarvelBit, &absForceOffset, &absPosOffset); - _RPMOscillation.trigger(); - _RPMOscillation.forceOffset(&dap_calculationVariables_st); - _BitePointOscillation.forceOffset(&dap_calculationVariables_st); - _G_force_effect.forceOffset(&dap_calculationVariables_st, dap_config_st.payLoadPedalConfig_.G_multi); - _WSOscillation.forceOffset(&dap_calculationVariables_st); - _Road_impact_effect.forceOffset(&dap_calculationVariables_st, dap_config_st.payLoadPedalConfig_.Road_multi); - CV1.forceOffset(dap_config_st.payLoadPedalConfig_.CV_freq_1,dap_config_st.payLoadPedalConfig_.CV_amp_1); - CV2.forceOffset(dap_config_st.payLoadPedalConfig_.CV_freq_2,dap_config_st.payLoadPedalConfig_.CV_amp_2); - - + absOscillation.forceOffset(&dap_calculationVariables_st, dap_config_st.payLoadPedalConfig_.absPattern, dap_config_st.payLoadPedalConfig_.absForceOrTarvelBit, &absForceOffset, &absPosOffset); + _RPMOscillation.trigger(); + _RPMOscillation.forceOffset(&dap_calculationVariables_st); + _BitePointOscillation.forceOffset(&dap_calculationVariables_st); + _G_force_effect.forceOffset(&dap_calculationVariables_st, dap_config_st.payLoadPedalConfig_.G_multi); + _WSOscillation.forceOffset(&dap_calculationVariables_st); + _Road_impact_effect.forceOffset(&dap_calculationVariables_st, dap_config_st.payLoadPedalConfig_.Road_multi); + CV1.forceOffset(dap_config_st.payLoadPedalConfig_.CV_freq_1,dap_config_st.payLoadPedalConfig_.CV_amp_1); + CV2.forceOffset(dap_config_st.payLoadPedalConfig_.CV_freq_2,dap_config_st.payLoadPedalConfig_.CV_amp_2); #endif + //update max force with G force effect + movingAverageFilter.dataPointsCount=dap_config_st.payLoadPedalConfig_.G_window; + movingAverageFilter_roadimpact.dataPointsCount=dap_config_st.payLoadPedalConfig_.Road_window; + dap_calculationVariables_st.reset_maxforce(); + dap_calculationVariables_st.Force_Max+=_G_force_effect.G_force; + dap_calculationVariables_st.Force_Max+=_Road_impact_effect.Road_Impact_force; + dap_calculationVariables_st.dynamic_update(); + dap_calculationVariables_st.updateStiffness(); - //update max force with G force effect - movingAverageFilter.dataPointsCount=dap_config_st.payLoadPedalConfig_.G_window; - movingAverageFilter_roadimpact.dataPointsCount=dap_config_st.payLoadPedalConfig_.Road_window; - dap_calculationVariables_st.reset_maxforce(); - dap_calculationVariables_st.Force_Max+=_G_force_effect.G_force; - dap_calculationVariables_st.Force_Max+=_Road_impact_effect.Road_Impact_force; - dap_calculationVariables_st.dynamic_update(); - dap_calculationVariables_st.updateStiffness(); // compute the pedal incline angle //#define COMPUTE_PEDAL_INCLINE_ANGLE #ifdef COMPUTE_PEDAL_INCLINE_ANGLE @@ -941,15 +934,12 @@ void pedalUpdateTask( void * pvParameters ) //Add effect by force - float effect_force=absForceOffset+ _BitePointOscillation.BitePoint_Force_offset+_WSOscillation.WS_Force_offset+CV1.CV_Force_offset+CV2.CV_Force_offset+_rudder.force_offset_filter; + float effect_force=absForceOffset+ _BitePointOscillation.BitePoint_Force_offset+_WSOscillation.WS_Force_offset+CV1.CV_Force_offset+CV2.CV_Force_offset; - - // use interpolation to determine local linearized spring stiffness double stepperPosFraction = stepper->getCurrentPositionFraction(); int32_t Position_Next = 0; - // select control loop algo if (dap_config_st.payLoadPedalConfig_.control_strategy_b <= 1) { @@ -960,19 +950,6 @@ void pedalUpdateTask( void * pvParameters ) { Position_Next = MoveByForceTargetingStrategy(filteredReading, stepper, &forceCurve, &dap_calculationVariables_st, &dap_config_st, effect_force, changeVelocity, stepper_vel_filtered_fl32, stepper_accel_filtered_fl32, d_phi_d_x, d_x_hor_d_phi); } - /* - if(dap_calculationVariables_st.rudder_status) - { - Serial.print("next:"); - Serial.println(Position_Next); - //Position_Next=Position_Next+dap_calculationVariables_st.stepperPosRange*0.5; - Serial.print("positionnext:"); - Serial.println(Position_Next); - Serial.print("stepper range*0.5"); - Serial.println(dap_calculationVariables_st.stepperPosRange*0.5); - - } - */ @@ -1005,8 +982,6 @@ void pedalUpdateTask( void * pvParameters ) //Adding effects Position_Next +=_RPMOscillation.RPM_position_offset; Position_Next +=absPosOffset; - - Position_Next = (int32_t)constrain(Position_Next, dap_calculationVariables_st.stepperPosMinEndstop, dap_calculationVariables_st.stepperPosMaxEndstop); @@ -1070,18 +1045,8 @@ void pedalUpdateTask( void * pvParameters ) else { //joystickNormalizedToInt32 = NormalizeControllerOutputValue(loadcellReading, dap_calculationVariables_st.Force_Min, dap_calculationVariables_st.Force_Max, dap_config_st.payLoadPedalConfig_.maxGameOutput); - if(dap_calculationVariables_st.rudder_status) - { - //filteredReading=filteredReading+_rudder.force_offset_filter; - filteredReading=constrain(filteredReading,dap_calculationVariables_st.Force_Min,dap_calculationVariables_st.Force_Max-_rudder.basic_support_force); - joystickNormalizedToInt32 = NormalizeControllerOutputValue(filteredReading, dap_calculationVariables_st.Force_Min, dap_calculationVariables_st.Force_Max-_rudder.basic_support_force, dap_config_st.payLoadPedalConfig_.maxGameOutput); - - } - else - { - joystickNormalizedToInt32 = NormalizeControllerOutputValue(filteredReading, dap_calculationVariables_st.Force_Min, dap_calculationVariables_st.Force_Max, dap_config_st.payLoadPedalConfig_.maxGameOutput); - - } + + joystickNormalizedToInt32 = NormalizeControllerOutputValue(filteredReading, dap_calculationVariables_st.Force_Min, dap_calculationVariables_st.Force_Max, dap_config_st.payLoadPedalConfig_.maxGameOutput); } xSemaphoreGive(semaphore_updateJoystick); @@ -1382,20 +1347,6 @@ void serialCommunicationTask( void * pvParameters ) Serial.write((char*)dap_config_st_local_ptr, sizeof(DAP_config_st)); Serial.print("\r\n"); } - if(dap_actions_st.payloadPedalAction_.rudder_value>0&&dap_actions_st.payloadPedalAction_.rudder_value<102) - { - dap_calculationVariables_st.rudder=dap_actions_st.payloadPedalAction_.rudder_value-1; - dap_calculationVariables_st.rudder_status=true; - //Serial.println("action:"); - //Serial.println(dap_actions_st.payloadPedalAction_.rudder_value); - } - else - { - //dap_calculationVariables_st.rudder=0; - dap_calculationVariables_st.rudder_status=false; - } - - } diff --git a/SimHubPlugin/DataPluginDemo.cs b/SimHubPlugin/DataPluginDemo.cs index d96ee03e..392d0c7b 100644 --- a/SimHubPlugin/DataPluginDemo.cs +++ b/SimHubPlugin/DataPluginDemo.cs @@ -8,7 +8,6 @@ using System.Runtime; using System.Runtime.InteropServices; using System.Text; -using System.Threading; using System.Windows.Controls; using System.Windows.Media; using Windows.UI.Notifications; @@ -24,7 +23,7 @@ static class Constants { // payload revisiom - public const uint pedalConfigPayload_version = 138; + public const uint pedalConfigPayload_version = 137; // pyload types @@ -60,7 +59,6 @@ public struct payloadPedalAction public byte impact_value; public byte Trigger_CV_1; public byte Trigger_CV_2; - public byte rudder_value; }; public struct payloadPedalState_Basic @@ -286,9 +284,6 @@ public class DIY_FFB_Pedal : IPlugin, IDataPlugin, IWPFSettingsV2 public string simhub_theme_color = "#7E87CEFA"; public uint debug_value = 0; public bool Rudder_enable_flag=false; - public byte _rudder_position = 50; - public bool flag_clear_action=false; - @@ -549,7 +544,6 @@ unsafe public void DataUpdate(PluginManager pluginManager, ref GameData data) tmp.payloadPedalAction_.impact_value = 0; tmp.payloadPedalAction_.Trigger_CV_1 = 0; tmp.payloadPedalAction_.Trigger_CV_2 = 0; - tmp.payloadPedalAction_.rudder_value = 255; if (Settings.G_force_enable_flag[pedalIdx] == 1) { tmp.payloadPedalAction_.G_value = (Byte)g_force_last_value; @@ -750,7 +744,6 @@ unsafe public void DataUpdate(PluginManager pluginManager, ref GameData data) tmp.payloadPedalAction_.impact_value = 0; tmp.payloadPedalAction_.Trigger_CV_1 = 0; tmp.payloadPedalAction_.Trigger_CV_2 = 0; - tmp.payloadPedalAction_.rudder_value = 255; rpm_last_value = 0; Road_impact_last = 0; debug_value = 0; @@ -789,7 +782,6 @@ unsafe public void DataUpdate(PluginManager pluginManager, ref GameData data) tmp.payloadPedalAction_.impact_value = 0; tmp.payloadPedalAction_.Trigger_CV_1 = 0; tmp.payloadPedalAction_.Trigger_CV_2 = 0; - tmp.payloadPedalAction_.rudder_value = 0; DAP_action_st* v = &tmp; byte* p = (byte*)v; tmp.payloadFooter_.checkSum = checksumCalc(p, sizeof(payloadHeader) + sizeof(payloadPedalAction)); @@ -813,73 +805,8 @@ unsafe public void DataUpdate(PluginManager pluginManager, ref GameData data) _serialPort[1].Write(newBuffer, 0, newBuffer.Length); } } - if (Rudder_enable_flag==true && flag_clear_action==false) - { - DAP_action_st tmp; - tmp.payloadHeader_.version = (byte)Constants.pedalConfigPayload_version; - tmp.payloadHeader_.payloadType = (byte)Constants.pedalActionPayload_type; - tmp.payloadPedalAction_.triggerAbs_u8 = 0; - tmp.payloadPedalAction_.RPM_u8 = 0; - tmp.payloadPedalAction_.G_value = 128; - tmp.payloadPedalAction_.WS_u8 = 0; - tmp.payloadPedalAction_.impact_value = 0; - tmp.payloadPedalAction_.Trigger_CV_1 = 0; - tmp.payloadPedalAction_.Trigger_CV_2 = 0; - tmp.payloadPedalAction_.rudder_value = _rudder_position; - DAP_action_st* v = &tmp; - byte* p = (byte*)v; - tmp.payloadFooter_.checkSum = checksumCalc(p, sizeof(payloadHeader) + sizeof(payloadPedalAction)); - int length = sizeof(DAP_action_st); - byte[] newBuffer = new byte[length]; - newBuffer = getBytes_Action(tmp); - for (uint pedalidx = 1; pedalidx < 3; pedalidx++) - { - if (_serialPort[pedalidx].IsOpen) - { - // clear inbuffer - _serialPort[pedalidx].DiscardInBuffer(); - - // send query command - _serialPort[pedalidx].Write(newBuffer, 0, newBuffer.Length); - } - } - - } - if (flag_clear_action) - { - DAP_action_st tmp; - tmp.payloadHeader_.version = (byte)Constants.pedalConfigPayload_version; - tmp.payloadHeader_.payloadType = (byte)Constants.pedalActionPayload_type; - tmp.payloadPedalAction_.triggerAbs_u8 = 0; - tmp.payloadPedalAction_.RPM_u8 = 0; - tmp.payloadPedalAction_.G_value = 128; - tmp.payloadPedalAction_.WS_u8 = 0; - tmp.payloadPedalAction_.impact_value = 0; - tmp.payloadPedalAction_.Trigger_CV_1 = 0; - tmp.payloadPedalAction_.Trigger_CV_2 = 0; - tmp.payloadPedalAction_.rudder_value = 0; - DAP_action_st* v = &tmp; - byte* p = (byte*)v; - tmp.payloadFooter_.checkSum = checksumCalc(p, sizeof(payloadHeader) + sizeof(payloadPedalAction)); - int length = sizeof(DAP_action_st); - byte[] newBuffer = new byte[length]; - newBuffer = getBytes_Action(tmp); - for (uint pedalidx = 0; pedalidx < 3; pedalidx++) - { - if (_serialPort[pedalidx].IsOpen) - { - // clear inbuffer - _serialPort[pedalidx].DiscardInBuffer(); - - // send query command - _serialPort[pedalidx].Write(newBuffer, 0, newBuffer.Length); - } - } - flag_clear_action = false; - } - this.AttachDelegate("CurrentProfile", () => current_profile); pluginManager.SetPropertyValue("SelectedPedal", this.GetType(), current_pedal); pluginManager.SetPropertyValue("Action", this.GetType(), current_action); diff --git a/SimHubPlugin/SettingsControlDemo.xaml b/SimHubPlugin/SettingsControlDemo.xaml index 1d4f3c9c..4b042991 100644 --- a/SimHubPlugin/SettingsControlDemo.xaml +++ b/SimHubPlugin/SettingsControlDemo.xaml @@ -843,7 +843,7 @@ - diff --git a/SimHubPlugin/SettingsControlDemo.xaml.cs b/SimHubPlugin/SettingsControlDemo.xaml.cs index 3bdfeb46..5f26f7ef 100644 --- a/SimHubPlugin/SettingsControlDemo.xaml.cs +++ b/SimHubPlugin/SettingsControlDemo.xaml.cs @@ -474,7 +474,6 @@ public void DAP_config_set_default(uint pedalIdx) dap_config_st[pedalIdx].payloadPedalConfig_.pedal_type = (byte)pedalIdx; dap_config_st[pedalIdx].payloadPedalConfig_.OTA_flag = 0; dap_config_st[pedalIdx].payloadPedalConfig_.enableReboot_u8 = 0; - } @@ -2085,7 +2084,54 @@ unsafe public void SendConfigToPedal_click(object sender, RoutedEventArgs e) { Sendconfig(indexOfSelectedPedal_u); - + /* + if (Plugin._serialPort[indexOfSelectedPedal_u].IsOpen) + { + + // compute checksum + //getBytes(this.dap_config_st[indexOfSelectedPedal_u].payloadPedalConfig_) + this.dap_config_st[indexOfSelectedPedal_u].payloadHeader_.version = (byte)Constants.pedalConfigPayload_version; + this.dap_config_st[indexOfSelectedPedal_u].payloadHeader_.payloadType = (byte)Constants.pedalConfigPayload_type; + this.dap_config_st[indexOfSelectedPedal_u].payloadHeader_.storeToEeprom = 1; + DAP_config_st tmp = this.dap_config_st[indexOfSelectedPedal_u]; + + //payloadPedalConfig tmp = this.dap_config_st[indexOfSelectedPedal_u].payloadPedalConfig_; + DAP_config_st* v = &tmp; + byte* p = (byte*)v; + this.dap_config_st[indexOfSelectedPedal_u].payloadFooter_.checkSum = Plugin.checksumCalc(p, sizeof(payloadHeader) + sizeof(payloadPedalConfig)); + + + //TextBox_debugOutput.Text = "CRC simhub calc: " + this.dap_config_st[indexOfSelectedPedal_u].payloadFooter_.checkSum + " "; + + TextBox_debugOutput.Text = String.Empty; + + try + { + int length = sizeof(DAP_config_st); + //int val = this.dap_config_st[indexOfSelectedPedal_u].payloadHeader_.checkSum; + //string msg = "CRC value: " + val.ToString(); + byte[] newBuffer = new byte[length]; + newBuffer = getBytes(this.dap_config_st[indexOfSelectedPedal_u]); + + //TextBox_debugOutput.Text = "ConfigLength" + length; + + // clear inbuffer + Plugin._serialPort[indexOfSelectedPedal_u].DiscardInBuffer(); + Plugin._serialPort[indexOfSelectedPedal_u].DiscardOutBuffer(); + + + // send data + Plugin._serialPort[indexOfSelectedPedal_u].Write(newBuffer, 0, newBuffer.Length); + //Plugin._serialPort[indexOfSelectedPedal_u].Write("\n"); + } + catch (Exception caughtEx) + { + string errorMessage = caughtEx.Message; + TextBox_debugOutput.Text = errorMessage; + } + + } + */ } @@ -2863,41 +2909,31 @@ unsafe public void timerCallback_serial(object sender, EventArgs e) else { //Brk move - Plugin.Rudder_enable_flag = true; - double Rudder_axis_value = 16384; + if (Pedal_position_reading[1] > Pedal_position_reading[2]) { - - Rudder_axis_value = Rudder_axis_value - Pedal_position_reading[1]/2; + double Rudder_axis_value = 16384; + Rudder_axis_value = Rudder_axis_value - Pedal_position_reading[1]; joystick.SetAxis((int)Rudder_axis_value, Plugin.Settings.vjoy_order, HID_USAGES.HID_USAGE_RZ); // HID_USAGES Enums - //rudder movement code - //TextBox2.Text = "Rudder:" + Rudder_axis_value; - //TextBox2.Text = "Rudder:" + Rudder_axis_value + "/"; - - } else { if (Pedal_position_reading[2] > Pedal_position_reading[1]) { - - Rudder_axis_value = Rudder_axis_value + Pedal_position_reading[2]/2; + double Rudder_axis_value = 16384; + Rudder_axis_value = Rudder_axis_value + Pedal_position_reading[2]; joystick.SetAxis((int)Rudder_axis_value, Plugin.Settings.vjoy_order, HID_USAGES.HID_USAGE_RZ); // HID_USAGES Enums - //TextBox2.Text = "Rudder:" + Rudder_axis_value; - //TextBox2.Text = "Rudder:" + Rudder_axis_value + "/"; } else { joystick.SetAxis(16384, Plugin.Settings.vjoy_order, HID_USAGES.HID_USAGE_RZ); - //TextBox2.Text = "Rudder:" + Rudder_axis_value+"/"; } } - Plugin._rudder_position = (byte)(Rudder_axis_value / 32768 * 100+1); - //TextBox2.Text += Plugin._rudder_position; + @@ -5347,16 +5383,13 @@ private void Slider_VFgain_ValueChanged(object sender, RoutedPropertyChangedEven private void CheckBox_rudder_Checked(object sender, RoutedEventArgs e) { Plugin.Rudder_enable_flag = true; - Plugin.flag_clear_action = true; } private void CheckBox_rudder_Unchecked(object sender, RoutedEventArgs e) { Plugin.Rudder_enable_flag = false; - - Plugin.flag_clear_action = true; - + } private void CheckBox_RTSDTR_Checked(object sender, RoutedEventArgs e) diff --git a/SimHubPlugin/bin/DiyActivePedal.dll b/SimHubPlugin/bin/DiyActivePedal.dll index 6d48037c..a40825e7 100644 Binary files a/SimHubPlugin/bin/DiyActivePedal.dll and b/SimHubPlugin/bin/DiyActivePedal.dll differ