when i do rosrun
it is closed by remote host but I have no idea
below code is very simple, and I check pin test, there is no error.
#!/usr/bin/env python
import rospy
import time
import RPi.GPIO as GPIO
from sensor_msgs.msg import JointState
class sensor_relay(object):
def __init__(self, num_relay, gpio_l):
self.n_relay = num_relay
self.motor_name = ['Boom', 'B_roller','MainSail']
self.pub_error = rospy.Publisher("/sensor_indicator", JointState, queue_size=1)
rospy.Subscriber("/relay_control",JointState, self.call_relay)
self.relay_name_pin_num = {'Boom':gpio_l[0], 'B_roller':gpio_l[1],'MainSail':gpio_l[2]}
if name == “main”:
rospy.init_node("u177_relay_control")
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
"""
these relays use 5v in raspberry pi
"""
boom = 26
roller = 6
mainsail = 13
gpio_list = [boom, roller, mainsail]
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)
num_of_relay = 3
try:
sensor_relay(num_of_relay, gpio_list)
except rospy.ROSInterruptException:
pass
rospy.spin()
GPIO.cleanup()