I added a function called circle() to the main program that came with the smart bat car. The important thing is to make move slower a wheel than the other. In this case the left wheel goes to 2/3 the speed of the right. So robot makes a circle. control variable in code, is the speed in general.
/*NOVELTY!*/
void circle ()
{
int slow;
// right motor back off
digitalWrite(Right_motor_back, LOW);
analogWrite(Right_motor_go, control); // PWM--Pulse Width Modulation(0~255) control speed
// left motor go ahead
digitalWrite(Left_motor_back, LOW);
slow = (int)(control * 2 / 3);//without decimals
analogWrite(Left_motor_go, slow); // PWM--Pulse Width Modulation(0~255) control speed
//speed of left wheel is two thirds of right wheel
}
Second, I incorporated a function that reads the level of attention of the brain from the mindwave mobile 2 EEG (ElectroEncephaloGraphy. The value of attention comes to the robot through (classic) bluetooth. There is a bluetooth module in the headset reader of electric waves and another master HC-05 that I substituted instead of the HC-06 slave that came with the smart bat car robot.
#define MINDWAVE_BAUD 57600
// checksum variables
byte generatedChecksum = 0;
byte checksum = 0;
int payloadLength = 0;
byte payloadData[64] = {
0};
byte poorQuality = 0;
byte attention = 0;
boolean bigPacket = false;
// Read data from Serial UART //
byte ReadOneByte() {
int ByteRead;
while(!Serial.available());
ByteRead = Serial.read();
return ByteRead;
}
void mindwaveAttent(){
// Look for sync bytes
if(ReadOneByte() == 170)
{
if(ReadOneByte() == 170)
{
payloadLength = ReadOneByte();
if(payloadLength > 169) //Payload length can not be greater than 169
return;
generatedChecksum = 0;
for(int i = 0; i < payloadLength; i++)
{
payloadData[i] = ReadOneByte(); //Read payload into memory
generatedChecksum += payloadData[i];
}
checksum = ReadOneByte(); //Read checksum byte from stream
generatedChecksum = 255 - generatedChecksum; //Take one's compliment of generated checksum
if(checksum == generatedChecksum)
{
poorQuality = 200;
attention = 0;
for(int i = 0; i < payloadLength; i++)
{ // Parse the payload
switch (payloadData[i])
{
case 2:
i++;
poorQuality = payloadData[i];
bigPacket = true;
break;
case 4:
i++;
attention = payloadData[i];
break;
case 5:
i++;
break;
case 0x80:
i = i + 3;
break;
case 0x83:
i = i + 25;
break;
default:
break;
} // switch
} // for loop
if(bigPacket && poorQuality == 0)
mindwaveSpeed(attention); //changes the wheels speed and commands circles
bigPacket = false;
}
else
{
//Checksum Error
} // end if else for checksum
} // end if read 0xAA byte (170 en binario)
} // end if read 0xAA byte
}
Third, I passed this attention value to another function, that converts it in speed of the wheels. That is, it changes the value of the control variable. And it sends a command to do circles. Incorporate this code on the main program:
//changes the wheels speed and commands circles
void mindwaveSpeed(int attention){
control = map(attention, 0, 100, 175, 270); //it is very rare achieve the top attention
if (control > 255)
control = 255;
newLineReceived = true; //send a command
inputString = "$7#"; //circles
}
Then we incorporate the function mindwaveAttent() into the loop()
void loop()
{
mindwaveAttent();
Bluetooth();
// Switch different mode
if (g_AllState == 0 && g_modeSelect == 1)
track();
CarControl();
}
Last there is necessary to configure HC-05 module. I do it by means of a USB to serial TTL converter cable and pressing the button incorporated on the module. It was setup as master and auto-connect.
Possible betteringsProving something similar with new kind of robots.
If you have liked this post, please consider to donate so we can go on.
Si te ha gustado nuestros proyectos, cosidera donar, para que podamos continuar.
Comments