Hi, I am Howard Choi I am trying to raspberry pi with ubiquity robot however I have a serious problem wih error which raspi is shutdown automatically when I use ros such as rospy with GPIO setup.
here is code : I use ir sensor(obstacle avoidance sensor)
but When I connected monitor it is NOT shutdown but in screen there is poped up shutddown ui.
#!/usr/bin/env python
import rospy
import time
import RPi.GPIO as GPIO
from sensor_msgs.msg import JointState
def exec_sensor():
rate = rospy.Rate(10)
while not rospy.is_shutdown():
if not GPIO.input(boom_lt_er):
rospy.loginfo("boom Left errors")
elif not GPIO.input(boom_rt_er):
rospy.loginfo("boom Right errors")
else:pass
rate.sleep()
def call_relay():
pass
if name == “main”:
rospy.init_node("u_177_test_relay_on_off")
pub_error = rospy.Publisher("/sensor_indicator", JointState, queue_size=1)
rospy.Subscriber("/relay_control",JointState, call_relay)
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
"""
these relays use 5v in raspberry pi
"""
boom = 23
roller = 6
mainsail = 13
GPIO.setup(boom, GPIO.OUT)
GPIO.setup(roller, GPIO.OUT)
GPIO.setup(mainsail, GPIO.OUT)
"""
these sensors use 3.3v in raspberry pi
"""
boom_lt_er = 20
boom_rt_er = 21
GPIO.setup(boom_lt_er, GPIO.IN)
GPIO.setup(boom_rt_er, GPIO.IN)
roller_lt_er = 16
roller_rt_er = 12
GPIO.setup(roller_lt_er, GPIO.IN)
GPIO.setup(roller_rt_er, GPIO.IN)
exec_sensor()
rospy.spin()
GPIO.cleanup()