Browse Source

Now everything works as expected.

master
nickg 5 years ago
parent
commit
ecd158439b
  1. 5
      Code/miniRobot/miniRobot.ino
  2. 21
      Code/miniRobot/temperatureDistance.ino
  3. 3
      Code/miniRobotRC/_main.ino
  4. 28
      Code/miniRobotRC/fahrsteuerung_old.ino
  5. 29
      Code/miniRobotRC/temp.ino

5
Code/miniRobot/miniRobot.ino

@ -77,7 +77,7 @@ void setup() {
//Temperatur- und Abstandsmessung //Temperatur- und Abstandsmessung
setEchoPins(16, 6); //16: A2, 6: D6
setEchoPins(A2, 6); //16: A2, 6: D6
tempDistSetup(); tempDistSetup();
timer = millis(); timer = millis();
} }
@ -94,7 +94,6 @@ void loop() {
temperature = dallas(4, 0); temperature = dallas(4, 0);
measureDistance(); measureDistance();
distance = calculateDistance(); distance = calculateDistance();
Serial.println(distance);
timer = currentMillis; timer = currentMillis;
} }
@ -194,10 +193,12 @@ void commandInterpretation() {
forwardB = true; forwardB = true;
driveOn = false; */ driveOn = false; */
break; break;
} }
} }
} }
clearCommands(); clearCommands();
} }

21
Code/miniRobot/temperatureDistance.ino

@ -5,29 +5,31 @@
int trig; int trig;
int echo; int echo;
uint16_t distance3 = 0;
uint16_t distance2 = 0;
unsigned long distance3 = 0;
unsigned long distance2 = 0;
//ISR for PCINT20
//ISR for PCINT2
ISR(PCINT2_vect) { ISR(PCINT2_vect) {
distance3 = pulseIn(echo, HIGH); distance3 = pulseIn(echo, HIGH);
if(distance3 > 0){ if(distance3 > 0){
distance2 = distance3; distance2 = distance3;
} }
delayMicroseconds(10);
PCICR &= ~0b00000100;
PCICR &= ~0b00000111;
PCMSK2 &= ~0b00010000; PCMSK2 &= ~0b00010000;
delayMicroseconds(10);
} }
void setEchoPins(int pin1, int pin2){ void setEchoPins(int pin1, int pin2){
trig = pin1; trig = pin1;
echo = pin2; echo = pin2;
} }
int16_t calculateDistance(){ int16_t calculateDistance(){
int16_t result2 = distance2/ 58;
int16_t result2 = (int16_t)(((float) distance2/ 58.0));
if(result2 > maxDistance){ if(result2 > maxDistance){
result2 = maxDistance; result2 = maxDistance;
} }
@ -43,8 +45,10 @@ void measureDistance(){
// ... put the trigger down ... // ... put the trigger down ...
digitalWrite(trig, LOW); digitalWrite(trig, LOW);
Serial.println("messe...");
PCICR |= 0b00000100; PCICR |= 0b00000100;
PCMSK2 |= 0b00010000;
PCMSK2 |= (1 << echo);
} }
@ -89,7 +93,6 @@ void tempDistSetup(){
// Reset the trigger pin and wait a half a second // Reset the trigger pin and wait a half a second
digitalWrite(trig, LOW); digitalWrite(trig, LOW);
delayMicroseconds(500); delayMicroseconds(500);
Serial.println(echo);
sei(); sei();

3
Code/miniRobotRC/_main.ino

@ -23,14 +23,17 @@ void loop() {
while(!tasten.getButtonCycle(buttonStart)) { while(!tasten.getButtonCycle(buttonStart)) {
manualDigitalDrive(); manualDigitalDrive();
updateTemp();
} }
tasten.clearButton(buttonStart); tasten.clearButton(buttonStart);
while(!tasten.getButtonCycle(buttonStart)){ while(!tasten.getButtonCycle(buttonStart)){
motorMapping(); motorMapping();
updateTemp();
} }
tasten.clearButton(buttonStart); tasten.clearButton(buttonStart);
while(!tasten.getButtonCycle(buttonStart)){ while(!tasten.getButtonCycle(buttonStart)){
joystickSteuerung(); //TODO () joystickSteuerung(); //TODO ()
updateTemp();
} }
tasten.clearButton(buttonStart); tasten.clearButton(buttonStart);

28
Code/miniRobotRC/fahrsteuerung_old.ino

@ -50,34 +50,6 @@ void manualDigitalDrive() {
goOn = false; goOn = false;
} }
//Temperatur <3
unsigned long currentMillis = millis();
if((unsigned long)(currentMillis - temp_time) >= 1000){ // jede Sekunden
temp_time = millis();
bool err = false;
clearCommands();
commands[0] = getTemp;
radio.write(&commands, sizeof(commands) && !err);
unsigned long start = micros();
radio.startListening();
while(!radio.available()){
//Serial.println("nix");
unsigned long currentMicros = micros();
if((unsigned long)(currentMicros - start) >= 1){
err = true;
}
}
if(!err){
int16_t readData;
radio.read(&readData, sizeof(int16_t));
temperature = readData;
}
radio.stopListening();
clearCommands();
}
// } // }
// tasten.clearAllButtons(); // tasten.clearAllButtons();
} }

29
Code/miniRobotRC/temp.ino

@ -0,0 +1,29 @@
//Temperatur <3
void updateTemp(){
unsigned long currentMillis = millis();
if((unsigned long)(currentMillis - temp_time) >= 1000){ // jede Sekunden
temp_time = millis();
bool err = false;
clearCommands();
commands[0] = getTemp;
radio.write(&commands, sizeof(commands) && !err);
unsigned long start = micros();
radio.startListening();
while(!radio.available()){
//Serial.println("nix");
unsigned long currentMicros = micros();
if((unsigned long)(currentMicros - start) >= 1){
err = true;
}
}
if(!err){
int16_t readData;
radio.read(&readData, sizeof(int16_t));
temperature = readData;
}
radio.stopListening();
clearCommands();
}
}
Loading…
Cancel
Save