Skip to content

Commit

Permalink
Revert "Rudder first implement"
Browse files Browse the repository at this point in the history
This reverts commit c1386fb.
  • Loading branch information
tcfshcrw committed Jul 24, 2024
1 parent c1386fb commit c3a0ab2
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 236 deletions.
63 changes: 0 additions & 63 deletions ESP32/include/ABSOscillation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}


};
7 changes: 1 addition & 6 deletions ESP32/include/DiyActivePedal_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <stdint.h>

// define the payload revision
#define DAP_VERSION_CONFIG 138
#define DAP_VERSION_CONFIG 137

// define the payload types
#define DAP_PAYLOAD_TYPE_CONFIG 100
Expand Down Expand Up @@ -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;
};


Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion ESP32/src/DiyActivePedal_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
89 changes: 20 additions & 69 deletions ESP32/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ WSOscillation _WSOscillation;
Road_impact_effect _Road_impact_effect;
Custom_vibration CV1;
Custom_vibration CV2;
Rudder _rudder;
#define ABS_OSCILLATION


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);
}
*/



Expand Down Expand Up @@ -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);


Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}




}
Expand Down
75 changes: 1 addition & 74 deletions SimHubPlugin/DataPluginDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,7 +23,7 @@
static class Constants
{
// payload revisiom
public const uint pedalConfigPayload_version = 138;
public const uint pedalConfigPayload_version = 137;


// pyload types
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;




Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion SimHubPlugin/SettingsControlDemo.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@
</StackPanel>
<StackPanel Height="20" Width="160" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5,4,0,0">
<styles:SHToggleButton x:Name="CheckBox_rudder" Content="" Checked="CheckBox_rudder_Checked" Unchecked="CheckBox_rudder_Unchecked" IsChecked="False" FontSize="10" Width="35" Height="15" HorizontalAlignment="Left" FontFamily="Arial" ToolTip="Combie Brk and Acc into 1 axis Rz, use as Rudder, only work in vjoy" RenderTransformOrigin="0.5,0.5" Margin="-10,0,0,0" IsEnabled="False" />
<Label Content="Rudder" Height="20" Width="130" Padding="0,0,0,0" VerticalContentAlignment="Center" FontFamily="Arial" HorizontalAlignment="Left" FontSize="10" Margin="4,0,0,0" ToolTip="experimental features use at your own risk"/>
<Label Content="Combine Axis" Height="20" Width="130" Padding="0,0,0,0" VerticalContentAlignment="Center" FontFamily="Arial" HorizontalAlignment="Left" FontSize="10" Margin="4,0,0,0"/>
</StackPanel>
<StackPanel Height="20" Width="160" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5,4,0,0">
<styles:SHToggleButton x:Name="CheckBox_RTSDTR" Content="" Checked="CheckBox_RTSDTR_Checked" Unchecked="CheckBox_RTSDTR_Unchecked" IsChecked="False" FontSize="10" Width="35" Height="15" HorizontalAlignment="Left" FontFamily="Arial" ToolTip="The option is for S3" RenderTransformOrigin="0.5,0.5" Margin="-10,0,0,0" />
Expand Down
Loading

0 comments on commit c3a0ab2

Please sign in to comment.