Percy has some new working eyes. His HC-SR04 ultrasonic sensors are fitted and working. Picaxe code below. Here is the B4A code: http://jimsrobot.com/download/2013/02/PercyRobot.zip
As an overview of the results so far testing them:
- The picaxe allows you to connect the 2 middle pins of the HC-SR04 with a 1K8 resistor and send a pulse and read the pulse back from the same pin. In the pics below I’ve soldered and heat shrunk the resistors into place.
- The sensors would be great with a backing plate, I used heat glue to stick on a flexible piece of plastic.
- While the sensors work on the bench, the mission critical “don’t crash” bit isn’t so good.
- Percy has 2 sensors (leftish and rightish) , but will probably end up with 4 (leftish, forward, rightish and don’t fall off the edge)
- Couches and soft furnishings don’t reflect the sound – crash
- Chair legs seem to be too narrow to work properly – crash
Also i2c has been replaced with UART/Serial as the i2c crashed, maybe due to a race condition. The asynch serial actually uses less processing power on the Android, which is paramount for decision making as the complexity of the navigation grows. Getting the data has dropped from 10ms to 2ms.
I have a dream of building a laser range finder to go with Percy, but I’m waiting on the camera component to try to get that to work.
BTW, the code as it stands is attached above or in snippets below these pictures.
The picaxe code with serial/uart link and averaging.
#no_table 'Speed up the programming time
HSERSETUP B115200_8, %00101
symbol PINRIGHT = c.2
symbol PINLEFT = c.1
symbol DATAIN = w0
symbol LDATA_ADD = w1
symbol RDATA_ADD = w2
symbol COUNTER = b10
main:
let RDATA_ADD = 0
let LDATA_ADD = 0
for COUNTER = 0 to 5
'Right hand sensor
High PINRIGHT 'trigger the HC-SR04 ultrasonic
Pulsin PINRIGHT, 1, DATAIN 'get the distance reading
let DATAIN = DATAIN / 11
'Clean the data
if DATAIN > 124 then
let DATAIN = 124
end if
if DATAIN < 0 then
let DATAIN = 0
end if
let RDATA_ADD = RDATA_ADD + DATAIN 'My Ebay sensor is calibrated to x 11
pause 5
'Left hand sensor
High PINLEFT 'trigger the HC-SR04 ultrasonic
Pulsin PINLEFT, 1, DATAIN 'get the distance reading
let DATAIN = DATAIN / 11
'Clean the data
if DATAIN > 124 then
let DATAIN = 124
end if
if DATAIN < 0 then
let DATAIN = 0
end if
let LDATA_ADD = LDATA_ADD + DATAIN 'My Ebay sensor is calibrated to x 11
pause 5
next
let RDATA_ADD = RDATA_ADD / 5
let LDATA_ADD = LDATA_ADD / 5
hserout 0, (b2, b4)
debug
goto main
Here is the connection code in the IOIO (VB4Android) – but also you need the navigation etc in the code.
Sub ReadFromUART
'uart order is is rx,spec,tx,spec,baud,pariy,stop
Dim sSin As InputStream
sSin=SER.InputStream
If sSin.BytesAvailable > 0 Then
Dim bufferin(sSin.BytesAvailable) As Byte
Dim count As Int
count = sSin.ReadBytes(bufferin,0, bufferin.Length)
If count = 2 Then
iDistanceRight = bufferin(0) : iDistanceLeft = bufferin(1)
lblright.Text = iDistanceRight
lblLeft.Text = iDistanceLeft
Else
lblMessage.Text = "Poor Read"
NewServiceMessage("Poor serial read" , "", 1, 500)
'ReadFromUART
End If
End If
End Sub