Running a SR04 ultrasonic sensor in my script, connected to a 3rd Arduino Uno (my test board). Still getting some ComPort error if I connect it to the mega. Looks like a simple issue but I didn´t had time to look at it so far. Measuring by hand the distance wasn´t correct. Multiplying the value with the factor 1.25 is delivering true results now.

This is the sensor part:

python = Runtime.start("python","Python")
sr04 = Runtime.start("sr04", "UltrasonicSensor")
sr04.attach(testPort, 9, 10)
sr04.addRangeListener(python)
def onRange(distance):
   print "distance to next object ", distance*1.25, " cm"
   if (distance <= 15) and (distance >= 1):
      sr04.stopRanging()
      i01.mouth.audioFile.playFile("G:/knowledge/fx/distance.mp3", False)
      sleep(0.4)
      i01.mouth.speakBlocking("keep safety distance")
      print "stopped, only ", distance*1.25, " cm to next object"
      sr04.startRanging()

 

 

bhouston

10 years 1 month ago

Nice work Masta, Thanks for sharing the script.

Mastablasta

10 years 1 month ago

In reply to by bhouston

You'd probably need 4 of the SR04 to cover all sides. Also I left the mouth.speak away, just the mp3 sound which is enough. There are lots of funny sounds around. I did this because if you stay in that "safety zone" he gets values and keeps on talking. The "and" for setting the 2 values was necessary as there is a "0" coming up here and there.

If I have any news I will post them.

I hooked up the 2 dc motors to the same Arduino and keep on getting the same error about the ports. My script for the sensor is blocking the "testPort" (COM11 in this case) on that port somehow. I´d like to keep using this 3rd Arduino. Got a hint for me?

GroG

10 years 1 month ago

In reply to by Mastablasta

Yep, 

Your onto another level of MRL.  You've moved on to MRL's  DNA - (Description of Neighboring Automata) 
UltrasonicSensor & InMoov are both Composite Services - they contain peers.  

What you want to do is merge 2 Peers together (sr04.arduinio with i01.left or i01.right)

So this is messing with their definition .. like messing with their DNA...

With a single line you can change the name of the sr04' arduino so it will merge with InMoov's i01.left .. they will both "share" the same Arduino - so there should not be any port in use exception..

You can merge any and all peers, creating variation mutants 

 

Thanks for the help GroG.

This is what I´m using and what I get as a result, looks ok but the sensor isn´t sensoring. I keep on getting only "0 cm".

 

Works for me using the following:

AdolphSmith

10 years 1 month ago

In reply to by Mastablasta

Check if part looks ok then if something short i change. And if ok i split for printing