I've made a simple python program to simulate the earbot, testing out just the very basic function of taking in a difference of time and outputting an angle.
So here's the code:
__author__ = 'JangoJungle'
"""Earbot test program
This program is the basic model of an earbot. Enter a small difference in time
and it will output what angle the sound came from, how far it has to turn and
in which direction, and it's new position.
"""
from numpy import *
# initialize variables
current_angle = 0
length = .1524 # this is approximately 6 inches in meters
time_constant = length/340.29 # length of time for sound to travel the full .1524 meters distance
# get the difference in time
while True:
delta_T = input('Please input the difference of time, a number between -0.00044785 and 0.00044785: \n(use negative sign to denote direction)\n')
# test for validity: the absolute value of delta_T should never be greater than time_constant
if abs(delta_T) > time_constant:
print ('Invalid time difference!')
continue
# calculate where to go
x = delta_T/time_constant
angle = arcsin(x)*180/pi
print ("The angle the sound came from is %s." % angle)
# go there/update position
current_angle += angle
if current_angle > 180:
current_angle -= 180
elif current_angle < 0:
current_angle += 180
print ("My new angle is %s." % current_angle)
So just a couple notes:
- this program does not distinguish between a sound from the front and a sound from behind. For simplicity's sake, I'm leaving it that way until I know the robot is built.
- In hindsight, it would have been simpler to make the time constant an integer, but this still shows the function well enough.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.