ADD: define to change gametrak ADC wirering in software

This commit is contained in:
Niklas Fauth
2018-12-16 09:58:14 +01:00
parent 95dc4938cf
commit 41a0f4b72d
2 changed files with 10 additions and 25 deletions

View File

@@ -39,10 +39,6 @@
#define INACTIVITY_TIMEOUT 8 // minutes of not driving until poweroff. it is not very precise. #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 ############################### // ############################### SERIAL DEBUG ###############################
//#define DEBUG_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuck or lcd) is used! //#define DEBUG_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuck or lcd) is used!
@@ -50,32 +46,15 @@
//#define DEBUG_SERIAL_SERVOTERM //#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" //#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 ####### // ###### TRANSPOTTER FIRMWARE #######
#define CONTROL_GAMETRAK #define CONTROL_GAMETRAK
#define SUPPORT_LCD #define SUPPORT_LCD
#define SUPPORT_NUNCHUCK #define SUPPORT_NUNCHUCK
//#define SUPPORT_REMOTE //#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 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. #define FILTER 0.1 // lower value == softer filter. do not use values <0.01, you will get float precision issues.

View File

@@ -335,9 +335,15 @@ int main(void) {
#ifdef GAMETRAK_CONNECTION_NORMAL
uint16_t distance = CLAMP((adc_buffer.l_rx2) - 180, 0, 4095); uint16_t distance = CLAMP((adc_buffer.l_rx2) - 180, 0, 4095);
steering = (adc_buffer.l_tx2 - 2048) / 2048.0; 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))); feedforward = ((distance - (int)(setDistance * 1345)));
if (nunchuck_connected == 0) { if (nunchuck_connected == 0) {
speedL = speedL * 0.8f + (CLAMP(feedforward + ((steering)*((float)MAX(ABS(feedforward), 50)) * ROT_P), -850, 850) * -0.2f); speedL = speedL * 0.8f + (CLAMP(feedforward + ((steering)*((float)MAX(ABS(feedforward), 50)) * ROT_P), -850, 850) * -0.2f);