how to use ros_arduino.py

asked 2022-03-22 10:21:20 -0600

madtech gravatar image

updated 2022-03-25 10:42:57 -0600

miura gravatar image

hello Guys, my bveeta robot using the ros_arduino_bridge package to read the output from Arduino Mega board.

However, i am trying to read temperature sensor LM35 from AnalogPin 13 on Arduino Mega. I try to look for the example in the forum but there is no example i found.

There is the Node name "arduino_node.py" inside "ros_arduino_python" package

    # Initialize any sensors
    self.mySensors = list()

    sensor_params = rospy.get_param("~sensors", dict({}))

    for name, params in sensor_params.iteritems():
        # Set the direction to input if not specified
        try:
            params['direction']
        except:
            params['direction'] = 'input'

        if params['type'] == "Ping":
            sensor = Ping(self.controller, name, params['pin'], params['rate'], self.base_frame)
        elif params['type'] == "GP2D12":
            sensor = GP2D12(self.controller, name, params['pin'], params['rate'], self.base_frame)
        elif params['type'] == 'Digital':
            sensor = DigitalSensor(self.controller, name, params['pin'], params['rate'], self.base_frame, direction=params['direction'])
        elif params['type'] == 'Analog':
            sensor = AnalogSensor(self.controller, name, params['pin'], params['rate'], self.base_frame, direction=params['direction'])
        elif params['type'] == 'PololuMotorCurrent':
            sensor = PololuMotorCurrent(self.controller, name, params['pin'], params['rate'], self.base_frame)
        elif params['type'] == 'PhidgetsVoltage':
            sensor = PhidgetsVoltage(self.controller, name, params['pin'], params['rate'], self.base_frame)
        elif params['type'] == 'PhidgetsCurrent':
            sensor = PhidgetsCurrent(self.controller, name, params['pin'], params['rate'], self.base_frame)

        # if params['type'] == "MaxEZ1":
        #     self.sensors[len(self.sensors)]['trigger_pin'] = params['trigger_pin']
        #     self.sensors[len(self.sensors)]['output_pin'] = params['output_pin']
        try:
            self.mySensors.append(sensor)
            rospy.loginfo(name + " " + str(params) + " published on topic " + rospy.get_name() + "/sensor/" + name)
        except:
            rospy.logerr("Sensor type " + str(params['type']) + " not recognized.")
edit retag flag offensive close merge delete