Amarino switching control method problems

I got my first robot working with bluetooth motion control which is great but I would like to be able to switch between motion control and autonomous movement. Preferably I would have it switch with the push of a button, such as p.

I can get it to switch over if I use just a variable to change over. For example if I make a variable called autonomous and set it to true every time I call the moveStop function then it switch's to object avoidance but if I change it to something like incomingByte = Serial.read(); and have an if (incomingByte = '112') 112 being what p comes across as then it wont work at all.

I know incomingByte = Serial.read(); works because when I have my WASD/Obstacle avoidance loaded you can move the bot using WASD and switch it to Obstacle avoidance, just fine.

I've tried setting it 2 ways one where the ObjAve is in the same function as the motion control and one where it is separate. I seem to be able to actually send serial data when its in its own function but it jumps right back out.

Please see attached code. Any advice will be greatly appreciated.

2 function method: https://www.dropbox.com/s/qoc3ytb2f6vef05/OwnFunction.txt Single function method: https://www.dropbox.com/s/7wo363hjoxl5kz8/SingleFunction.txt

but if I change it to something like incomingByte = Serial.read(); and have an if (incomingByte = '112') 112 being what p comes across as then it wont work at all.

Nonsense. '112' is NOT what came across. 112, maybe.

Post your code as an attachment, no using trashbox. I will not access that site - too much chance of getting infected.

Attached

SingleFunction.txt (10.3 KB)

TwoFunctions.txt (10.4 KB)

I think I have found the core of the problem just not sure about the solution. The key press command is getting over written when with the accelerometer information is sent immediately after a key press. Is there away to have the Serial.read() ignore numerical data and pick up only characters? That should solve the problem I think

The key press command is getting over written when with the accelerometer information is sent immediately after a key press.

"key press command"?

Is there away to have the Serial.read() ignore numerical data and pick up only characters?

No. But YOU can discard any value read that is not of the type you want. You can't put them back in the buffer though.

By key press command I mean the data that comes when I push 'a' or any other letter. So as of now the accelerometer send the 3 data points constantly and when I use Serial.Read() to try and catch the 'a' it won't work because the first thing it reads is always a accelerometer rather than the letter. So how can I temporarily strip the coordinates or listen only for a letter?

So as of now the accelerometer send the 3 data points constantly and when I use Serial.Read() to try and catch the 'a' it won't work because the first thing it reads is always a accelerometer rather than the letter. So how can I temporarily strip the coordinates or listen only for a letter?

Does this mean that the accelerometer is a serial device, and that you are using Serial to talk to the accelerometer AND the PC? If so, you need to stop that. The Serial port is meant to talk to ONE device - either the PC or the accelerometer.

The accelerometer is on my phone so its connected via bluetooth to the bot and sends serial data to it. Only the phone and bot are communicating. So it sends a constant stream of accelerometer data from my phone to the bot and I am also trying to send a letter command to change control method(motion or autonomous object avoidance).

So it sends a constant stream of accelerometer data from my phone to the bot and I am also trying to send a letter command to change control method(motion or autonomous object avoidance).

Are you trying to send this “change control method” from your phone, too? If so, your phone app needs some work. It needs to tell the accelerometer to shut the f**k up.

Yes,

I am sending the letter command from my phone aswell. The app is Amarino, which is why I put it in the title. Yeah, I kind of figured I needed the accelerometer to stop sending data but I don't think you can with this app. Guess i'll have to figure out a different way to access accelerometer data and send it.

Will serial.Find() work to pluck just one piece of designated data out of the stream? Like if its sending a stream of accelerometer data I want it to only find the 'a' and ignore the rest.

You posted two codes. Which one are we trying to debug?

The single function code. I have tried it several different ways but single function one seems to get me the closest. In that code I have it set that when stop is called it changes autonomous to true and it will switch over but I am wanting to using serial data for the if condition rather than a variable getting switched everytime I call stop.

When I get home I might upload the 2 function code I am currently working.