changed valuerange to 255 and tested device

This commit is contained in:
Lukas Bachschwell 2018-04-17 21:57:25 +02:00
parent c01d36fc34
commit 76fb5d0dcf
2 changed files with 69 additions and 106 deletions

View File

@ -8,6 +8,7 @@
#define esc1pin 15
#define esc2pin 13
#define fallbackpin 36
#define failsafeValue 127
Servo esc1;
@ -72,8 +73,8 @@ void setup() {
// Init escs, min and max value similar as Traxxas TQI 1100, 1900
// chanel, minAngel, maxAngel, minPulseWidth, maxPulseWidth
esc1.attach(esc1pin, 0, 0, 180, 1100, 1900);
esc2.attach(esc2pin, 1, 0, 180, 1100, 1900);
esc1.attach(esc1pin, 0, 0, 255, 1100, 1900);
esc2.attach(esc2pin, 1, 0, 255, 1100, 1900);
//Set device in AP mode to begin with
WiFi.mode(WIFI_AP);
@ -103,7 +104,8 @@ void setup() {
void loop() {
if(millis() - lastPacket > CONNECTION_TIMEOUT ) {
isConnected = false;
int failsafeValue = map(analogRead(fallbackpin), 0, 4095, 0, 180);
//int failsafeValue = map(analogRead(fallbackpin), 0, 4095, 0, 180);
// Taking 127 because it should be the center value anyway
writeServos(failsafeValue, failsafeValue);
display.clear();
char buf[25];

View File

@ -36,22 +36,24 @@ const byte numOfSettings = 11;
const float minVoltage = 3.2;
const float maxVoltage = 4.1;
const float refVoltage = 3.3;
// Global copy of slave
esp_now_peer_info_t slave;
#define CHANNEL 3
#define PRINTSCANRESULTS 0
#define DELETEBEFOREPAIR 0
#define HAL_MIN 1290
#define HAL_MAX 2285
#define HAL_CENTER 1785
#define HAL_MIN 1390
#define HAL_MAX 2260
#define HAL_CENTER 1890
#define TRIM_LOW 180
#define TRIM_HIGH 0
//#define pairingMode
#define leverPin 36
#define triggerPin 37
#define batteryMeasurePin 35
#define triggerPin 17
#define batteryMeasurePin 38
// ESPNOW functions ##############################
@ -193,7 +195,7 @@ bool manageSlave() {
// send data
void sendData() {
uint8_t esc1 = map(analogRead(leverPin), HAL_MIN, HAL_MAX, TRIM_LOW, TRIM_HIGH);
uint8_t esc1 = sendThrottle;
uint8_t esc2 = esc1;
const uint8_t data[] = { esc1, esc2 }; // no mixture for the normal mode
@ -252,7 +254,7 @@ void calculateThrottlePosition() {
total += analogRead(leverPin);
}
hallMeasurement = total / 10;
Serial.println(hallMeasurement);
//DEBUG_PRINT( (String)hallMeasurement );
if (hallMeasurement >= HAL_CENTER) {
@ -271,16 +273,13 @@ float batteryVoltage() {
float batteryVoltage = 0.0;
int total = 0;
return 3.6; // for now always full
/*
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 10; i++) {
total += analogRead(batteryMeasurePin);
}
}
batteryVoltage = (refVoltage / 1024.0) * ((float)total / 10.0);
return batteryVoltage;
*/
batteryVoltage = (refVoltage / 4096.0) * ((float)total / 10.0);
Serial.println(batteryVoltage);
return batteryVoltage;
}
// Function used to indicate the remotes battery level.
@ -392,84 +391,47 @@ void drawTitleScreen(String title) {
delay(1500);
}
void drawPage() {
/*
int decimals;
float value;
String suffix;
String prefix;
void drawBoardVoltage() {
int first, last;
int x = 0;
int y = 16;
String suffix = "V";
String prefix = "BATTERY";
float value = 0.0; // TODO: No info this yet, measure in the board
int x = 0;
int y = 16;
// Display prefix (title)
displayString = prefix;
displayString.toCharArray(displayBuffer, 10);
u8g2.setFont(u8g2_font_profont12_tr);
u8g2.drawStr(x, y - 1, displayBuffer);
// Rotate the realtime data each 4s.
if ((millis() - lastDataRotation) >= 4000) {
// Split up the float value: a number, b decimals.
int first = abs(floor(value));
int last = value * pow(10, 3) - first * pow(10, 3);
lastDataRotation = millis();
displayData++;
// Add leading zero
if (first <= 9) {
displayString = "0" + (String)first;
} else {
displayString = (String)first;
}
if (displayData > 2) {
displayData = 0;
}
}
// Display numbers
displayString.toCharArray(displayBuffer, 10);
u8g2.setFont(u8g2_font_logisoso22_tn );
u8g2.drawStr(x + 55, y + 13, displayBuffer);
switch (displayData) {
case 0:
value = ratioRpmSpeed * data.rpm;
suffix = "KMH";
prefix = "SPEED";
decimals = 1;
break;
case 1:
value = ratioPulseDistance * data.tachometerAbs;
suffix = "KM";
prefix = "DISTANCE";
decimals = 2;
break;
case 2:
value = data.inpVoltage;
suffix = "V";
prefix = "BATTERY";
decimals = 1;
break;
}
// Display decimals
displayString = "." + (String)last;
displayString.toCharArray(displayBuffer, 3);
u8g2.setFont(u8g2_font_profont12_tr);
u8g2.drawStr(x + 86, y - 1, displayBuffer);
// Display prefix (title)
displayString = prefix;
displayString.toCharArray(displayBuffer, 10);
u8g2.setFont(u8g2_font_profont12_tr);
u8g2.drawStr(x, y - 1, displayBuffer);
// Split up the float value: a number, b decimals.
first = abs(floor(value));
last = value * pow(10, 3) - first * pow(10, 3);
// Add leading zero
if (first <= 9) {
displayString = "0" + (String)first;
} else {
displayString = (String)first;
}
// Display numbers
displayString.toCharArray(displayBuffer, 10);
u8g2.setFont(u8g2_font_logisoso22_tn );
u8g2.drawStr(x + 55, y + 13, displayBuffer);
// Display decimals
displayString = "." + (String)last;
displayString.toCharArray(displayBuffer, decimals + 2);
u8g2.setFont(u8g2_font_profont12_tr);
u8g2.drawStr(x + 86, y - 1, displayBuffer);
// Display suffix
displayString = suffix;
displayString.toCharArray(displayBuffer, 10);
u8g2.setFont(u8g2_font_profont12_tr);
u8g2.drawStr(x + 86 + 2, y + 13, displayBuffer);
*/
// Display suffix
displayString = suffix;
displayString.toCharArray(displayBuffer, 10);
u8g2.setFont(u8g2_font_profont12_tr);
u8g2.drawStr(x + 86 + 2, y + 13, displayBuffer);
}
void drawSettingsMenu() {
@ -519,11 +481,11 @@ void updateMainDisplay() {
do {
if (changeSettings == true) {
//drawSettingsMenu();
drawSettingsMenu();
drawSettingNumber();
} else {
drawThrottle();
drawPage();
drawBoardVoltage();
drawBatteryLevel();
drawSignal();
}
@ -564,12 +526,12 @@ void setup() {
Serial.println("ESPNowSkate Sender");
u8g2.begin();
drawStartScreen();
/*
if (triggerActive()) {
if (triggerActive()) {
changeSettings = true;
drawTitleScreen("Remote Settings");
}
*/
}
// This is the mac address of the Master in Station Mode
Serial.print("STA MAC: "); Serial.println(WiFi.macAddress());
@ -599,17 +561,6 @@ void loop() {
// Call function to update display and LED
updateMainDisplay();
/* update Value
char buf[10];
sprintf(buf, "%i", map(analogRead(leverPin), HAL_MIN, HAL_MAX, TRIM_LOW, TRIM_HIGH));
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_10x20_tr );
u8g2.drawStr(0, 20, buf);
} while ( u8g2.nextPage() );
*/
calculateThrottlePosition();
if (changeSettings == true) {
@ -633,7 +584,17 @@ void loop() {
if (isPaired) {
// pair success or already paired
// Send data to device
sendData();
/* update Value
char buf[10];
sprintf(buf, "%i", map(analogRead(leverPin), HAL_MIN, HAL_MAX, TRIM_LOW, TRIM_HIGH));
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_10x20_tr );
u8g2.drawStr(0, 20, buf);
} while ( u8g2.nextPage() );
*/
} else {
// slave pair failed