Skip to content

Commit

Permalink
Add Center Sensors
Browse files Browse the repository at this point in the history
Implement Sensors to detect the center position
  • Loading branch information
gagagu committed Apr 21, 2023
1 parent de49247 commit e1acf73
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 14 deletions.
47 changes: 46 additions & 1 deletion Arduino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
#define ADJ_ENDSWITCH_ROLL_RIGHT 3
#define ADJ_BUTTON_CALIBRATION 4

// If you use center sensor use
// RES_1 connector for Roll Roll Sensor
// RES_2 connector for Pitch Sensor
#if defined(LANGUAGE_EN)
#define ADJ_MIDDLESWITCH_ROLL 5
#define ADJ_MIDDLESWITCH_PITCH 6
#endif

// variables for Speed calculation
byte roll_speed = 0;
Expand Down Expand Up @@ -209,6 +216,31 @@ void CheckCalibrationMode() {

// dsiable motor
DisableMotors();

#if defined(LANGUAGE_EN)
// Print message to display for center position
LcdPrintCalibrationMiddleSensors();

// measure center by ir sensors
byte byteFlag=0;
while(byteFlag!= B00000011)
{
delay(1);
ReadMux();

// If Center Roll Sensor detects reset Roll counter
if((iSensorPinStates & (1 << ADJ_MIDDLESWITCH_ROLL))==0){
counterRoll.readAndReset();
byteFlag=byteFlag | B00000001;
}

// If Center Pitch Sensor detects reset Roll counter
if((iSensorPinStates & (1 << ADJ_MIDDLESWITCH_PITCH))==0){
counterPitch.readAndReset();
byteFlag=byteFlag | B00000010;
}
}
#else
// Print message to display for center position
LcdPrintCalibrationMiddle();

Expand All @@ -217,10 +249,11 @@ void CheckCalibrationMode() {
delay(1);
ReadMux();
}

// reset counters to zero
counterRoll.readAndReset();
counterPitch.readAndReset();
#endif


// small wait; not really needed but nicer in behavior
delay(500);
Expand Down Expand Up @@ -377,6 +410,18 @@ void ReadMux() {

}//for

// only for censter sensors
#if defined(LANGUAGE_EN)
// If Center Roll Sensor detects reset Roll counter
if((iSensorPinStates & (1 << ADJ_MIDDLESWITCH_ROLL))==0){
counterRoll.readAndReset();
}

// If Center Pitch Sensor detects reset Roll counter
if((iSensorPinStates & (1 << ADJ_MIDDLESWITCH_PITCH))==0){
counterPitch.readAndReset();
}
#endif
}// ReadMux

/******************************************
Expand Down
6 changes: 4 additions & 2 deletions Arduino_FFB_Yoke.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

// Version 1.3.0

#define languageEN // Special thank to Lollo for the inspiration and code
#define LANGUAGE_EN // Special thank to Lollo for the inspiration and code
#define USE_CENTER_SENSOR // comment out when not using center sensor

#define SERIAL_BAUD 115200 // Communication Speed


Expand Down Expand Up @@ -85,8 +87,8 @@ void setup() {
void loop() {
currentMillis = millis(); // number of milliseconds passed since the Arduino board began running the current program

ReadMux(); // Read values of buttons and end switch sensors (except yoke axes)
if (currentMillis >= nextJoystickMillis) { // do not run more frequently than these many milliseconds, the window system needs time to process
ReadMux(); // Read values of buttons and end switch sensors (except yoke axes)
CheckCalibrationMode(); // check if calibration button was pressed an do it
UpdateJoystickButtons(); // set Joystick buttons
Joystick.sendState(); // send joystick values to system
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Cad/FreeCad/IR_Senors_Encoder/Yoke_Pipe_EndRing_Sensor.FCStd
Binary file not shown.
36 changes: 25 additions & 11 deletions LCD_EN.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if defined(languageEN) // language englisch
#if defined(LANGUAGE_EN) // language englisch

/******************************************
Into
Expand Down Expand Up @@ -45,16 +45,30 @@ void LCDPrintDebugMode(){
lcd.setCursor(0, 0);
lcd.print(F("Debug Mode: On"));
}
/******************************************
show calibration middle
*******************************************/
void LcdPrintCalibrationMiddle(){
lcd.setCursor(0, 0);
lcd.print(F("Put all axes in the "));
lcd.print(F("middle position and "));
lcd.print(F("press the calibratib"));
lcd.print(F("ration button "));
}

#if defined(LANGUAGE_EN)
/******************************************
show calibration middle
*******************************************/
void LcdPrintCalibrationMiddleSensors(){
lcd.setCursor(0, 0);
lcd.print(F("Put all axes from "));
lcd.print(F("one end to the other"));
lcd.print(F("to detect the middle"));
lcd.print(F("by sensor "));
}
#else
/******************************************
show calibration middle
*******************************************/
void LcdPrintCalibrationMiddle(){
lcd.setCursor(0, 0);
lcd.print(F("Put all axes in the "));
lcd.print(F("middle position and "));
lcd.print(F("press the calibratib"));
lcd.print(F("ration button "));
}
#endif

/******************************************
show calibration start
Expand Down

0 comments on commit e1acf73

Please sign in to comment.