def main(): # instantiate the distance object #sensor = DistanceSensor() my_sensor = EasyDistanceSensor() #sensor.start_continuous() rospy.init_node("distance_sensor") pub_distance = rospy.Publisher("~distance", Range, queue_size=10) msg_range = Range() msg_range.header.frame_id = "distance" msg_range.radiation_type = Range.INFRARED msg_range.min_range = 0.02 msg_range.max_range = 3.0 rate = rospy.Rate(rospy.get_param('~hz', 1)) while not rospy.is_shutdown(): # read distance in meters read_distance = my_sensor.read() / 100.0 msg_range.range = read_distance # Add timestamp msg_range.header.stamp = rospy.Time.now() # Print current distance print msg_range.range * 1000, " mm" # Publish distance message pub_distance.publish(msg_range) rate.sleep()
def __init__(self, addr=8, detect=True): gopigo3.GoPiGo3.__init__(self) self.scan_data = {} # mutex sensors on IC2 self.distance_sensor = EasyDistanceSensor(port="RPI_1", use_mutex=True) self.imu = inertial_measurement_unit.InertialMeasurementUnit(bus="RPI_1") # use_mutex=True # buffer for reading the gyro self.gyro_buffer = 0 self.stop()
#!/usr/bin/env python # # https://www.dexterindustries.com # # Copyright (c) 2017 Dexter Industries # Released under the MIT license (http://choosealicense.com/licenses/mit/). # For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md # # Python example program for the Dexter Industries Distance Sensor from __future__ import print_function from __future__ import division # import the modules from di_sensors.easy_distance_sensor import EasyDistanceSensor from time import sleep # instantiate the distance object my_sensor = EasyDistanceSensor() # and read the sensor iteratively while True: read_distance = my_sensor.read() print("distance from object: {} mm".format(read_distance)) sleep(0.1)
from di_sensors.easy_distance_sensor import EasyDistanceSensor import time import rospy from geometry_msgs.msg import Twist if __name__ == '__main__': rospy.init_node("runnerDistanceNode") pub = rospy.Publisher("runnerDistance", Twist, queue_size=3) my_sensor = EasyDistanceSensor(address=0x2a, use_mutex=False) rate = rospy.Rate(10) while not rospy.is_shutdown(): read_distance = my_sensor.read() data = Twist() data.linear.x = read_distance / 100 pub.publish(data) rospy.loginfo(f"Distance: {read_distance/100}m") rate.sleep()
def __init__(self): super().__init__() self.imu = InertialMeasurementUnit(bus="GPG3_AD1") self.ds = EasyDistanceSensor()
# Copyright (c) 2017 Dexter Industries # Released under the MIT license (http://choosealicense.com/licenses/mit/). # For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md # # Python example program for the Dexter Industries Temperature Humidity Pressure Sensor from __future__ import print_function from __future__ import division # do the import stuff from di_sensors.easy_distance_sensor import EasyDistanceSensor from time import time, sleep from threading import Thread, Event, get_ident # instantiate the distance object my_sensor = EasyDistanceSensor(use_mutex = True) start_time = time() runtime = 2.0 # create an event object for triggering the "shutdown" of each thread stop_event = Event() # target function for each thread def readingSensor(): while not stop_event.is_set(): thread_id = get_ident() distance = my_sensor.read() print("Thread ID = {} with distance value = {}".format(thread_id, distance)) sleep(0.001) # create an object for each thread thread1 = Thread(target = readingSensor)
import urllib2 import base64 import picamera import json from subprocess import call import time import datetime import atexit from googleapiclient import discovery import google.auth from easygopigo3 import EasyGoPiGo3 from di_sensors.easy_distance_sensor import EasyDistanceSensor gpg = EasyGoPiGo3() button = gpg.init_button_sensor("AD1") # button on GoPiGo3's AD1 port ds = EasyDistanceSensor() # distance sensor on I2C port atexit.register(gpg.stop) # If we exit, stop the motors #Calls the Espeak TTS Engine to read aloud a sentence # This function is going to read aloud some text over the speakers def sound(spk): # -ven+m7: Male voice # The variants are +m1 +m2 +m3 +m4 +m5 +m6 +m7 for male voices and +f1 +f2 +f3 +f4 which simulate female voices by using higher pitches. Other variants include +croak and +whisper. # Run the command espeak --voices for a list of voices. # -s180: set reading to 180 Words per minute # -k20: Emphasis on Capital letters # to enable audio output on the audio jack # otherwise, instead of one, select 2 for HDMI or 0 for automatic