ROS study of three notes: the wireless connection Arduino

    In the preparation process, we implemented based communications rosserial and Arduino, identifying the SCM system can also be used as a Node ROS, the ROS into the robot system.
    But at the current level and to my understanding, it seems that the Master ROS must be run on a PC, and the corresponding system of ubuntu PC installed.
    If via serial cable (USB line) and the Arduino board connected in order to achieve rosserial, it was too restrictive. Because the car as a learning platform will not do much, otherwise the cost is too high. This laptop will not be placed in a small car, if selective ROS can run single board computer seems expensive.
    So, in the realization of rosserial, the first step is to want to verify: whether it would be wired into a wireless connection?

    I do use two USB wireless adapter (supports USB to wireless UART or wireless transfer, implemented STM32F103C8, USB virtual serial port is implemented with the STM32 USB Library), one connected to a computer via USB, via a UART port Arduino Nano connected to the plate.

 
    Because I was on a virtual machine installed ubuntu, STM32 virtual serial port driver is installed under win10 ubuntu system should be able to identify, in fact, seems a little problem, I do not familiar with Linux, the main purpose is not pondering the STM32 USB virtual serial port, so around open, with a CH340 USB to TTL serial module access the PC, so that in ubuntu to know.
    Ubuntu terminal sequence start, run roscore, rosrun rosserial_python serial_node.py / dev / ttyUSB0, the connection is not found, the display synchronization failure.
https://github.com/ros-drivers/rosserial/blob/melodic-devel/rosserial_arduino/src/rosserial_arduino/SerialClient.py     ; fear Arduino reset signal is connected to the USB port is not generated, that synchronization fails. With USB to serial module directly to TTL chips Arduino TXD, RXD terminal, a result of normal work, the problem seems not reset signal.

    Again according to the aforementioned wiring, use two wireless UART connection instead of pass-through module, this success!



    I tried several times, and the findings may reset some extent. 
    Rosserial must be running on the PC after the Arduino module to generate a reset, otherwise it seems to be due to the serial buffer has data, synchronous communication can not be achieved. Feeling a little problem in the library program handles communications frame can not find a valid sync frame from continuous data stream, but from the beginning of the reset detection.
    The later date when the specific implementation of it, at least to verify the possibility of achieving rosserial by wireless, so you can play on most of the space.

Padding:
    Now the roserial_arduino source code on github, is provided in the communication request signal to reset the DTR signal via the board Arduino:
https://github.com/ros-drivers/rosserial/blob/melodic-devel/rosserial_arduino/src/rosserial_arduino /SerialClient.py
......

import time
   
 

import rospy

 

from std_srvs.srv import Empty, EmptyResponse

   
 

from serial import Serial

   
 

from rosserial_python import SerialClient as _SerialClient

   
 

MINIMUM_RESET_TIME = 30

   
 

class SerialClient(_SerialClient):

   
 

def __init__(self, *args, **kwargs):

 

# The number of seconds to wait after a sync failure for a sync success before automatically performing a reset.

 

# If 0, no reset is performed.

 

self.auto_reset_timeout = kwargs.pop('auto_reset_timeout', 0)

 

self.lastsync_reset = rospy.Time.now()

 

rospy.Service('~reset_arduino', Empty, self.resetArduino)

 

super(SerialClient, self).__init__(*args, **kwargs)

   
 

def resetArduino(self, *args, **kwargs):

 

"""

 

Forces the Arduino to perform a reset, as though its reset button was pressed.

 

"""

 

with self.read_lock, self.write_lock:

 

rospy.loginfo('Beginning Arduino reset on port %s. Closing serial port...' % self.port.portstr)

 

self.port.close()

 

with Serial(self.port.portstr) as arduino:

 

arduino.setDTR(False)

 

time.sleep(3)

 

arduino.flushInput()

 

arduino.setDTR(True)

 

time.sleep(5)

 

rospy.loginfo('Reopening serial port...')

 

self.port.open()

 

rospy.loginfo('Arduino reset complete.')

 

self.lastsync_reset = rospy.Time.now()

 

self.requestTopics()

 

return EmptyResponse()

   
 

def sendDiagnostics(self, level, msg_text):

 

super(SerialClient, self).sendDiagnostics(level, msg_text)

 

# Reset when we haven't received any data from the Arduino in over N seconds.

 

if self.auto_reset_timeout and (rospy.Time.now() - self.last_read).secs >= self.auto_reset_timeout:

 

if (rospy.Time.now() - self.lastsync_reset).secs < MINIMUM_RESET_TIME:

 

rospy.loginfo('Sync has failed, but waiting for last reset to complete.')

 

else:

 

rospy.loginfo('Sync has failed for over %s seconds. Initiating automatic reset.' % self.auto_reset_timeout)

 

self.resetArduino()

Guess you like

Origin blog.csdn.net/embedream/article/details/91819927