Ask Your Question

Tufte's profile - activity

2019-07-10 23:43:48 -0600 received badge  Notable Question (source)
2019-06-10 19:51:28 -0600 commented question Building failed. Running ./RedistMaker

I see, I'll try that. Thx

2019-06-06 06:38:54 -0600 received badge  Famous Question (source)
2019-06-06 06:38:54 -0600 received badge  Notable Question (source)
2019-06-06 06:38:54 -0600 received badge  Popular Question (source)
2019-05-31 17:00:15 -0600 asked a question Building failed. Running ./RedistMaker

Building failed. Running ./RedistMaker Trying to install OpenNI to use Xbox Kinect camera. But when I follow the guide

2019-05-28 22:56:28 -0600 received badge  Popular Question (source)
2019-05-28 14:01:19 -0600 received badge  Supporter (source)
2019-05-28 14:01:15 -0600 marked best answer Node stuck on endless loop


Hi. I'm running a Raspberry 3+ with ROS and a CamJam Edu kit 3. This has a Audio/Echo locator (HC-SR04). The program below is the python file for calculating and publishing the distance in front of the robot. When I run this trough the launch file. And then try to stop it (Ctrl+C, Ctrl+Z). The rest of my program, pubs/subs/etc stops, but this file keeps on going on an endless loop, printing out the distance. And it does not show up in rosnode list, so I can't kill it. The only thing I find to work is to reboot my R-pi, by pulling the plug. Any good ideas of what I might be doing wrong?

#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
import rospy
from sensor_msgs.msg import Range

#set GPIO Pins

#set GPIO direction (IN / OUT)

def distance():
    # set Trigger to HIGH
    GPIO.output(GPIO_TRIGGER, True)

    # set Trigger after 0.01ms to LOW
    GPIO.output(GPIO_TRIGGER, False)

    StartTime = time.time()
    StopTime = time.time()

    # save StartTime
    while GPIO.input(GPIO_ECHO) == 0:
        StartTime = time.time()

    # save time of arrival
    while GPIO.input(GPIO_ECHO) == 1:
        StopTime = time.time()

    # time difference between start and arrival
    TimeElapsed = StopTime - StartTime
    # multiply with the sonic speed (34300 cm/s)
    # and divide by 2, because there and back
    distance = (TimeElapsed * 34300) / 2

    return distance

if __name__ == '__main__':
    soundPub = rospy.Publisher('/distance', Range, queue_size=1)
    pub_range = Range()
        while True:
            dist = distance()
            pub_range.range = dist
            print("Distance: %.1f cm" % pub_range.range)
            #print ("Measured Distance = %.1f cm" % dist)

        # Reset by pressing CTRL + C
    except KeyboardInterrupt:
        print("Measurement stopped by User")
2019-05-28 14:01:15 -0600 received badge  Scholar (source)
2019-05-28 13:59:29 -0600 commented answer Node stuck on endless loop

Great. Just tried it out. Works perfectly. Thank you so much!

2019-05-28 13:53:05 -0600 commented answer Node stuck on endless loop

Thank you for the quick reply. I see, so where do i need that line? instead of "try" or the over the function call?

2019-05-28 13:17:48 -0600 asked a question Node stuck on endless loop

Node stuck on endless loop ///////////////////////////////////////////////////////////////////////////////////////////