Quick peek at some of the new UltrasonicSensor Service stuff ..
Use 1.0.31+
MRLComm.ino version is 15 (I think) - so you'll probably have to reload it.

THIS HAS NON BLOCKING RANGING WHICH DOESNT INTERFERE WITH SERVOS (YAY TO THAT!)

This is copied from Java code .. so I might not have Python-ized it correctly
 
 
sr04 = Runtime.start("sr04", "UltrasonicSensor")
sr04.attach("COM15", 7, 8) # I quick attach - will create an arduino if necessary
 
def publishRange(myRange):
  print myRange # call back - we will now setup the listener
 
# sr04.arduino.setLoadTimingEnabled(true); # < you can look at the load timings of the duino with this
# sr04.arduino.setLoadTimingEnabled(false);
 
sr04.addPublishRangeListener(python);
#  IMPORTANT - I've added my python service as a listener
# SO I BETTER HAVE a def publishRange(data) somewhere
 
sr04.startRanging() # start raging for 10 seconds
sleep(10)
sr04.stopRanging();
 
# blocking range
myRange = sr04.range()
print myRange
 

 

bhouston

10 years 3 months ago



Can the Ultrasonic sensor be used in place of the PIR sensor? Wondering if it can be configured to power up the robot when something comes within a set range. Also, can it be used as an override to prevent the robot from hitting something?    

 

It "could" be .. here are some differences..

The Ultrasonic Senor has a more narrow field of view.. PIRs are usually designed to have wide field. 
PIR can not do range.. Ultrasonic can
Ultrasonic is effected by sound absorbing materials - e.g. pillows, soft things..  PIR is sensitive to fluctuations in heat..

Yes, obstacle avoidance is a common application

bhouston

10 years 3 months ago

Are there any instructions somewhere to install one on InMoov? I guess a "pin" would have to be available to connect it to.

No instructions as of yet.

Depending on what kind of Ultrasonic sensor you have it might require 2 pins.

1 Trigger pin & 1 Echo pin - this is how the most common SR04 is configured.

kmcgerald

10 years 3 months ago

I got mine working even though there was no 4.000 MHz crystal soldered on the board.  

 

sr04 = Runtime.start("sr04", "UltrasonicSensor")
sr04.attach("/dev/tty.usbmodem1411", 7, 8) # I quick attach - will create an arduino if necessary (comm dev, trigger pin, echo pin)
 
def publishRange(myRange):
  print myRange # call back - we will now setup the listener
 
# sr04.arduino.setLoadTimingEnabled(true); # < you can look at the load timings of the duino with this
# sr04.arduino.setLoadTimingEnabled(false);
 
sr04.addPublishRangeListener(python);
#  IMPORTANT - I've added my python service as a listener
# SO I BETTER HAVE a def publishRange(data) somewhere
 
sr04.startRanging() # start raging for 10 seconds
sleep(10)
sr04.stopRanging();
 
# blocking range
myRange = sr04.range()
print myRange
I updated the comment for the attach to call out what the args were.  The first was obvious but which pin was which took a leap of faith since I was too lazy to look it up. Well it was a Jedi mind trick leap of faith based on Grog saying "1 Trigger pin & 1 Echo pin - this is how the most common SR04 is configured." I took them to be respective of that order and swapped my jumper wires before firing it up.
 

GroG

10 years 3 months ago

In reply to by kmcgerald

Wow ..

It's really nice to hear something is Worky for a change :) 

Thanks KMC .. I appreciate it