Page 1 of 1

Sensor data

PostPosted: Sun May 24, 2015 5:25 pm
by kevcook
I've managed to get a Sharp infrared (analogue) sensor and it works according to the sensor example. However I want to just get this data on it's own. I'm lost. I've tried analogRead() etc but cannot seem to get it. I need some help with the code to (a) get the data from A2, (b) display the data, (c) the code to compare the data to a set variable. i.e if A2 reading > than 200 then Action etc etc. This is for use in an object collision python program. If any one could even direct me to where this is clearer than currently shown in the camera robot tutorial which displays ALL sensors in a loop.
I appreciate this is pretty basic stuff.

Re: Sensor data

PostPosted: Mon May 25, 2015 4:24 pm
by danijazz
There are several ways you could do this. One way is to take the robot_sensor_test.py and copy it. Comment out everything not needed and use. data[0] is A0, data[1] A1 etc.
while True:

miniDriver.setSensorConfiguration( sensorConfiguration )

miniDriver.update()
sys.stdout.write ("{0} ".format(miniDriver.getAnalogReadings().data[2]))
sys.stdout.flush()
time.sleep( 0.1 )

To do the comparison you could use if (miniDriver.getAnalogReadings().data[2] > 200)

Re: Sensor data

PostPosted: Mon May 25, 2015 6:40 pm
by kevcook
Thanks alot. Very useful and makes sense of it all! Got it working now (well best I can!), just need to flesh it out and tidy it up.
Thanks again.