mirror of
https://github.com/YikeStone/ros_arduino_bridge.git
synced 2025-08-05 20:14:07 +05:30
fix #40 issue and add .gitignore file
* Make the parameter "motors_reversed" take effect: Before returning encoder data, check parameter "motors_reversed" if true. If true, make these data opposite. So does motors speed data. * Add .gitignore to ignore files like pyc generated by PVM and temporary files generated by vim or other editors
This commit is contained in:
parent
ef83edc1dc
commit
844f33b6c0
106
.gitignore
vendored
Normal file
106
.gitignore
vendored
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
|
||||||
|
# Created by https://www.gitignore.io/api/python
|
||||||
|
|
||||||
|
### Python ###
|
||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
env/
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*,cover
|
||||||
|
.hypothesis/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
.python-version
|
||||||
|
|
||||||
|
# celery beat schedule file
|
||||||
|
celerybeat-schedule
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# dotenv
|
||||||
|
.env
|
||||||
|
|
||||||
|
# virtualenv
|
||||||
|
.venv
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# End of https://www.gitignore.io/api/python
|
||||||
|
# temporary files
|
||||||
|
*~
|
@ -43,7 +43,7 @@ class ArduinoROS():
|
|||||||
self.baud = int(rospy.get_param("~baud", 57600))
|
self.baud = int(rospy.get_param("~baud", 57600))
|
||||||
self.timeout = rospy.get_param("~timeout", 0.5)
|
self.timeout = rospy.get_param("~timeout", 0.5)
|
||||||
self.base_frame = rospy.get_param("~base_frame", 'base_link')
|
self.base_frame = rospy.get_param("~base_frame", 'base_link')
|
||||||
|
self.motors_reversed = rospy.get_param("~motors_reversed", False)
|
||||||
# Overall loop rate: should be faster than fastest sensor rate
|
# Overall loop rate: should be faster than fastest sensor rate
|
||||||
self.rate = int(rospy.get_param("~rate", 50))
|
self.rate = int(rospy.get_param("~rate", 50))
|
||||||
r = rospy.Rate(self.rate)
|
r = rospy.Rate(self.rate)
|
||||||
@ -91,7 +91,7 @@ class ArduinoROS():
|
|||||||
rospy.Service('~analog_read', AnalogRead, self.AnalogReadHandler)
|
rospy.Service('~analog_read', AnalogRead, self.AnalogReadHandler)
|
||||||
|
|
||||||
# Initialize the controlller
|
# Initialize the controlller
|
||||||
self.controller = Arduino(self.port, self.baud, self.timeout)
|
self.controller = Arduino(self.port, self.baud, self.timeout, self.motors_reversed)
|
||||||
|
|
||||||
# Make the connection
|
# Make the connection
|
||||||
self.controller.connect()
|
self.controller.connect()
|
||||||
|
@ -38,7 +38,7 @@ class Arduino:
|
|||||||
N_ANALOG_PORTS = 6
|
N_ANALOG_PORTS = 6
|
||||||
N_DIGITAL_PORTS = 12
|
N_DIGITAL_PORTS = 12
|
||||||
|
|
||||||
def __init__(self, port="/dev/ttyUSB0", baudrate=57600, timeout=0.5):
|
def __init__(self, port="/dev/ttyUSB0", baudrate=57600, timeout=0.5, motors_reversed=False):
|
||||||
|
|
||||||
self.PID_RATE = 30 # Do not change this! It is a fixed property of the Arduino PID controller.
|
self.PID_RATE = 30 # Do not change this! It is a fixed property of the Arduino PID controller.
|
||||||
self.PID_INTERVAL = 1000 / 30
|
self.PID_INTERVAL = 1000 / 30
|
||||||
@ -49,7 +49,7 @@ class Arduino:
|
|||||||
self.encoder_count = 0
|
self.encoder_count = 0
|
||||||
self.writeTimeout = timeout
|
self.writeTimeout = timeout
|
||||||
self.interCharTimeout = timeout / 30.
|
self.interCharTimeout = timeout / 30.
|
||||||
|
self.motors_reversed = motors_reversed
|
||||||
# Keep things thread safe
|
# Keep things thread safe
|
||||||
self.mutex = thread.allocate_lock()
|
self.mutex = thread.allocate_lock()
|
||||||
|
|
||||||
@ -270,6 +270,8 @@ class Arduino:
|
|||||||
raise SerialException
|
raise SerialException
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
|
if self.motors_reversed:
|
||||||
|
values[0], values[1] = -values[0], -values[1]
|
||||||
return values
|
return values
|
||||||
|
|
||||||
def reset_encoders(self):
|
def reset_encoders(self):
|
||||||
@ -280,6 +282,8 @@ class Arduino:
|
|||||||
def drive(self, right, left):
|
def drive(self, right, left):
|
||||||
''' Speeds are given in encoder ticks per PID interval
|
''' Speeds are given in encoder ticks per PID interval
|
||||||
'''
|
'''
|
||||||
|
if self.motors_reversed:
|
||||||
|
left, right = -left, -right
|
||||||
return self.execute_ack('m %d %d' %(right, left))
|
return self.execute_ack('m %d %d' %(right, left))
|
||||||
|
|
||||||
def drive_m_per_s(self, right, left):
|
def drive_m_per_s(self, right, left):
|
||||||
@ -374,4 +378,3 @@ if __name__ == "__main__":
|
|||||||
myArduino.close()
|
myArduino.close()
|
||||||
|
|
||||||
print "Shutting down Arduino."
|
print "Shutting down Arduino."
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user