Skip to content

Commit

Permalink
Merge pull request #9 from tcfshcrw/main
Browse files Browse the repository at this point in the history
add analogoutput and simulated ABS effect
  • Loading branch information
ChrGri authored Dec 24, 2023
2 parents 2263fd2 + 3711aef commit 55892cc
Show file tree
Hide file tree
Showing 24 changed files with 1,410 additions and 194 deletions.
3 changes: 2 additions & 1 deletion Arduino/Esp32/Main/DiyActivePedal_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ void DAP_config_st::initialiseDefaults() {
payLoadPedalConfig_.horPos_AB = 215;
payLoadPedalConfig_.verPos_AB = 80;
payLoadPedalConfig_.lengthPedal_CB = 200;

payLoadPedalConfig_.Simulate_ABS_trigger = 0;// add for abs trigger
payLoadPedalConfig_.Simulate_ABS_value = 80;// add for abs trigger
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
7 changes: 5 additions & 2 deletions Arduino/Esp32/Main/DiyActivePedal_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <stdint.h>


#define DAP_VERSION_CONFIG 108
#define DAP_VERSION_CONFIG 109
#define DAP_PAYLOAD_TYPE_CONFIG 100

struct payloadHeader {
Expand Down Expand Up @@ -59,7 +59,9 @@ struct payloadPedalConfig {
uint8_t horPos_AB;
uint8_t verPos_AB;
uint8_t lengthPedal_CB;

//Simulate ABS trigger
uint8_t Simulate_ABS_trigger;
uint8_t Simulate_ABS_value;
// cubic spline parameters
float cubic_spline_param_a_array[5];
float cubic_spline_param_b_array[5];
Expand Down Expand Up @@ -126,6 +128,7 @@ struct DAP_calculationVariables_st
float endPosRel;
float absFrequency;
float absAmplitude;


float dampingPress;

Expand Down
2 changes: 2 additions & 0 deletions Arduino/Esp32/Main/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
// stepper pins
#define dirPinStepper 22
#define stepPinStepper 23
//analog output pin
#define D_O 25

// endstop pins
#define minPin 12
Expand Down
62 changes: 53 additions & 9 deletions Arduino/Esp32/Main/Main.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#define ESTIMATE_LOADCELL_VARIANCE
#define ISV_COMMUNICATION
//#define Using_analog_output
//#define PRINT_SERVO_STATES

#define DEBUG_INFO_0_CYCLE_TIMER 1
Expand All @@ -16,6 +17,11 @@ bool isv57LifeSignal_b = false;
int32_t servo_offset_compensation_steps_i32 = 0;
#endif

#ifdef Using_analog_output
int32_t Using_analog_output_ = 1;
#else
int32_t Using_analog_output_ = 0;
#endif



Expand Down Expand Up @@ -207,8 +213,15 @@ void setup()
Serial.println(" ");

// init controller
SetupController();
delay(2000);
if(Using_analog_output_ !=1)
{
SetupController();
delay(2000);
}
else
{
delay(10000);
}


// check whether iSV57 communication can be established
Expand Down Expand Up @@ -665,6 +678,19 @@ void pedalUpdateTask( void * pvParameters )
joystickNormalizedToInt32 = NormalizeControllerOutputValue(loadcellReading, 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);
if(Using_analog_output_ =1)
{
int dac_value=(int)(joystickNormalizedToInt32*255/10000);
dacWrite(D_O,dac_value);
}
if(dap_config_st.payLoadPedalConfig_.Simulate_ABS_trigger==1)
{
int32_t ABS_trigger_value=dap_config_st.payLoadPedalConfig_.Simulate_ABS_value*100;
if(joystickNormalizedToInt32 > ABS_trigger_value)
{
absOscillation.trigger();
}
}
}
}
else
Expand Down Expand Up @@ -863,20 +889,38 @@ void serialCommunicationTask( void * pvParameters )
}

// transmit controller output
if (IsControllerReady()) {
if(Using_analog_output_ =1)
{
if(semaphore_updateJoystick!=NULL)
{
if(xSemaphoreTake(semaphore_updateJoystick, (TickType_t)1)==pdTRUE)
{
joystickNormalizedToInt32_local = joystickNormalizedToInt32;
xSemaphoreGive(semaphore_updateJoystick);
if(xSemaphoreTake(semaphore_updateJoystick, (TickType_t)1)==pdTRUE)
{
joystickNormalizedToInt32_local = joystickNormalizedToInt32;
xSemaphoreGive(semaphore_updateJoystick);
}
//else
//{
//Serial.println("semaphore_updateJoystick == 0");
//Serial.println("semaphore_updateJoystick == 0");
//}
}
}
else
{
if (IsControllerReady()) {
if(semaphore_updateJoystick!=NULL)
{
if(xSemaphoreTake(semaphore_updateJoystick, (TickType_t)1)==pdTRUE)
{
joystickNormalizedToInt32_local = joystickNormalizedToInt32;
xSemaphoreGive(semaphore_updateJoystick);
}
//else
//{
//Serial.println("semaphore_updateJoystick == 0");
//}
}
SetControllerOutputValue(joystickNormalizedToInt32_local);
}
SetControllerOutputValue(joystickNormalizedToInt32_local);
}

}
Expand Down
36 changes: 36 additions & 0 deletions SimHubPlugin/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// Les informations générales relatives à un assembly dépendent de
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
// associées à un assembly.
[assembly: AssemblyTitle("User.PluginSdkDemo")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("User.PluginSdkDemo")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly
// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de
// COM, affectez la valeur true à l'attribut ComVisible sur ce type.
[assembly: ComVisible(false)]

// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM
[assembly: Guid("833040c9-fe5e-4ccf-b21d-71979e049b6b")]

// Les informations de version pour un assembly se composent des quatre valeurs suivantes :
//
// Version principale
// Version secondaire
// Numéro de build
// Révision
//
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
8 changes: 6 additions & 2 deletions SimHubPlugin/DataPluginDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@ public struct payloadPedalConfig
public byte absFrequency; // In Hz
public byte absAmplitude; // In kg/20



// geometric properties of the pedal
// in mm
public byte lengthPedal_AC;
public byte horPos_AB;
public byte verPos_AB;
public byte lengthPedal_CB;
public byte Simulate_ABS_trigger; //simulateABS
public byte Simulate_ABS_value; //simulated ABS value

// cubic spline params
public float cubic_spline_param_a_0;
Expand Down Expand Up @@ -467,7 +471,7 @@ public void Init(PluginManager pluginManager)


dap_config_initial_st.payloadHeader_.payloadType = 100;
dap_config_initial_st.payloadHeader_.version = 108;
dap_config_initial_st.payloadHeader_.version = 109;
dap_config_initial_st.payloadHeader_.storeToEeprom = 0;
dap_config_initial_st.payloadPedalConfig_.pedalStartPosition = 35;
dap_config_initial_st.payloadPedalConfig_.pedalEndPosition = 80;
Expand All @@ -486,7 +490,7 @@ public void Init(PluginManager pluginManager)
dap_config_initial_st.payloadPedalConfig_.horPos_AB = 215;
dap_config_initial_st.payloadPedalConfig_.verPos_AB = 80;
dap_config_initial_st.payloadPedalConfig_.lengthPedal_CB = 200;

dap_config_initial_st.payloadPedalConfig_.Simulate_ABS_trigger = 0;
dap_config_initial_st.payloadPedalConfig_.maxGameOutput = 100;

dap_config_initial_st.payloadPedalConfig_.kf_modelNoise = 128;
Expand Down
10 changes: 10 additions & 0 deletions SimHubPlugin/DesignTimeResources.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
<ResourceDictionary Source="pack://application:,,,/SimHub.Plugins;component/Styles/SimHubStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
73 changes: 73 additions & 0 deletions SimHubPlugin/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 55892cc

Please sign in to comment.