SimpleBot with Touch sensor


#1

Hello, I would like to put a touch sensor on my SimpleBot robot to detect walls. Where should I test in the code if the button is enabled? i have a similar Simplebot_simple.py code on GitHub.
I would like if I touch a wall, back for 2 seconds, turn 90 degrees and continue my program.
How it s possible ?

Sorry for my english, I speak french. I hope that you understand me anyway


#2

Hi triwey,
Can you send a link of the touch sensor that you are going to use. Also, can you send a link to your code on github that you are going to use.

-Karan


#3

hello,
i use this sensor ( Sensor ). And i want use this code ( code )


#4

That particular sensor uses this code example:

https://github.com/DexterInd/BrickPi_Python/blob/master/Sensor_Examples/LEGO-Touch_Sensor_Test.py

So you would just merge that code (for the sensor) into the simplebot code you have linked.

Best, John


#5

yes but I wonder how always test the distance between the robot and the wall. I would need this information all the time no card only once in the program
Do you understand what I mean?


#6

You can add the code to read the sensor each time in the loop here: https://github.com/DexterInd/BrickPi_Python/blob/master/Project_Examples/simplebot/simplebot_simple.py#L60-L74 . Whener the robot touched the wall, tha touch sensor would be pressed and you’ll see it go from 0 to 1 in the loop. You can take further actions depending on the output of the sensor.

-Karan