]Hallo
nach dem ich endlich durch die Hürden der Verbindung zw. Arduino und Raspberry pi mich durchgewühlt habe kommt ein neues Problem das ich ohne Hilfe nicht bewältigen kann.
Da sich meine Programmierkenntnisse auf die rudimentären Funktion beschränken hoffe ich sehr Ihr könnt mir sicherlich weiterhelfen.
Mein Problem zeichnet sich wie folgt :
Es sind mehr oder weniger 2 Programme zus geführt worden der eine steuert über die Serial2 mein Fahrzeug der andere soll die Servos drehen.
getrennt funktionieren beide Programme sehr gut nur zusammen. kommen die Befehle sehr spät an die Verzögerung kann von 2 sek bis zu 6 -7 sek dauern.
eine Steuerung des Roboters ist so nicht möglich.
hier mein Code :
/*
Front Motor (Steering) => Channel A
Back Motor => Channel B
Since the motor shield hijacks 6 pins for the motors'
control, they are declared in the MotorShieldR3 library.
*/
#include <MotorShieldR3.h>
#include <VarSpeedServo.h>
MotorShieldR3 yellowCar;
#define pinfrontLights 7 //Pin that activates the Front lights.
#define pinbackLights 4 //Pin that activates the Back lights.
char command = 'x';
int velocity = 0;
VarSpeedServo schwenk;
VarSpeedServo kipp;
int t;
int u;
char pos1 ='0';
char pos2 ='0';
char comm[2];
void setup()
{
Serial.begin(9600);
Serial2.begin(9600); //Set the baud rate to that of your Bluetooth module.
//pinMode(pinfrontLights , OUTPUT);
schwenk.attach(40);
kipp.attach(41);
}
void loop(){
while(Serial2.available() > 0){
command = Serial2.read();
//Change pin mode only if new command is different from previous.
//Serial.println(command);
switch(command){
case 'w':
yellowCar.Forward_2W(velocity = 255, velocity = 255);
break;
case 's':
yellowCar.Back_2W(velocity = 254, velocity = 254);
break;
case 'a':
yellowCar.RotateLeft_2W(velocity = 240, velocity = 240 );
break;
case 'd':
yellowCar.RotateRight_2W(velocity = 240, velocity = 240);
break;
case 'x':
yellowCar.Stopped_2W();
break;
case 'b': //Everything OFF
digitalWrite(pinfrontLights, LOW);
digitalWrite(pinbackLights, LOW);
yellowCar.Stopped_2W();
break;
}
}
while (Serial2.available()) {
Serial2.readBytes(comm, 2);
pos1 = comm[0];
Serial2.println(pos1);
pos2 = comm[1];
Serial2.println(pos2);
t = pos1-'0';
t=t*20;
u= pos2 -'0';
u = u*20;
if (t != 9*20)
{ schwenk.slowmove(t,90);
delay(100); }
if (u != 9*20)
{ kipp.slowmove(u,90);
delay(100); }
}
}
Die delay's habe ich schon raus gehabt ohne Erfolg
Ich tippe es liegt an der doppelten Aufruf des readbytes aber wie kann ich das umgehen?
Der eine teil des Prg. wartet auf Zeicheneingabe der andere geht über die Zahlenwerte von 1 bis 8 usw..
Bin für jede Hilfe dankbar
Gruß
Chris