Skip to content

Commit

Permalink
ADD: define to change gametrak ADC wirering in software
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Fauth committed Dec 16, 2018
1 parent 95dc493 commit 41a0f4b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
27 changes: 3 additions & 24 deletions Inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,22 @@

#define INACTIVITY_TIMEOUT 8 // minutes of not driving until poweroff. it is not very precise.

// ############################### LCD DEBUG ###############################

//#define DEBUG_I2C_LCD // standard 16x2 or larger text-lcd via i2c-converter on right sensor board cable

// ############################### SERIAL DEBUG ###############################

//#define DEBUG_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuck or lcd) is used!
//#define DEBUG_BAUD 115200 // UART baud rate
//#define DEBUG_SERIAL_SERVOTERM
//#define DEBUG_SERIAL_ASCII // "1:345 2:1337 3:0 4:0 5:0 6:0 7:0 8:0\r\n"

// ############################### INPUT ###############################

// ###### CONTROL VIA UART (serial) ######
//#define CONTROL_SERIAL_USART2 // left sensor board cable, disable if ADC or PPM is used!
// #define CONTROL_BAUD 19200 // control via usart from eg an Arduino or raspberry
// for Arduino, use void loop(void){ Serial.write((uint8_t *) &steer, sizeof(steer)); Serial.write((uint8_t *) &speed, sizeof(speed));delay(20); }

// ###### CONTROL VIA RC REMOTE ######
// left sensor board cable. Channel 1: steering, Channel 2: speed.
//#define CONTROL_PPM // use PPM-Sum as input. disable DEBUG_SERIAL_USART2!
//#define PPM_NUM_CHANNELS 6 // total number of PPM channels to receive, even if they are not used.

// ###### CONTROL VIA TWO POTENTIOMETERS ######
// ADC-calibration to cover the full poti-range: connect potis to left sensor board cable (0 to 3.3V) (do NOT use the red 15V wire in the cable!). see <How to calibrate>. turn the potis to minimum position, write value 1 to ADC1_MIN and value 2 to ADC2_MIN. turn to maximum position and repeat it for ADC?_MAX. make, flash and test it.
//#define CONTROL_ADC // use ADC as input. disable DEBUG_SERIAL_USART2!
//#define ADC1_MIN 0 // min ADC1-value while poti at minimum-position (0 - 4095)
//#define ADC1_MAX 4095 // max ADC1-value while poti at maximum-position (0 - 4095)
//#define ADC2_MIN 0 // min ADC2-value while poti at minimum-position (0 - 4095)
//#define ADC2_MAX 4095 // max ADC2-value while poti at maximum-position (0 - 4095)

// ###### TRANSPOTTER FIRMWARE #######
#define CONTROL_GAMETRAK
#define SUPPORT_LCD
#define SUPPORT_NUNCHUCK
//#define SUPPORT_REMOTE

#define GAMETRAK_CONNECTION_NORMAL // for normal wireing accoring to the wiki Instructions
//#define GAMETRAK_CONNECTION_ALTERNATE // use this define instead if you messed up the gametrak ADC wirering (steering is speed, and length of teh wire is steering)

#define ROT_P -1.2 // P coefficient for the direction controller. Positive / Negative values to invert gametrak steering direction.
#define FILTER 0.1 // lower value == softer filter. do not use values <0.01, you will get float precision issues.

Expand Down
8 changes: 7 additions & 1 deletion Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,15 @@ int main(void) {




#ifdef GAMETRAK_CONNECTION_NORMAL
uint16_t distance = CLAMP((adc_buffer.l_rx2) - 180, 0, 4095);
steering = (adc_buffer.l_tx2 - 2048) / 2048.0;
#endif
#ifdef GAMETRAK_CONNECTION_ALTERNATE
uint16_t distance = CLAMP((adc_buffer.l_tx2) - 180, 0, 4095);
steering = (adc_buffer.l_rx2 - 2048) / 2048.0;
#endif

feedforward = ((distance - (int)(setDistance * 1345)));
if (nunchuck_connected == 0) {
speedL = speedL * 0.8f + (CLAMP(feedforward + ((steering)*((float)MAX(ABS(feedforward), 50)) * ROT_P), -850, 850) * -0.2f);
Expand Down

0 comments on commit 41a0f4b

Please sign in to comment.