2017년 3월 27일 월요일

Run time error when creating sonar using Arduino ultrasonic sensor and app inventors


I'm trying to create sonar using Arduino ultrasonic sensor and app inventors. I'm running into a huge problem.
I'm trying to draw points on the canvas based on reading from ultrasonic sonar, I'm getting data from sonar using Bluetooth. But sometimes Bluetooth is passing 2 values next to each other resulting in the runtime error. How can I catch this error or is there ay another way to avoid this? 

--
Your circle centerY is trying to use global value distance which is set to [52 52] butit should be a number.
You need to extract the value as number.

-- 
How can I do that? When I try to receive signed/unsignedbyte number it receiving random number totally from to the ones on arguing console 

-- 
the value in the local variable distance is changing every 250 ms. It's getting this data from Arduino, but from time to time its passing 2 numbers instead of just one 

-- 
You need to send each number with a delimiter, 
typically using println(), and tell AI2 to pull in only
one message at a time by watching for that delimiter.

The Designer BlueTooth component has a Delimiter attribute,
which you can set to 10 (decimal of LF),
and the BlueToothClient.ReceiveText block should ask for -1 bytes,
which should deliver exactly one message.

Expect  some lag as the messages pile up in an AI2 buffer
if you are reading much slower than your Arduino is transmitting.

That's the price to pay for the Delimiter convenience.

-- 
thanks for replay. Wow that sound good, unfortunately I don't understand how to set this up. Could you try to explain how to set it up please. Much appreciate 

-- 
THANK YOU very much Its worked fine!. Understand what you meant. I did what you have suggested. In designer tab I put Bluetooth Delimiter attribute to 10 and set to receive bites by -1,. HoweverI had to change the speed of sending data and clock interval to 500 from 250 miliseconds in order to stop drawing wrong circles. Is there any other method of achieving this without slowing down sending of data ? 
-- 
Understand what you mean by lag now it is noticeable. The object has to be in front of sonar for at least 3 seconds in order to draw the circle in the different point. this is working solution but the project I'm doing should catch the fast moving object that is passing through the ultrasonic sonar. Any other suggestions ? 

-- 
Regarding the lag, it can be made visible on the AI2 side by copying the BytesAvailable value to a label.Text.

Maybe if it gets too high, the AI2 Clock could be speeded up to lower the backlog,
either manually by slider or automatically by some kind of sofwate feedback loop.

-- 
I looked closer at your blocls.
Did you lose the Bytes Available > 0 test?

You need to have

IF Connected then
    Say Connected
    IF Bytes Avaliable > 0 then
       Receive -1 bytes and process it
       ...
Else
  Say Disconnected

in your Timer.

-- 
Thank you very much mate you deserve a beer! I did what you said I put to set the label to byte available to receive. I notice that it keep growing by 4 until 128. Meaning that its loading buffer with data that's why it was very slow to receive correct data. Then I created if else function to check if bytes available to receive are > 4 and if so to set times to 100 else to 250. I notice that It was working but circles were drawn in kind of lag matter. (like it draw 5 circles smoothly and then wait for a bit and draw another 5). So I got read of if else function and just change the clock timer to 200. So my Arduino send data every 250 ms and app clock goes every 200 ms. That way there is no buffer overload and circles are drawn smoothly. 

-- 
Thanks for the feedback!

The AI2 docs don't discuss the buffering that happens behind the scenes when 
a Delimiter is used, and there's not much discussion out there about how to set
relative clock frequencies on the sending and receiving sides.

-- 

댓글 없음:

댓글 쓰기