From 12a7ca4dbb15ebb413241bf23b4300dee5011d73 Mon Sep 17 00:00:00 2001 From: Michael Ferguson Date: Sat, 2 Feb 2013 12:43:37 -0800 Subject: [PATCH 01/37] catkinize --- CMakeLists.txt | 17 -------- Makefile | 1 - ros_arduino_bridge/package.xml | 21 +++++++++ ros_arduino_firmware/CMakeLists.txt | 35 +++------------ ros_arduino_firmware/Makefile | 1 - ros_arduino_firmware/mainpage.dox | 26 ----------- ros_arduino_firmware/manifest.xml | 14 ------ ros_arduino_firmware/package.xml | 13 ++++++ ros_arduino_msgs/CMakeLists.txt | 43 ++++++++----------- ros_arduino_msgs/Makefile | 1 - ros_arduino_msgs/mainpage.dox | 26 ----------- ros_arduino_msgs/manifest.xml | 13 ------ ros_arduino_msgs/package.xml | 17 ++++++++ .../src/ros_arduino_msgs/__init__.py | 0 ros_arduino_python/CMakeLists.txt | 40 ++++++----------- ros_arduino_python/Makefile | 1 - ros_arduino_python/mainpage.dox | 26 ----------- ros_arduino_python/manifest.xml | 22 ---------- ros_arduino_python/nodes/arduino_node.py | 6 +-- ros_arduino_python/package.xml | 21 +++++++++ ros_arduino_python/setup.py | 11 +++++ ros_arduino_python/src/__init__.py | 0 .../arduino_driver.py | 0 .../arduino_sensors.py | 0 .../base_controller.py | 0 stack.xml | 12 ------ 26 files changed, 125 insertions(+), 242 deletions(-) delete mode 100644 CMakeLists.txt delete mode 100644 Makefile create mode 100644 ros_arduino_bridge/package.xml delete mode 100644 ros_arduino_firmware/Makefile delete mode 100644 ros_arduino_firmware/mainpage.dox delete mode 100644 ros_arduino_firmware/manifest.xml create mode 100644 ros_arduino_firmware/package.xml delete mode 100644 ros_arduino_msgs/Makefile delete mode 100644 ros_arduino_msgs/mainpage.dox delete mode 100644 ros_arduino_msgs/manifest.xml create mode 100644 ros_arduino_msgs/package.xml delete mode 100644 ros_arduino_msgs/src/ros_arduino_msgs/__init__.py delete mode 100644 ros_arduino_python/Makefile delete mode 100644 ros_arduino_python/mainpage.dox delete mode 100644 ros_arduino_python/manifest.xml create mode 100644 ros_arduino_python/package.xml create mode 100644 ros_arduino_python/setup.py delete mode 100644 ros_arduino_python/src/__init__.py rename ros_arduino_python/src/{ => ros_arduino_python}/arduino_driver.py (100%) rename ros_arduino_python/src/{ => ros_arduino_python}/arduino_sensors.py (100%) rename ros_arduino_python/src/{ => ros_arduino_python}/base_controller.py (100%) delete mode 100644 stack.xml diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 28105dd..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -cmake_minimum_required(VERSION 2.4.6) -include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake) - -# Append to CPACK_SOURCE_IGNORE_FILES a semicolon-separated list of -# directories (or patterns, but directories should suffice) that should -# be excluded from the distro. This is not the place to put things that -# should be ignored everywhere, like "build" directories; that happens in -# rosbuild/rosbuild.cmake. Here should be listed packages that aren't -# ready for inclusion in a distro. -# -# This list is combined with the list in rosbuild/rosbuild.cmake. Note -# that CMake 2.6 may be required to ensure that the two lists are combined -# properly. CMake 2.4 seems to have unpredictable scoping rules for such -# variables. -#list(APPEND CPACK_SOURCE_IGNORE_FILES /core/experimental) - -rosbuild_make_distribution(0.1.0) diff --git a/Makefile b/Makefile deleted file mode 100644 index a818cca..0000000 --- a/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(shell rospack find mk)/cmake_stack.mk \ No newline at end of file diff --git a/ros_arduino_bridge/package.xml b/ros_arduino_bridge/package.xml new file mode 100644 index 0000000..6f4cf8a --- /dev/null +++ b/ros_arduino_bridge/package.xml @@ -0,0 +1,21 @@ + + ros_arduino_bridge + 0.2.0 + + Metapackage for ros_arduino_bridge. + + Patrick Goebel + Patrick Goebel + BSD + http://ros.org/wiki/ros_arduino_bridge + + catkin + + ros_arduino_firmware + ros_arduino_msgs + ros_arduino_python + + + + + diff --git a/ros_arduino_firmware/CMakeLists.txt b/ros_arduino_firmware/CMakeLists.txt index f8f1c9c..1148d7b 100644 --- a/ros_arduino_firmware/CMakeLists.txt +++ b/ros_arduino_firmware/CMakeLists.txt @@ -1,30 +1,9 @@ -cmake_minimum_required(VERSION 2.4.6) -include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake) +cmake_minimum_required(VERSION 2.8.3) +project(ros_arduino_firmware) -# Set the build type. Options are: -# Coverage : w/ debug symbols, w/o optimization, w/ code-coverage -# Debug : w/ debug symbols, w/o optimization -# Release : w/o debug symbols, w/ optimization -# RelWithDebInfo : w/ debug symbols, w/ optimization -# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries -#set(ROS_BUILD_TYPE RelWithDebInfo) +find_package(catkin REQUIRED) +catkin_package(DEPENDS) -rosbuild_init() - -#set the default path for built executables to the "bin" directory -set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) -#set the default path for built libraries to the "lib" directory -set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) - -#uncomment if you have defined messages -#rosbuild_genmsg() -#uncomment if you have defined services -#rosbuild_gensrv() - -#common commands for building c++ executables and libraries -#rosbuild_add_library(${PROJECT_NAME} src/example.cpp) -#target_link_libraries(${PROJECT_NAME} another_library) -#rosbuild_add_boost_directories() -#rosbuild_link_boost(${PROJECT_NAME} thread) -#rosbuild_add_executable(example examples/example.cpp) -#target_link_libraries(example ${PROJECT_NAME}) +install(DIRECTORY src + DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} +) diff --git a/ros_arduino_firmware/Makefile b/ros_arduino_firmware/Makefile deleted file mode 100644 index b75b928..0000000 --- a/ros_arduino_firmware/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(shell rospack find mk)/cmake.mk \ No newline at end of file diff --git a/ros_arduino_firmware/mainpage.dox b/ros_arduino_firmware/mainpage.dox deleted file mode 100644 index a28c5dd..0000000 --- a/ros_arduino_firmware/mainpage.dox +++ /dev/null @@ -1,26 +0,0 @@ -/** -\mainpage -\htmlinclude manifest.html - -\b ros_arduino_firmware is ... - - - - -\section codeapi Code API - - - - -*/ diff --git a/ros_arduino_firmware/manifest.xml b/ros_arduino_firmware/manifest.xml deleted file mode 100644 index 245bdf3..0000000 --- a/ros_arduino_firmware/manifest.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - ROS Arduino Firmware - - - Patrick Goebel - BSD - - http://ros.org/wiki/ros_arduino_firmware - - - - diff --git a/ros_arduino_firmware/package.xml b/ros_arduino_firmware/package.xml new file mode 100644 index 0000000..ccc2e3d --- /dev/null +++ b/ros_arduino_firmware/package.xml @@ -0,0 +1,13 @@ + + ros_arduino_firmware + 0.2.0 + + ROS Arduino Firmware. + + Patrick Goebel + Patrick Goebel + BSD + http://ros.org/wiki/ros_arduino_firmware + + catkin + diff --git a/ros_arduino_msgs/CMakeLists.txt b/ros_arduino_msgs/CMakeLists.txt index f1c1a19..c504682 100644 --- a/ros_arduino_msgs/CMakeLists.txt +++ b/ros_arduino_msgs/CMakeLists.txt @@ -1,30 +1,23 @@ -cmake_minimum_required(VERSION 2.4.6) -include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake) +cmake_minimum_required(VERSION 2.8.3) +project(ros_arduino_msgs) -# Set the build type. Options are: -# Coverage : w/ debug symbols, w/o optimization, w/ code-coverage -# Debug : w/ debug symbols, w/o optimization -# Release : w/o debug symbols, w/ optimization -# RelWithDebInfo : w/ debug symbols, w/ optimization -# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries -#set(ROS_BUILD_TYPE RelWithDebInfo) +find_package(catkin REQUIRED genmsg std_msgs) -rosbuild_init() +add_message_files(FILES + AnalogFloat.msg + Analog.msg + Digital.msg + SensorState.msg + ) -#set the default path for built executables to the "bin" directory -set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) -#set the default path for built libraries to the "lib" directory -set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) +add_service_files(FILES + DigitalSetDirection.srv + DigitalWrite.srv + ServoRead.srv + ServoWrite.srv + ) -#uncomment if you have defined messages -rosbuild_genmsg() -#uncomment if you have defined services -rosbuild_gensrv() +generate_messages(DEPENDENCIES std_msgs) + +catkin_package(DEPENDS std_msgs) -#common commands for building c++ executables and libraries -#rosbuild_add_library(${PROJECT_NAME} src/example.cpp) -#target_link_libraries(${PROJECT_NAME} another_library) -#rosbuild_add_boost_directories() -#rosbuild_link_boost(${PROJECT_NAME} thread) -#rosbuild_add_executable(example examples/example.cpp) -#target_link_libraries(example ${PROJECT_NAME}) diff --git a/ros_arduino_msgs/Makefile b/ros_arduino_msgs/Makefile deleted file mode 100644 index b75b928..0000000 --- a/ros_arduino_msgs/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(shell rospack find mk)/cmake.mk \ No newline at end of file diff --git a/ros_arduino_msgs/mainpage.dox b/ros_arduino_msgs/mainpage.dox deleted file mode 100644 index 4a0daab..0000000 --- a/ros_arduino_msgs/mainpage.dox +++ /dev/null @@ -1,26 +0,0 @@ -/** -\mainpage -\htmlinclude manifest.html - -\b ros_arduino_msgs is ... - - - - -\section codeapi Code API - - - - -*/ diff --git a/ros_arduino_msgs/manifest.xml b/ros_arduino_msgs/manifest.xml deleted file mode 100644 index 62ebb0b..0000000 --- a/ros_arduino_msgs/manifest.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - ROS Arduino Messages - - - Patrick Goebel - BSD - - http://ros.org/wiki/ros_arduino_msgs - - - diff --git a/ros_arduino_msgs/package.xml b/ros_arduino_msgs/package.xml new file mode 100644 index 0000000..939fcb9 --- /dev/null +++ b/ros_arduino_msgs/package.xml @@ -0,0 +1,17 @@ + + ros_arduino_msgs + 0.2.0 + + ROS Arduino Messages. + + Patrick Goebel + Patrick Goebel + BSD + http://ros.org/wiki/ros_arduino_msgs + + catkin + + std_msgs + + std_msgs + diff --git a/ros_arduino_msgs/src/ros_arduino_msgs/__init__.py b/ros_arduino_msgs/src/ros_arduino_msgs/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/ros_arduino_python/CMakeLists.txt b/ros_arduino_python/CMakeLists.txt index f8f1c9c..a79bb49 100644 --- a/ros_arduino_python/CMakeLists.txt +++ b/ros_arduino_python/CMakeLists.txt @@ -1,30 +1,18 @@ -cmake_minimum_required(VERSION 2.4.6) -include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake) +cmake_minimum_required(VERSION 2.8.3) +project(ros_arduino_python) -# Set the build type. Options are: -# Coverage : w/ debug symbols, w/o optimization, w/ code-coverage -# Debug : w/ debug symbols, w/o optimization -# Release : w/o debug symbols, w/ optimization -# RelWithDebInfo : w/ debug symbols, w/ optimization -# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries -#set(ROS_BUILD_TYPE RelWithDebInfo) +find_package(catkin REQUIRED) +catkin_package(DEPENDS) +catkin_python_setup() -rosbuild_init() +install(DIRECTORY config + DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} +) -#set the default path for built executables to the "bin" directory -set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) -#set the default path for built libraries to the "lib" directory -set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) +install(DIRECTORY launch + DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} +) -#uncomment if you have defined messages -#rosbuild_genmsg() -#uncomment if you have defined services -#rosbuild_gensrv() - -#common commands for building c++ executables and libraries -#rosbuild_add_library(${PROJECT_NAME} src/example.cpp) -#target_link_libraries(${PROJECT_NAME} another_library) -#rosbuild_add_boost_directories() -#rosbuild_link_boost(${PROJECT_NAME} thread) -#rosbuild_add_executable(example examples/example.cpp) -#target_link_libraries(example ${PROJECT_NAME}) +install(DIRECTORY nodes + DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} +) diff --git a/ros_arduino_python/Makefile b/ros_arduino_python/Makefile deleted file mode 100644 index b75b928..0000000 --- a/ros_arduino_python/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(shell rospack find mk)/cmake.mk \ No newline at end of file diff --git a/ros_arduino_python/mainpage.dox b/ros_arduino_python/mainpage.dox deleted file mode 100644 index 10ef6c2..0000000 --- a/ros_arduino_python/mainpage.dox +++ /dev/null @@ -1,26 +0,0 @@ -/** -\mainpage -\htmlinclude manifest.html - -\b ros_arduino_python is ... - - - - -\section codeapi Code API - - - - -*/ diff --git a/ros_arduino_python/manifest.xml b/ros_arduino_python/manifest.xml deleted file mode 100644 index 1d04908..0000000 --- a/ros_arduino_python/manifest.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - ROS Arduino Python - - - Patrick Goebel - BSD - - http://ros.org/wiki/ros_arduino_python - - - - - - - - - - - - diff --git a/ros_arduino_python/nodes/arduino_node.py b/ros_arduino_python/nodes/arduino_node.py index e9c65f0..9730e4a 100755 --- a/ros_arduino_python/nodes/arduino_node.py +++ b/ros_arduino_python/nodes/arduino_node.py @@ -21,10 +21,10 @@ import roslib; roslib.load_manifest('ros_arduino_python') import rospy -from arduino_driver import Arduino -from arduino_sensors import * +from ros_arduino_python.arduino_driver import Arduino +from ros_arduino_python.arduino_sensors import * from ros_arduino_msgs.srv import * -from base_controller import BaseController +from ros_arduino_python.base_controller import BaseController from geometry_msgs.msg import Twist import os, time import thread diff --git a/ros_arduino_python/package.xml b/ros_arduino_python/package.xml new file mode 100644 index 0000000..b84c9cb --- /dev/null +++ b/ros_arduino_python/package.xml @@ -0,0 +1,21 @@ + + ros_arduino_python + 0.2.0 + + ROS Arduino Python. + + Patrick Goebel + Patrick Goebel + BSD + http://ros.org/wiki/ros_arduino_python + + catkin + + rospy + std_msgs + sensor_msgs + geometry_msgs + nav_msgs + tf + ros_arduino_msgs + diff --git a/ros_arduino_python/setup.py b/ros_arduino_python/setup.py new file mode 100644 index 0000000..e09dd1b --- /dev/null +++ b/ros_arduino_python/setup.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +from distutils.core import setup +from catkin_pkg.python_setup import generate_distutils_setup + +d = generate_distutils_setup( + packages=['ros_arduino_python'], + package_dir={'': 'src'}, + ) + +setup(**d) diff --git a/ros_arduino_python/src/__init__.py b/ros_arduino_python/src/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/ros_arduino_python/src/arduino_driver.py b/ros_arduino_python/src/ros_arduino_python/arduino_driver.py similarity index 100% rename from ros_arduino_python/src/arduino_driver.py rename to ros_arduino_python/src/ros_arduino_python/arduino_driver.py diff --git a/ros_arduino_python/src/arduino_sensors.py b/ros_arduino_python/src/ros_arduino_python/arduino_sensors.py similarity index 100% rename from ros_arduino_python/src/arduino_sensors.py rename to ros_arduino_python/src/ros_arduino_python/arduino_sensors.py diff --git a/ros_arduino_python/src/base_controller.py b/ros_arduino_python/src/ros_arduino_python/base_controller.py similarity index 100% rename from ros_arduino_python/src/base_controller.py rename to ros_arduino_python/src/ros_arduino_python/base_controller.py diff --git a/stack.xml b/stack.xml deleted file mode 100644 index f4c5a70..0000000 --- a/stack.xml +++ /dev/null @@ -1,12 +0,0 @@ - - ROS Arduino Bridge - Maintained by Patrick Goebel - BSD - - http://ros.org/wiki/ros_arduino_bridge - - - - - - From 233d9986a3feb2c3eff8b12e4cbbdfe706d38b70 Mon Sep 17 00:00:00 2001 From: Michael Ferguson Date: Sat, 2 Feb 2013 12:46:33 -0800 Subject: [PATCH 02/37] update readme a bit for catkin, probably needs more work --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f15ca5f..af82cbc 100644 --- a/README.md +++ b/README.md @@ -52,10 +52,10 @@ Arduino IDE. Installation ------------ - $ cd ~/ros_workspace + $ cd ~/catkin_workspace/src $ git clone https://github.com/hbrobotics/ros_arduino_bridge.git - $ cd ros_arduino_bridge - $ rosmake + $ cd ~/catkin_workspace + $ catkin_make The provided Arduino library is called ROSArduinoBridge and is located in the ros\_arduino\_firmware package. This sketch is @@ -412,4 +412,4 @@ so it looks like this: Compile the changes and upload to your controller. Next, edit your my\_arduino_params.yaml file and make sure the -use\_base\_controller parameter is set to False. That's all there is to it. \ No newline at end of file +use\_base\_controller parameter is set to False. That's all there is to it. From f0bc3b654fa4cb1a26aa3f1dccb42e153db6d222 Mon Sep 17 00:00:00 2001 From: Michael Ferguson Date: Sat, 23 Nov 2013 13:32:14 -0800 Subject: [PATCH 03/37] remove roslib setup --- ros_arduino_python/nodes/arduino_node.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ros_arduino_python/nodes/arduino_node.py b/ros_arduino_python/nodes/arduino_node.py index 9730e4a..2e4c745 100755 --- a/ros_arduino_python/nodes/arduino_node.py +++ b/ros_arduino_python/nodes/arduino_node.py @@ -19,7 +19,6 @@ http://www.gnu.org/licenses/gpl.html """ -import roslib; roslib.load_manifest('ros_arduino_python') import rospy from ros_arduino_python.arduino_driver import Arduino from ros_arduino_python.arduino_sensors import * From dec97857f66f14c8d1dc912109a37a571920e004 Mon Sep 17 00:00:00 2001 From: Michael Ferguson Date: Sun, 24 Nov 2013 12:53:50 -0800 Subject: [PATCH 04/37] add depend on python serial --- ros_arduino_python/package.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/ros_arduino_python/package.xml b/ros_arduino_python/package.xml index b84c9cb..5bd96a0 100644 --- a/ros_arduino_python/package.xml +++ b/ros_arduino_python/package.xml @@ -18,4 +18,5 @@ nav_msgs tf ros_arduino_msgs + python-serial From af85174fb76a3e0fad98238436e7d3207574b2b2 Mon Sep 17 00:00:00 2001 From: Michael Ferguson Date: Mon, 25 Nov 2013 14:13:04 -0800 Subject: [PATCH 05/37] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index a6058cc..daede5c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +Overview +-------- +This branch (hydro-devel) is intended for ROS Hydro and above, and uses the Catkin buildsystem. It may also be compatible with ROS Groovy. + This ROS stack includes an Arduino library (called ROSArduinoBridge) and a collection of ROS packages for controlling an Arduino-based robot using standard ROS messages and services. The stack does **not** depend on ROS Serial. Features of the stack include: From 6faf351cc795766a9f040fbfe8ff6588afde8fe6 Mon Sep 17 00:00:00 2001 From: Michael Ferguson Date: Thu, 2 Jan 2014 13:58:29 -0800 Subject: [PATCH 06/37] add CMakeLists for caktin metapackage --- ros_arduino_bridge/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 ros_arduino_bridge/CMakeLists.txt diff --git a/ros_arduino_bridge/CMakeLists.txt b/ros_arduino_bridge/CMakeLists.txt new file mode 100644 index 0000000..2581b5a --- /dev/null +++ b/ros_arduino_bridge/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8.3) +project(ros_arduino_bridge) +find_package(catkin REQUIRED) +catkin_metapackage() From 8ec8dc88163e5dd2d84eb199fcb94c8a48a35c21 Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Thu, 27 Feb 2014 07:16:09 -0800 Subject: [PATCH 07/37] Added base_frame parameter (default base_link) that can be set to base_footprint for robots that use base_footprint instead of base_link --- ros_arduino_python/config/arduino_params.yaml | 3 +++ ros_arduino_python/nodes/arduino_node.py | 19 ++++++++++--------- .../src/ros_arduino_python/arduino_sensors.py | 2 +- .../src/ros_arduino_python/base_controller.py | 11 ++++++----- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/ros_arduino_python/config/arduino_params.yaml b/ros_arduino_python/config/arduino_params.yaml index 84f9b77..9acbe3d 100644 --- a/ros_arduino_python/config/arduino_params.yaml +++ b/ros_arduino_python/config/arduino_params.yaml @@ -13,6 +13,9 @@ sensorstate_rate: 10 use_base_controller: False base_controller_rate: 10 +# For a robot that uses base_footprint, change base_frame to base_footprint +base_frame: base_link + # === Robot drivetrain parameters #wheel_diameter: 0.146 #wheel_track: 0.2969 diff --git a/ros_arduino_python/nodes/arduino_node.py b/ros_arduino_python/nodes/arduino_node.py index d844f3e..4e2f34b 100755 --- a/ros_arduino_python/nodes/arduino_node.py +++ b/ros_arduino_python/nodes/arduino_node.py @@ -38,6 +38,7 @@ class ArduinoROS(): self.port = rospy.get_param("~port", "/dev/ttyACM0") self.baud = int(rospy.get_param("~baud", 57600)) self.timeout = rospy.get_param("~timeout", 0.5) + self.base_frame = rospy.get_param("~base_frame", 'base_link') # Overall loop rate: should be faster than fastest sensor rate self.rate = int(rospy.get_param("~rate", 50)) @@ -100,19 +101,19 @@ class ArduinoROS(): params['direction'] = 'input' if params['type'] == "Ping": - sensor = Ping(self.controller, name, params['pin'], params['rate']) + 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']) + 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'], direction=params['direction']) + 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'], direction=params['direction']) + 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']) + 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']) + 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']) + 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'] @@ -123,7 +124,7 @@ class ArduinoROS(): # Initialize the base controller if used if self.use_base_controller: - self.myBaseController = BaseController(self.controller) + self.myBaseController = BaseController(self.controller, self.base_frame) # Start polling the sensors and base controller while not rospy.is_shutdown(): @@ -142,7 +143,7 @@ class ArduinoROS(): if now > self.t_next_sensors: msg = SensorState() - msg.header.frame_id = 'base_link' + msg.header.frame_id = self.base_frame msg.header.stamp = now for i in range(len(self.mySensors)): msg.name.append(self.mySensors[i].name) diff --git a/ros_arduino_python/src/ros_arduino_python/arduino_sensors.py b/ros_arduino_python/src/ros_arduino_python/arduino_sensors.py index c5601ce..2f9b11c 100755 --- a/ros_arduino_python/src/ros_arduino_python/arduino_sensors.py +++ b/ros_arduino_python/src/ros_arduino_python/arduino_sensors.py @@ -39,7 +39,7 @@ class MessageType: BOOL = 5 class Sensor(object): - def __init__(self, controller, name, pin, rate, frame_id="/base_link", direction="input", **kwargs): + def __init__(self, controller, name, pin, rate, frame_id, direction="input", **kwargs): self.controller = controller self.name = name self.pin = pin diff --git a/ros_arduino_python/src/ros_arduino_python/base_controller.py b/ros_arduino_python/src/ros_arduino_python/base_controller.py index 0c7656e..246be0f 100755 --- a/ros_arduino_python/src/ros_arduino_python/base_controller.py +++ b/ros_arduino_python/src/ros_arduino_python/base_controller.py @@ -31,10 +31,11 @@ from tf.broadcaster import TransformBroadcaster """ Class to receive Twist commands and publish Odometry data """ class BaseController: - def __init__(self, arduino): + def __init__(self, arduino, base_frame): self.arduino = arduino + self.base_frame = base_frame self.rate = float(rospy.get_param("~base_controller_rate", 10)) - self.timeout = rospy.get_param('~base_controller_timeout', 1.0) + self.timeout = rospy.get_param("~base_controller_timeout", 1.0) self.stopped = False pid_params = dict() @@ -90,7 +91,7 @@ class BaseController: self.odomBroadcaster = TransformBroadcaster() rospy.loginfo("Started base controller for a base of " + str(self.wheel_track) + "m wide with " + str(self.encoder_resolution) + " ticks per rev") - rospy.loginfo("Publishing odometry data at: " + str(self.rate) + " Hz") + rospy.loginfo("Publishing odometry data at: " + str(self.rate) + " Hz using " + str(self.base_frame) + " as base frame") def setup_pid(self, pid_params): # Check to see if any PID parameters are missing @@ -166,13 +167,13 @@ class BaseController: (self.x, self.y, 0), (quaternion.x, quaternion.y, quaternion.z, quaternion.w), rospy.Time.now(), - "base_link", + self.base_frame, "odom" ) odom = Odometry() odom.header.frame_id = "odom" - odom.child_frame_id = "base_link" + odom.child_frame_id = self.base_frame odom.header.stamp = now odom.pose.pose.position.x = self.x odom.pose.pose.position.y = self.y From 5eed2f718de187bbad2b24936a658e0f8321f041 Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Fri, 28 Feb 2014 11:56:44 -0800 Subject: [PATCH 08/37] Updated package.xml and CMakeLists.txt in ros_arduino_msgs to fix Jenkins doc build error --- ros_arduino_msgs/CMakeLists.txt | 7 +++++-- ros_arduino_msgs/package.xml | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ros_arduino_msgs/CMakeLists.txt b/ros_arduino_msgs/CMakeLists.txt index c504682..fea7424 100644 --- a/ros_arduino_msgs/CMakeLists.txt +++ b/ros_arduino_msgs/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 2.8.3) project(ros_arduino_msgs) -find_package(catkin REQUIRED genmsg std_msgs) +find_package(catkin REQUIRED message_generation std_msgs) add_message_files(FILES AnalogFloat.msg @@ -19,5 +19,8 @@ add_service_files(FILES generate_messages(DEPENDENCIES std_msgs) -catkin_package(DEPENDS std_msgs) +catkin_package( + DEPENDS std_msgs + CATKIN DEPENDS message_runtime std_msgs +) diff --git a/ros_arduino_msgs/package.xml b/ros_arduino_msgs/package.xml index 939fcb9..9d17a91 100644 --- a/ros_arduino_msgs/package.xml +++ b/ros_arduino_msgs/package.xml @@ -11,7 +11,10 @@ catkin + message_generation std_msgs + message_runtime std_msgs + From e41ab213fbfba48122ca207bf31b6f1c91fb8ea6 Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Wed, 12 Mar 2014 19:58:43 -0700 Subject: [PATCH 09/37] Cleaned up CMakeLists.txt in ros_arduino_msgs --- ros_arduino_msgs/CMakeLists.txt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/ros_arduino_msgs/CMakeLists.txt b/ros_arduino_msgs/CMakeLists.txt index fea7424..ad5e695 100644 --- a/ros_arduino_msgs/CMakeLists.txt +++ b/ros_arduino_msgs/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 2.8.3) project(ros_arduino_msgs) -find_package(catkin REQUIRED message_generation std_msgs) +find_package(catkin REQUIRED COMPONENTS std_msgs message_generation) add_message_files(FILES AnalogFloat.msg @@ -17,10 +17,9 @@ add_service_files(FILES ServoWrite.srv ) -generate_messages(DEPENDENCIES std_msgs) - -catkin_package( - DEPENDS std_msgs - CATKIN DEPENDS message_runtime std_msgs -) +generate_messages( + DEPENDENCIES + std_msgs +) +catkin_package(CATKIN_DEPENDS message_runtime std_msgs) From 07022b6fe687ff655c4f122e7b5621b5193df477 Mon Sep 17 00:00:00 2001 From: yellow-sky Date: Sat, 5 Apr 2014 19:25:07 +0400 Subject: [PATCH 10/37] Fix servo contract (radian is float) --- ros_arduino_msgs/srv/ServoRead.srv | 2 +- ros_arduino_msgs/srv/ServoWrite.srv | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ros_arduino_msgs/srv/ServoRead.srv b/ros_arduino_msgs/srv/ServoRead.srv index d14b4e1..fd68ffa 100755 --- a/ros_arduino_msgs/srv/ServoRead.srv +++ b/ros_arduino_msgs/srv/ServoRead.srv @@ -1,3 +1,3 @@ uint8 id --- -int16 value +float32 value diff --git a/ros_arduino_msgs/srv/ServoWrite.srv b/ros_arduino_msgs/srv/ServoWrite.srv index e4fa991..5a9170b 100755 --- a/ros_arduino_msgs/srv/ServoWrite.srv +++ b/ros_arduino_msgs/srv/ServoWrite.srv @@ -1,3 +1,3 @@ uint8 id -int16 value +float32 value --- From e0f00edf8c9d8d5ae96d42b36c283f127cebc57e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Tr=C3=B6ster?= Date: Mon, 28 Apr 2014 10:01:07 +0200 Subject: [PATCH 11/37] Added AnalogWrite.srv and added code to use the arduino pwm output --- ros_arduino_msgs/srv/AnalogWrite.srv | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 ros_arduino_msgs/srv/AnalogWrite.srv diff --git a/ros_arduino_msgs/srv/AnalogWrite.srv b/ros_arduino_msgs/srv/AnalogWrite.srv new file mode 100644 index 0000000..5973435 --- /dev/null +++ b/ros_arduino_msgs/srv/AnalogWrite.srv @@ -0,0 +1,3 @@ +uint8 pin +float32 value +--- From d83dcb8cb6a9f6cf656a1d50f9cbb90c1945c599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Tr=C3=B6ster?= Date: Mon, 28 Apr 2014 10:22:15 +0200 Subject: [PATCH 12/37] added code for arduino pwm output --- ros_arduino_msgs/CMakeLists.txt | 1 + ros_arduino_python/nodes/arduino_node.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ros_arduino_msgs/CMakeLists.txt b/ros_arduino_msgs/CMakeLists.txt index ad5e695..16e7f81 100644 --- a/ros_arduino_msgs/CMakeLists.txt +++ b/ros_arduino_msgs/CMakeLists.txt @@ -15,6 +15,7 @@ add_service_files(FILES DigitalWrite.srv ServoRead.srv ServoWrite.srv + AnalogWrite.srv ) generate_messages( diff --git a/ros_arduino_python/nodes/arduino_node.py b/ros_arduino_python/nodes/arduino_node.py index 4e2f34b..085289b 100755 --- a/ros_arduino_python/nodes/arduino_node.py +++ b/ros_arduino_python/nodes/arduino_node.py @@ -76,8 +76,11 @@ class ArduinoROS(): # A service to turn a digital sensor on or off rospy.Service('~digital_write', DigitalWrite, self.DigitalWriteHandler) + + # A service to set pwm values for the pins + rospy.Service('~analog_write', AnalogWrite, self.AnalogWriteHandler) - # Initialize the controlller + # Initialize the controlller self.controller = Arduino(self.port, self.baud, self.timeout) # Make the connection @@ -173,7 +176,11 @@ class ArduinoROS(): def DigitalWriteHandler(self, req): self.controller.digital_write(req.pin, req.value) return DigitalWriteResponse() - + + def AnalogWriteHandler(self, req): + self.controller.analog_write(req.pin, req.value) + return AnalogWriteRrsponse() + def shutdown(self): # Stop the robot try: From dec9b51bc26bf40717361516593d8a18d47ce973 Mon Sep 17 00:00:00 2001 From: PTroester Date: Mon, 28 Apr 2014 10:28:40 +0200 Subject: [PATCH 13/37] fixed a spelling mistake --- ros_arduino_python/nodes/arduino_node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros_arduino_python/nodes/arduino_node.py b/ros_arduino_python/nodes/arduino_node.py index 085289b..4d52a1b 100755 --- a/ros_arduino_python/nodes/arduino_node.py +++ b/ros_arduino_python/nodes/arduino_node.py @@ -179,7 +179,7 @@ class ArduinoROS(): def AnalogWriteHandler(self, req): self.controller.analog_write(req.pin, req.value) - return AnalogWriteRrsponse() + return AnalogWriteResponse() def shutdown(self): # Stop the robot From f2d40aa724cdfc38190fdecbd748948b5709050d Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Wed, 30 Apr 2014 06:32:24 -0700 Subject: [PATCH 14/37] Fixed indentation --- ros_arduino_msgs/CMakeLists.txt | 2 +- ros_arduino_python/nodes/arduino_node.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ros_arduino_msgs/CMakeLists.txt b/ros_arduino_msgs/CMakeLists.txt index 16e7f81..bd6cfb3 100644 --- a/ros_arduino_msgs/CMakeLists.txt +++ b/ros_arduino_msgs/CMakeLists.txt @@ -15,7 +15,7 @@ add_service_files(FILES DigitalWrite.srv ServoRead.srv ServoWrite.srv - AnalogWrite.srv + AnalogWrite.srv ) generate_messages( diff --git a/ros_arduino_python/nodes/arduino_node.py b/ros_arduino_python/nodes/arduino_node.py index 4d52a1b..e379615 100755 --- a/ros_arduino_python/nodes/arduino_node.py +++ b/ros_arduino_python/nodes/arduino_node.py @@ -178,8 +178,8 @@ class ArduinoROS(): return DigitalWriteResponse() def AnalogWriteHandler(self, req): - self.controller.analog_write(req.pin, req.value) - return AnalogWriteResponse() + self.controller.analog_write(req.pin, req.value) + return AnalogWriteResponse() def shutdown(self): # Stop the robot From 8e6b2ff0ce07710d82c0cf1fb1aa0415131458ba Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Sat, 7 Jun 2014 19:06:04 -0700 Subject: [PATCH 15/37] Added missing pin_mode statements to Analog and AnalogFloat sensor types --- .../src/ros_arduino_python/arduino_sensors.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ros_arduino_python/src/ros_arduino_python/arduino_sensors.py b/ros_arduino_python/src/ros_arduino_python/arduino_sensors.py index 2f9b11c..51a7916 100755 --- a/ros_arduino_python/src/ros_arduino_python/arduino_sensors.py +++ b/ros_arduino_python/src/ros_arduino_python/arduino_sensors.py @@ -89,6 +89,13 @@ class AnalogSensor(Sensor): self.pub = rospy.Publisher("~sensor/" + self.name, Analog) + if self.direction == "output": + self.controller.pin_mode(self.pin, OUTPUT) + else: + self.controller.pin_mode(self.pin, INPUT) + + self.value = LOW + def read_value(self): return self.controller.analog_read(self.pin) @@ -105,6 +112,19 @@ class AnalogFloatSensor(Sensor): self.msg.header.frame_id = self.frame_id self.pub = rospy.Publisher("~sensor/" + self.name, AnalogFloat) + + if self.direction == "output": + self.controller.pin_mode(self.pin, OUTPUT) + else: + self.controller.pin_mode(self.pin, INPUT) + + self.value = LOW + + def read_value(self): + return self.controller.analog_read(self.pin) + + def write_value(self, value): + return self.controller.analog_write(self.pin, value) class DigitalSensor(Sensor): From 4d399627e6f97a42f46185463f96108660d5edcc Mon Sep 17 00:00:00 2001 From: Kristof Robot Date: Sun, 1 Sep 2013 21:16:08 +0200 Subject: [PATCH 16/37] Added direct support for wheel encoders (Arduino Uno) Added support for wheel encoder counting directly on the main Arduino board. This allows connecting wheel encoders directly to the Arduino board, without the need for any additional wheel encoder counter equipment. For speed, the code is directly addressing the specific Atmega328p ports and interrupts, making this implementation Atmega328p (Arduino Uno) dependent. It should be easy to adapt for other boards/AVR chips though. --- .../ROSArduinoBridge/ROSArduinoBridge.ino | 24 +++++++++++ .../ROSArduinoBridge/encoder_driver.h | 12 ++++++ .../ROSArduinoBridge/encoder_driver.ino | 41 +++++++++++++++++++ 3 files changed, 77 insertions(+) diff --git a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/ROSArduinoBridge.ino b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/ROSArduinoBridge.ino index 77322d2..ff8bfe1 100644 --- a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/ROSArduinoBridge.ino +++ b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/ROSArduinoBridge.ino @@ -58,6 +58,9 @@ /* The RoboGaia encoder shield */ #define ROBOGAIA + + /* Encoders directly attached to Arduino board */ + //#define ARDUINO_ENC_COUNTER #endif //#define USE_SERVOS // Enable use of PWM servos as defined in servos.h @@ -236,6 +239,27 @@ void setup() { // Initialize the motor controller if used */ #ifdef USE_BASE + #ifdef ARDUINO_ENC_COUNTER + //set as inputs + DDRD &= ~(1<> 2; //read the current state into lowest 2 bits + + left_enc_pos += ENC_STATES[(enc_last & 0x0f)]; + } + + /* Interrupt routine for RIGHT encoder, taking care of actual counting */ + ISR (PCINT1_vect){ + static uint8_t enc_last=0; + + enc_last <<=2; //shift previous state two places + enc_last |= (PINC & (3 << 4)) >> 4; //read the current state into lowest 2 bits + + right_enc_pos += ENC_STATES[(enc_last & 0x0f)]; + } + + /* Wrap the encoder reading function */ + long readEncoder(int i) { + if (i == LEFT) return left_enc_pos; + else return right_enc_pos; + } + + /* Wrap the encoder reset function */ + void resetEncoder(int i) { + if (i == LEFT){ + left_enc_pos=0L; + return; + } else { + right_enc_pos=0L; + return; + } + } #else #error A encoder driver must be selected! #endif From ecff340ffc3f79dc3b45caf2a7d5d3fc5c602881 Mon Sep 17 00:00:00 2001 From: Kristof Robot Date: Sat, 3 Jan 2015 08:39:03 +0100 Subject: [PATCH 17/37] README.md: adding instructions for on-board wheel encoder counter --- README.md | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index daede5c..ad90ffd 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,9 @@ the PC. The base controller requires the use of a motor controller and encoders * Pololu VNH5019 dual motor controller shield (http://www.pololu.com/catalog/product/2502) or Pololu MC33926 dual motor shield (http://www.pololu.com/catalog/product/2503). * Robogaia Mega Encoder shield -(http://www.robogaia.com/two-axis-encoder-counter-mega-shield-version-2.html). +(http://www.robogaia.com/two-axis-encoder-counter-mega-shield-version-2.html) or on-board wheel encoder counters. -**NOTE:** The Robogaia Mega Encoder shield can only be used with an Arduino Mega. +**NOTE:** The Robogaia Mega Encoder shield can only be used with an Arduino Mega. The on-board wheel encoder counters are currently only supported by Arduino Uno. * The library can be easily extended to include support for other motor controllers and encoder hardware or libraries. @@ -438,6 +438,31 @@ where id is the index of the servo as defined in the Arduino sketch (servos.h) a where id is the index of the servo as defined in the Arduino sketch (servos.h) +Using the on-board wheel encoder counters (Arduino Uno only) +------------------------------------------------------------ +The firmware supports on-board wheel encoder counters for Arduino Uno. +This allows connecting wheel encoders directly to the Arduino board, without the need for any additional wheel encoder counter equipment (such as a RoboGaia encoder shield). + +For speed, the code is directly addressing specific Atmega328p ports and interrupts, making this implementation Atmega328p (Arduino Uno) dependent. (It should be easy to adapt for other boards/AVR chips though.) + +To use the on-board wheel encoder counters, connect your wheel encoders to Arduino Uno as follows: + + Left wheel encoder A output -- Arduino UNO pin 2 + Left wheel encoder B output -- Arduino UNO pin 3 + + Right wheel encoder A output -- Arduino UNO pin A4 + Right wheel encoder B output -- Arduino UNO pin A5 + +Make the following changes in the ROSArduinoBridge sketch to disable the RoboGaia encoder shield, and enable the on-board one: + + /* The RoboGaia encoder shield */ + //#define ROBOGAIA + /* Encoders directly attached to Arduino board */ + #define ARDUINO_ENC_COUNTER + +Compile the changes and upload to your controller. + + NOTES ----- If you do not have the hardware required to run the base controller, From 415dde63eecb2b89f20a1c2adec9bf0e5e92dc51 Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Fri, 30 Jan 2015 06:17:47 -0800 Subject: [PATCH 18/37] Changed readEncoder() arguments from 0, 1 to LEFT, RIGHT in diff_controller.h --- .../src/libraries/ROSArduinoBridge/diff_controller.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/diff_controller.h b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/diff_controller.h index 6bb1002..f648209 100644 --- a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/diff_controller.h +++ b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/diff_controller.h @@ -50,14 +50,14 @@ unsigned char moving = 0; // is the base in motion? */ void resetPID(){ leftPID.TargetTicksPerFrame = 0.0; - leftPID.Encoder = readEncoder(0); + leftPID.Encoder = readEncoder(LEFT); leftPID.PrevEnc = leftPID.Encoder; leftPID.output = 0; leftPID.PrevInput = 0; leftPID.ITerm = 0; rightPID.TargetTicksPerFrame = 0.0; - rightPID.Encoder = readEncoder(1); + rightPID.Encoder = readEncoder(RIGHT); rightPID.PrevEnc = rightPID.Encoder; rightPID.output = 0; rightPID.PrevInput = 0; @@ -105,8 +105,8 @@ void doPID(SetPointInfo * p) { /* Read the encoder values and call the PID routine */ void updatePID() { /* Read the encoders */ - leftPID.Encoder = readEncoder(0); - rightPID.Encoder = readEncoder(1); + leftPID.Encoder = readEncoder(LEFT); + rightPID.Encoder = readEncoder(RIGHT); /* If we're not moving there is nothing more to do */ if (!moving){ From 4f45c3467d724cd7a25db3445f4c98dc759e8fd0 Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Mon, 23 Feb 2015 07:03:47 -0800 Subject: [PATCH 19/37] Fixed README servos position is given in radians not degrees --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ad90ffd..918c40b 100644 --- a/README.md +++ b/README.md @@ -430,7 +430,7 @@ where pin is the pin number and value is 0 for LOW and 1 for HIGH. $ rosservice call /arduino/servo_write id pos -where id is the index of the servo as defined in the Arduino sketch (servos.h) and pos is the position in degrees (0 - 180). +where id is the index of the servo as defined in the Arduino sketch (servos.h) and pos is the position in radians (0 - 3.14). **servo\_read** - read the position of a servo From 858fa824b749224ffcb1c9a3c5ddd949867a6fa4 Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Tue, 10 Mar 2015 19:40:40 -0700 Subject: [PATCH 20/37] Added queue_size=5 to all publishers --- ros_arduino_python/nodes/arduino_node.py | 4 ++-- .../src/ros_arduino_python/arduino_sensors.py | 8 ++++---- .../src/ros_arduino_python/base_controller.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ros_arduino_python/nodes/arduino_node.py b/ros_arduino_python/nodes/arduino_node.py index e379615..7925e69 100755 --- a/ros_arduino_python/nodes/arduino_node.py +++ b/ros_arduino_python/nodes/arduino_node.py @@ -59,11 +59,11 @@ class ArduinoROS(): self.cmd_vel = Twist() # A cmd_vel publisher so we can stop the robot when shutting down - self.cmd_vel_pub = rospy.Publisher('cmd_vel', Twist) + self.cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=5) # The SensorState publisher periodically publishes the values of all sensors on # a single topic. - self.sensorStatePub = rospy.Publisher('~sensor_state', SensorState) + self.sensorStatePub = rospy.Publisher('~sensor_state', SensorState, queue_size=5) # A service to position a PWM servo rospy.Service('~servo_write', ServoWrite, self.ServoWriteHandler) diff --git a/ros_arduino_python/src/ros_arduino_python/arduino_sensors.py b/ros_arduino_python/src/ros_arduino_python/arduino_sensors.py index 51a7916..f8f17d4 100755 --- a/ros_arduino_python/src/ros_arduino_python/arduino_sensors.py +++ b/ros_arduino_python/src/ros_arduino_python/arduino_sensors.py @@ -87,7 +87,7 @@ class AnalogSensor(Sensor): self.msg = Analog() self.msg.header.frame_id = self.frame_id - self.pub = rospy.Publisher("~sensor/" + self.name, Analog) + self.pub = rospy.Publisher("~sensor/" + self.name, Analog, queue_size=5) if self.direction == "output": self.controller.pin_mode(self.pin, OUTPUT) @@ -111,7 +111,7 @@ class AnalogFloatSensor(Sensor): self.msg = AnalogFloat() self.msg.header.frame_id = self.frame_id - self.pub = rospy.Publisher("~sensor/" + self.name, AnalogFloat) + self.pub = rospy.Publisher("~sensor/" + self.name, AnalogFloat, queue_size=5) if self.direction == "output": self.controller.pin_mode(self.pin, OUTPUT) @@ -136,7 +136,7 @@ class DigitalSensor(Sensor): self.msg = Digital() self.msg.header.frame_id = self.frame_id - self.pub = rospy.Publisher("~sensor/" + self.name, Digital) + self.pub = rospy.Publisher("~sensor/" + self.name, Digital, queue_size=5) if self.direction == "output": self.controller.pin_mode(self.pin, OUTPUT) @@ -163,7 +163,7 @@ class RangeSensor(Sensor): self.msg = Range() self.msg.header.frame_id = self.frame_id - self.pub = rospy.Publisher("~sensor/" + self.name, Range) + self.pub = rospy.Publisher("~sensor/" + self.name, Range, queue_size=5) def read_value(self): self.msg.header.stamp = rospy.Time.now() diff --git a/ros_arduino_python/src/ros_arduino_python/base_controller.py b/ros_arduino_python/src/ros_arduino_python/base_controller.py index 246be0f..813e873 100755 --- a/ros_arduino_python/src/ros_arduino_python/base_controller.py +++ b/ros_arduino_python/src/ros_arduino_python/base_controller.py @@ -87,7 +87,7 @@ class BaseController: self.arduino.reset_encoders() # Set up the odometry broadcaster - self.odomPub = rospy.Publisher('odom', Odometry) + self.odomPub = rospy.Publisher('odom', Odometry, queue_size=5) self.odomBroadcaster = TransformBroadcaster() rospy.loginfo("Started base controller for a base of " + str(self.wheel_track) + "m wide with " + str(self.encoder_resolution) + " ticks per rev") From ddecaa0b2cd33de0470e006167f6cbab40f65ea1 Mon Sep 17 00:00:00 2001 From: theroboticsheep Date: Fri, 17 Apr 2015 14:52:46 -0700 Subject: [PATCH 21/37] added speed controlled servo sweep --- .../ROSArduinoBridge/ROSArduinoBridge.ino | 26 ++++--- .../src/libraries/ROSArduinoBridge/servos.h | 38 ++++++++-- .../src/libraries/ROSArduinoBridge/servos.ino | 74 +++++++++++++++++++ 3 files changed, 120 insertions(+), 18 deletions(-) create mode 100644 ros_arduino_firmware/src/libraries/ROSArduinoBridge/servos.ino diff --git a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/ROSArduinoBridge.ino b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/ROSArduinoBridge.ino index ff8bfe1..466dd19 100644 --- a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/ROSArduinoBridge.ino +++ b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/ROSArduinoBridge.ino @@ -45,8 +45,8 @@ * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ -#define USE_BASE // Enable the base controller code -//#undef USE_BASE // Disable the base controller code +//#define USE_BASE // Enable the base controller code +#undef USE_BASE // Disable the base controller code /* Define the motor controller and encoder library you are using */ #ifdef USE_BASE @@ -63,8 +63,8 @@ //#define ARDUINO_ENC_COUNTER #endif -//#define USE_SERVOS // Enable use of PWM servos as defined in servos.h -#undef USE_SERVOS // Disable use of PWM servos +#define USE_SERVOS // Enable use of PWM servos as defined in servos.h +//#undef USE_SERVOS // Disable use of PWM servos /* Serial port baud rate */ #define BAUDRATE 57600 @@ -184,11 +184,11 @@ int runCommand() { break; #ifdef USE_SERVOS case SERVO_WRITE: - servos[arg1].write(arg2); + servos[arg1].setTargetPosition(arg2); Serial.println("OK"); break; case SERVO_READ: - Serial.println(servos[arg1].read()); + Serial.println(servos[arg1].getServo().read()); break; #endif @@ -268,7 +268,7 @@ void setup() { #ifdef USE_SERVOS int i; for (i = 0; i < N_SERVOS; i++) { - servos[i].attach(servoPins[i]); + servos[i].initServo(servoPins[i], servoInitPosition[i]); } #endif } @@ -330,12 +330,14 @@ void loop() { setMotorSpeeds(0, 0); moving = 0; } +#endif +// Sweep servos +#ifdef USE_SERVOS + int i; + for (i = 0; i < N_SERVOS; i++) { + servos[i].doSweep(); + } #endif } - - - - - diff --git a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/servos.h b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/servos.h index 4b97050..ff80420 100644 --- a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/servos.h +++ b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/servos.h @@ -1,9 +1,35 @@ -/* Define the attachment of any servos here. - The example shows two servos attached on pins 3 and 5. -*/ +#ifndef SERVOS_H +#define SERVOS_H -#define N_SERVOS 2 -Servo servos [N_SERVOS]; -byte servoPins [N_SERVOS] = {3, 5}; +#define N_SERVOS 1 +// This delay in milliseconds determines determines the pause +// between each one degree step the servo travels. Increasing +// this number will make the servo sweep more slowly. +// Decreasing this number will make the servo sweep more quickly. +#define SWEEP_COMMAND_INTERVAL 150 // ms + +byte servoPins [N_SERVOS] = { 3 }; +byte servoInitPosition [N_SERVOS] = { 90 }; // degrees + + +class SweepServo +{ + public: + SweepServo(); + void initServo(int servoPin, int initPosition); + void doSweep(); + void setTargetPosition(int position); + Servo getServo(); + + private: + Servo servo; + int currentPositionDegrees; + int targetPositionDegrees; + long lastSweepCommand; +}; + +SweepServo servos [N_SERVOS]; + +#endif diff --git a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/servos.ino b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/servos.ino new file mode 100644 index 0000000..fc68f60 --- /dev/null +++ b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/servos.ino @@ -0,0 +1,74 @@ +/*************************************************************** + Servo Sweep - by Nathaniel Gallinger + + Sweep servos one degree step at a time with a user defined + delay in between steps. Supports changing direction + mid-sweep. Important for applications such as robotic arms + where the stock servo speed is too fast for the strength + of your system. + + *************************************************************/ + +#ifdef USE_SERVOS + + +// Constructor +SweepServo::SweepServo() +{ + this->currentPositionDegrees = 0; + this->targetPositionDegrees = 0; + this->lastSweepCommand = 0; +} + + +// Init +void SweepServo::initServo(int servoPin, int initPosition) +{ + this->servo.attach(servoPin); + this->currentPositionDegrees = initPosition; + this->targetPositionDegrees = initPosition; + this->lastSweepCommand = millis(); +} + + +// Perform Sweep +void SweepServo::doSweep() +{ + + // Get ellapsed time + int delta = millis() - this->lastSweepCommand; + + // Check if time for a step + if (delta > SWEEP_COMMAND_INTERVAL) { + // Check step direction + if (this->targetPositionDegrees > this->currentPositionDegrees) { + this->currentPositionDegrees++; + this->servo.write(this->currentPositionDegrees); + } + else if (this->targetPositionDegrees < this->currentPositionDegrees) { + this->currentPositionDegrees--; + this->servo.write(this->currentPositionDegrees); + } + // if target == current position, do nothing + + // reset timer + this->lastSweepCommand = millis(); + } +} + + +// Set a new target position +void SweepServo::setTargetPosition(int position) +{ + this->targetPositionDegrees = position; +} + + +// Accessor for servo object +Servo SweepServo::getServo() +{ + return this->servo; +} + + +#endif From eda206f68c2cf6a4426004787c304610f16a8fbc Mon Sep 17 00:00:00 2001 From: theroboticsheep Date: Fri, 17 Apr 2015 15:04:23 -0700 Subject: [PATCH 22/37] changed default sweep delay to zero so that servos will behave normally unless delay is increased --- ros_arduino_firmware/src/libraries/ROSArduinoBridge/servos.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/servos.h b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/servos.h index ff80420..f0f404e 100644 --- a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/servos.h +++ b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/servos.h @@ -8,7 +8,7 @@ // between each one degree step the servo travels. Increasing // this number will make the servo sweep more slowly. // Decreasing this number will make the servo sweep more quickly. -#define SWEEP_COMMAND_INTERVAL 150 // ms +#define SWEEP_COMMAND_INTERVAL 0 // ms byte servoPins [N_SERVOS] = { 3 }; byte servoInitPosition [N_SERVOS] = { 90 }; // degrees From e9810841b48f0eb95362657bbe94cf1ae5823bf5 Mon Sep 17 00:00:00 2001 From: theroboticsheep Date: Sat, 18 Apr 2015 18:29:53 -0700 Subject: [PATCH 23/37] added support for rotating servos at different speeds --- .../ROSArduinoBridge/ROSArduinoBridge.ino | 15 +++++++----- .../src/libraries/ROSArduinoBridge/servos.h | 23 +++++++++++++------ .../src/libraries/ROSArduinoBridge/servos.ino | 8 +++++-- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/ROSArduinoBridge.ino b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/ROSArduinoBridge.ino index 466dd19..5de3726 100644 --- a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/ROSArduinoBridge.ino +++ b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/ROSArduinoBridge.ino @@ -265,12 +265,15 @@ void setup() { #endif /* Attach servos if used */ -#ifdef USE_SERVOS - int i; - for (i = 0; i < N_SERVOS; i++) { - servos[i].initServo(servoPins[i], servoInitPosition[i]); - } -#endif + #ifdef USE_SERVOS + int i; + for (i = 0; i < N_SERVOS; i++) { + servos[i].initServo( + servoPins[i], + stepDelay[i], + servoInitPosition[i]); + } + #endif } /* Enter the main loop. Read and parse input from the serial port diff --git a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/servos.h b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/servos.h index f0f404e..d2b6d21 100644 --- a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/servos.h +++ b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/servos.h @@ -2,29 +2,38 @@ #define SERVOS_H -#define N_SERVOS 1 +#define N_SERVOS 2 -// This delay in milliseconds determines determines the pause +// This delay in milliseconds determines the pause // between each one degree step the servo travels. Increasing // this number will make the servo sweep more slowly. -// Decreasing this number will make the servo sweep more quickly. -#define SWEEP_COMMAND_INTERVAL 0 // ms +// Decreasing this number will make the servo sweep more quickly. +// Zero is the default number and will make the servos spin at +// full speed. 150 ms makes them spin very slowly. +int stepDelay [N_SERVOS] = { 0, 0 }; // ms -byte servoPins [N_SERVOS] = { 3 }; -byte servoInitPosition [N_SERVOS] = { 90 }; // degrees +// Pins +byte servoPins [N_SERVOS] = { 3, 4 }; + +// Initial Position +byte servoInitPosition [N_SERVOS] = { 90, 90 }; // [0, 180] degrees class SweepServo { public: SweepServo(); - void initServo(int servoPin, int initPosition); + void initServo( + int servoPin, + int stepDelayMs, + int initPosition); void doSweep(); void setTargetPosition(int position); Servo getServo(); private: Servo servo; + int stepDelayMs; int currentPositionDegrees; int targetPositionDegrees; long lastSweepCommand; diff --git a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/servos.ino b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/servos.ino index fc68f60..5ba344c 100644 --- a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/servos.ino +++ b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/servos.ino @@ -22,9 +22,13 @@ SweepServo::SweepServo() // Init -void SweepServo::initServo(int servoPin, int initPosition) +void SweepServo::initServo( + int servoPin, + int stepDelayMs, + int initPosition) { this->servo.attach(servoPin); + this->stepDelayMs = stepDelayMs; this->currentPositionDegrees = initPosition; this->targetPositionDegrees = initPosition; this->lastSweepCommand = millis(); @@ -39,7 +43,7 @@ void SweepServo::doSweep() int delta = millis() - this->lastSweepCommand; // Check if time for a step - if (delta > SWEEP_COMMAND_INTERVAL) { + if (delta > this->stepDelayMs) { // Check step direction if (this->targetPositionDegrees > this->currentPositionDegrees) { this->currentPositionDegrees++; From 4ee96157a64df53a8e66aa5f3f075cc4ceb73c6e Mon Sep 17 00:00:00 2001 From: "Wayne C. Gramlich" Date: Tue, 12 May 2015 17:16:29 -0700 Subject: [PATCH 24/37] Implemented ~motors_reversed parameter. Added ~left_motor_reversed and ~right_motor_reversed parameter. --- ros_arduino_python/config/arduino_params.yaml | 2 ++ .../src/ros_arduino_python/arduino_driver.py | 22 +++++++++++++++++++ .../src/ros_arduino_python/base_controller.py | 5 ++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ros_arduino_python/config/arduino_params.yaml b/ros_arduino_python/config/arduino_params.yaml index 9acbe3d..96513da 100644 --- a/ros_arduino_python/config/arduino_params.yaml +++ b/ros_arduino_python/config/arduino_params.yaml @@ -22,6 +22,8 @@ base_frame: base_link #encoder_resolution: 8384 # from Pololu for 131:1 motors #gear_reduction: 1.0 #motors_reversed: True +#left_motor_reversed: True +#right_motor_reversed: True # === PID parameters #Kp: 10 diff --git a/ros_arduino_python/src/ros_arduino_python/arduino_driver.py b/ros_arduino_python/src/ros_arduino_python/arduino_driver.py index f210d14..b9b6b2a 100755 --- a/ros_arduino_python/src/ros_arduino_python/arduino_driver.py +++ b/ros_arduino_python/src/ros_arduino_python/arduino_driver.py @@ -49,6 +49,9 @@ class Arduino: self.encoder_count = 0 self.writeTimeout = timeout self.interCharTimeout = timeout / 30. + self.motors_reversed = False + self.left_motor_reversed = False + self.right_motor_reversed = False # Keep things thread safe self.mutex = thread.allocate_lock() @@ -92,6 +95,12 @@ class Arduino: ''' self.port.close() + def motors_configure(motors_reversed = False, + left_motor_reversed = False, right_motor_reversed = False): + self.motors_reversed = motors_reversed + self.left_motor_reversed = left_motor_reversed + self.right_motor_reversed = right_motor_reversed + def send(self, cmd): ''' This command should not be used on its own: it is called by the execute commands below in a thread safe manner. @@ -267,6 +276,12 @@ class Arduino: raise SerialException return None else: + if self.motors_reversed: + values[0], values[1] = values[1], values[0] + if self.left_motor_reversed: + values[0] = -values[0] + if self.right_motor_reversed: + values[1] = -values[1] return values def reset_encoders(self): @@ -277,6 +292,13 @@ class Arduino: def drive(self, right, left): ''' Speeds are given in encoder ticks per PID interval ''' + if self.left_motor_reversed: + left = -left + if self.right_motor_reversed: + right = -right + if self.motors_reversed: + left, right = right, left + return self.execute_ack('m %d %d' %(right, left)) def drive_m_per_s(self, right, left): diff --git a/ros_arduino_python/src/ros_arduino_python/base_controller.py b/ros_arduino_python/src/ros_arduino_python/base_controller.py index 813e873..7c3b29c 100755 --- a/ros_arduino_python/src/ros_arduino_python/base_controller.py +++ b/ros_arduino_python/src/ros_arduino_python/base_controller.py @@ -50,7 +50,10 @@ class BaseController: self.accel_limit = rospy.get_param('~accel_limit', 0.1) self.motors_reversed = rospy.get_param("~motors_reversed", False) - + self.left_motor_reversed = rospy.get_param("~left_motor_reversed", False) + self.right_motor_reversed = rospy.get_param("~right_motor_reversed", False) + arduino.motors_configure(self.motors_reversed, self.left_motor_reverse, self.right_motor_reverse) + # Set up PID parameters and check for missing values self.setup_pid(pid_params) From 1d43339c009e196774937b4d47c003eef15e5d4a Mon Sep 17 00:00:00 2001 From: "Wayne C. Gramlich" Date: Wed, 13 May 2015 19:33:21 -0700 Subject: [PATCH 25/37] Fixed some typos. --- ros_arduino_python/src/ros_arduino_python/arduino_driver.py | 2 +- ros_arduino_python/src/ros_arduino_python/base_controller.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ros_arduino_python/src/ros_arduino_python/arduino_driver.py b/ros_arduino_python/src/ros_arduino_python/arduino_driver.py index b9b6b2a..ab48748 100755 --- a/ros_arduino_python/src/ros_arduino_python/arduino_driver.py +++ b/ros_arduino_python/src/ros_arduino_python/arduino_driver.py @@ -95,7 +95,7 @@ class Arduino: ''' self.port.close() - def motors_configure(motors_reversed = False, + def motors_configure(self, motors_reversed = False, left_motor_reversed = False, right_motor_reversed = False): self.motors_reversed = motors_reversed self.left_motor_reversed = left_motor_reversed diff --git a/ros_arduino_python/src/ros_arduino_python/base_controller.py b/ros_arduino_python/src/ros_arduino_python/base_controller.py index 7c3b29c..2d37526 100755 --- a/ros_arduino_python/src/ros_arduino_python/base_controller.py +++ b/ros_arduino_python/src/ros_arduino_python/base_controller.py @@ -52,7 +52,7 @@ class BaseController: self.motors_reversed = rospy.get_param("~motors_reversed", False) self.left_motor_reversed = rospy.get_param("~left_motor_reversed", False) self.right_motor_reversed = rospy.get_param("~right_motor_reversed", False) - arduino.motors_configure(self.motors_reversed, self.left_motor_reverse, self.right_motor_reverse) + arduino.motors_configure(self.motors_reversed, self.left_motor_reversed, self.right_motor_reversed) # Set up PID parameters and check for missing values self.setup_pid(pid_params) From 8963ce8c59573f14dee25394696a1d3f6cc7d765 Mon Sep 17 00:00:00 2001 From: "Wayne C. Gramlich" Date: Thu, 14 May 2015 08:54:55 -0700 Subject: [PATCH 26/37] Backed out changes that were accidently checked into hbrobotics repository. Explaination: I am president of Homebrew Roboics, so I am also an 'owner' of the hbrobotics repository. By accident, I checked in some untested changes into the hbrobotics web site, when I thought I was checking them into a staging repository. Me bad. This should get us back to the way we were at pull request #18. --- ros_arduino_python/config/arduino_params.yaml | 2 -- .../src/ros_arduino_python/arduino_driver.py | 22 ------------------- .../src/ros_arduino_python/base_controller.py | 5 +---- 3 files changed, 1 insertion(+), 28 deletions(-) diff --git a/ros_arduino_python/config/arduino_params.yaml b/ros_arduino_python/config/arduino_params.yaml index 96513da..9acbe3d 100644 --- a/ros_arduino_python/config/arduino_params.yaml +++ b/ros_arduino_python/config/arduino_params.yaml @@ -22,8 +22,6 @@ base_frame: base_link #encoder_resolution: 8384 # from Pololu for 131:1 motors #gear_reduction: 1.0 #motors_reversed: True -#left_motor_reversed: True -#right_motor_reversed: True # === PID parameters #Kp: 10 diff --git a/ros_arduino_python/src/ros_arduino_python/arduino_driver.py b/ros_arduino_python/src/ros_arduino_python/arduino_driver.py index ab48748..f210d14 100755 --- a/ros_arduino_python/src/ros_arduino_python/arduino_driver.py +++ b/ros_arduino_python/src/ros_arduino_python/arduino_driver.py @@ -49,9 +49,6 @@ class Arduino: self.encoder_count = 0 self.writeTimeout = timeout self.interCharTimeout = timeout / 30. - self.motors_reversed = False - self.left_motor_reversed = False - self.right_motor_reversed = False # Keep things thread safe self.mutex = thread.allocate_lock() @@ -95,12 +92,6 @@ class Arduino: ''' self.port.close() - def motors_configure(self, motors_reversed = False, - left_motor_reversed = False, right_motor_reversed = False): - self.motors_reversed = motors_reversed - self.left_motor_reversed = left_motor_reversed - self.right_motor_reversed = right_motor_reversed - def send(self, cmd): ''' This command should not be used on its own: it is called by the execute commands below in a thread safe manner. @@ -276,12 +267,6 @@ class Arduino: raise SerialException return None else: - if self.motors_reversed: - values[0], values[1] = values[1], values[0] - if self.left_motor_reversed: - values[0] = -values[0] - if self.right_motor_reversed: - values[1] = -values[1] return values def reset_encoders(self): @@ -292,13 +277,6 @@ class Arduino: def drive(self, right, left): ''' Speeds are given in encoder ticks per PID interval ''' - if self.left_motor_reversed: - left = -left - if self.right_motor_reversed: - right = -right - if self.motors_reversed: - left, right = right, left - return self.execute_ack('m %d %d' %(right, left)) def drive_m_per_s(self, right, left): diff --git a/ros_arduino_python/src/ros_arduino_python/base_controller.py b/ros_arduino_python/src/ros_arduino_python/base_controller.py index 2d37526..813e873 100755 --- a/ros_arduino_python/src/ros_arduino_python/base_controller.py +++ b/ros_arduino_python/src/ros_arduino_python/base_controller.py @@ -50,10 +50,7 @@ class BaseController: self.accel_limit = rospy.get_param('~accel_limit', 0.1) self.motors_reversed = rospy.get_param("~motors_reversed", False) - self.left_motor_reversed = rospy.get_param("~left_motor_reversed", False) - self.right_motor_reversed = rospy.get_param("~right_motor_reversed", False) - arduino.motors_configure(self.motors_reversed, self.left_motor_reversed, self.right_motor_reversed) - + # Set up PID parameters and check for missing values self.setup_pid(pid_params) From b02f9aea5653f989836557f64dc661ee15bef3fe Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Tue, 25 Aug 2015 06:18:25 -0700 Subject: [PATCH 27/37] Updated README for indigo-devel branch --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 918c40b..408cc70 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Overview -------- -This branch (hydro-devel) is intended for ROS Hydro and above, and uses the Catkin buildsystem. It may also be compatible with ROS Groovy. +This branch (indigo-devel) is intended for ROS Indigo and above, and uses the Catkin buildsystem. It may also be compatible with ROS Hydro. This ROS stack includes an Arduino library (called ROSArduinoBridge) and a collection of ROS packages for controlling an Arduino-based robot using standard ROS messages and services. The stack does **not** depend on ROS Serial. From b7f922f7e7c9f61589c9db98a7f380a28a140c90 Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Sun, 22 Nov 2015 17:06:20 -0800 Subject: [PATCH 28/37] Fixed ifdef typo in encoder_driver.ino --- .../src/libraries/ROSArduinoBridge/encoder_driver.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/encoder_driver.ino b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/encoder_driver.ino index 294cdb3..e1792bb 100644 --- a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/encoder_driver.ino +++ b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/encoder_driver.ino @@ -9,7 +9,7 @@ #ifdef USE_BASE -#if defined ROBOGAIA +#ifdef ROBOGAIA /* The Robogaia Mega Encoder shield */ #include "MegaEncoderCounter.h" From c958e590cce930e04c10d8ba33068387e275ba1f Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Sun, 22 Nov 2015 17:15:11 -0800 Subject: [PATCH 29/37] Fixed some indentation in arduino_node.py --- ros_arduino_python/nodes/arduino_node.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ros_arduino_python/nodes/arduino_node.py b/ros_arduino_python/nodes/arduino_node.py index 7925e69..50f2185 100755 --- a/ros_arduino_python/nodes/arduino_node.py +++ b/ros_arduino_python/nodes/arduino_node.py @@ -75,12 +75,12 @@ class ArduinoROS(): rospy.Service('~digital_set_direction', DigitalSetDirection, self.DigitalSetDirectionHandler) # A service to turn a digital sensor on or off - rospy.Service('~digital_write', DigitalWrite, self.DigitalWriteHandler) - - # A service to set pwm values for the pins - rospy.Service('~analog_write', AnalogWrite, self.AnalogWriteHandler) + rospy.Service('~digital_write', DigitalWrite, self.DigitalWriteHandler) - # Initialize the controlller + # A service to set pwm values for the pins + rospy.Service('~analog_write', AnalogWrite, self.AnalogWriteHandler) + + # Initialize the controlller self.controller = Arduino(self.port, self.baud, self.timeout) # Make the connection From c26830b5c4e12e94997783ca79ba3171fc943b09 Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Sat, 5 Dec 2015 07:22:50 -0800 Subject: [PATCH 30/37] Added ArduinoConstants.msg to enumerate LOW, HIGH, INPUT, OUTPUT --- ros_arduino_msgs/CMakeLists.txt | 1 + ros_arduino_msgs/msg/ArduinoConstants.msg | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 ros_arduino_msgs/msg/ArduinoConstants.msg diff --git a/ros_arduino_msgs/CMakeLists.txt b/ros_arduino_msgs/CMakeLists.txt index bd6cfb3..44a57fa 100644 --- a/ros_arduino_msgs/CMakeLists.txt +++ b/ros_arduino_msgs/CMakeLists.txt @@ -6,6 +6,7 @@ find_package(catkin REQUIRED COMPONENTS std_msgs message_generation) add_message_files(FILES AnalogFloat.msg Analog.msg + ArduinoConstants.msg Digital.msg SensorState.msg ) diff --git a/ros_arduino_msgs/msg/ArduinoConstants.msg b/ros_arduino_msgs/msg/ArduinoConstants.msg new file mode 100644 index 0000000..0fe70f4 --- /dev/null +++ b/ros_arduino_msgs/msg/ArduinoConstants.msg @@ -0,0 +1,5 @@ +# Arduino-style constants +uint8 LOW=0 +uint8 HIGH=1 +uint8 INPUT=0 +uint8 OUTPUT=1 From 1f3ae62769f06bcadd57268f778084cab7f2b18a Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Sat, 5 Dec 2015 19:07:29 -0800 Subject: [PATCH 31/37] Added AnalogRead (analog_Read) and DigitaRead (digital_read) services --- ros_arduino_msgs/CMakeLists.txt | 2 ++ ros_arduino_msgs/srv/AnalogRead.srv | 3 +++ ros_arduino_msgs/srv/DigitalRead.srv | 3 +++ ros_arduino_python/nodes/arduino_node.py | 16 +++++++++++++++- 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100755 ros_arduino_msgs/srv/AnalogRead.srv create mode 100755 ros_arduino_msgs/srv/DigitalRead.srv diff --git a/ros_arduino_msgs/CMakeLists.txt b/ros_arduino_msgs/CMakeLists.txt index 44a57fa..373ae0a 100644 --- a/ros_arduino_msgs/CMakeLists.txt +++ b/ros_arduino_msgs/CMakeLists.txt @@ -14,9 +14,11 @@ add_message_files(FILES add_service_files(FILES DigitalSetDirection.srv DigitalWrite.srv + DigitalRead.srv ServoRead.srv ServoWrite.srv AnalogWrite.srv + AnalogRead.srv ) generate_messages( diff --git a/ros_arduino_msgs/srv/AnalogRead.srv b/ros_arduino_msgs/srv/AnalogRead.srv new file mode 100755 index 0000000..24014ed --- /dev/null +++ b/ros_arduino_msgs/srv/AnalogRead.srv @@ -0,0 +1,3 @@ +uint8 pin +--- +uint16 value diff --git a/ros_arduino_msgs/srv/DigitalRead.srv b/ros_arduino_msgs/srv/DigitalRead.srv new file mode 100755 index 0000000..605f196 --- /dev/null +++ b/ros_arduino_msgs/srv/DigitalRead.srv @@ -0,0 +1,3 @@ +uint8 pin +--- +bool value diff --git a/ros_arduino_python/nodes/arduino_node.py b/ros_arduino_python/nodes/arduino_node.py index 50f2185..d281f9e 100755 --- a/ros_arduino_python/nodes/arduino_node.py +++ b/ros_arduino_python/nodes/arduino_node.py @@ -75,10 +75,16 @@ class ArduinoROS(): rospy.Service('~digital_set_direction', DigitalSetDirection, self.DigitalSetDirectionHandler) # A service to turn a digital sensor on or off - rospy.Service('~digital_write', DigitalWrite, self.DigitalWriteHandler) + rospy.Service('~digital_write', DigitalWrite, self.DigitalWriteHandler) + + # A service to read the value of a digital sensor + rospy.Service('~digital_read', DigitalRead, self.DigitalReadHandler) # A service to set pwm values for the pins rospy.Service('~analog_write', AnalogWrite, self.AnalogWriteHandler) + + # A service to read the value of an analog sensor + rospy.Service('~analog_read', AnalogRead, self.AnalogReadHandler) # Initialize the controlller self.controller = Arduino(self.port, self.baud, self.timeout) @@ -176,10 +182,18 @@ class ArduinoROS(): def DigitalWriteHandler(self, req): self.controller.digital_write(req.pin, req.value) return DigitalWriteResponse() + + def DigitalReadHandler(self, req): + value = self.controller.digital_read(req.pin) + return DigitalReadResponse(value) def AnalogWriteHandler(self, req): self.controller.analog_write(req.pin, req.value) return AnalogWriteResponse() + + def AnalogReadHandler(self, req): + value = self.controller.analog_read(req.pin) + return AnalogReadResponse(value) def shutdown(self): # Stop the robot From 32245aa9d39b7f0f0ae28db81f7fbed9f6034de3 Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Sun, 6 Dec 2015 16:13:37 -0800 Subject: [PATCH 32/37] Fixed ServoRead service handler so that it actually returns a value other than 0 --- ros_arduino_python/nodes/arduino_node.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ros_arduino_python/nodes/arduino_node.py b/ros_arduino_python/nodes/arduino_node.py index d281f9e..eae7a73 100755 --- a/ros_arduino_python/nodes/arduino_node.py +++ b/ros_arduino_python/nodes/arduino_node.py @@ -172,8 +172,8 @@ class ArduinoROS(): return ServoWriteResponse() def ServoReadHandler(self, req): - self.controller.servo_read(req.id) - return ServoReadResponse() + pos = self.controller.servo_read(req.id) + return ServoReadResponse(pos) def DigitalSetDirectionHandler(self, req): self.controller.pin_mode(req.pin, req.direction) From 06884afb879048e4a7bb693031cbf34454541e79 Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Sun, 6 Dec 2015 16:14:52 -0800 Subject: [PATCH 33/37] Changed AnalogWrite service data value from float32 to uint16 --- ros_arduino_msgs/srv/AnalogWrite.srv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros_arduino_msgs/srv/AnalogWrite.srv b/ros_arduino_msgs/srv/AnalogWrite.srv index 5973435..6169d65 100644 --- a/ros_arduino_msgs/srv/AnalogWrite.srv +++ b/ros_arduino_msgs/srv/AnalogWrite.srv @@ -1,3 +1,3 @@ uint8 pin -float32 value +uint16 value --- From b1b6caf47ca7b1ef200e97047f070626aab403c5 Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Sun, 6 Dec 2015 16:16:11 -0800 Subject: [PATCH 34/37] Fixed a couple of comment typos in base_controller.py --- .../src/ros_arduino_python/base_controller.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ros_arduino_python/src/ros_arduino_python/base_controller.py b/ros_arduino_python/src/ros_arduino_python/base_controller.py index 813e873..46d19ed 100755 --- a/ros_arduino_python/src/ros_arduino_python/base_controller.py +++ b/ros_arduino_python/src/ros_arduino_python/base_controller.py @@ -68,7 +68,7 @@ class BaseController: self.t_delta = rospy.Duration(1.0 / self.rate) self.t_next = now + self.t_delta - # internal data + # Internal data self.enc_left = None # encoder readings self.enc_right = None self.x = 0 # position in xy plane @@ -80,7 +80,7 @@ class BaseController: self.v_des_right = 0 self.last_cmd_vel = now - # subscriptions + # Subscriptions rospy.Subscriber("cmd_vel", Twist, self.cmdVelCallback) # Clear any old odometry info @@ -131,7 +131,7 @@ class BaseController: self.then = now dt = dt.to_sec() - # calculate odometry + # Calculate odometry if self.enc_left == None: dright = 0 dleft = 0 From 1a560fa50869122fe5c3c7310bf74e8371c55b7b Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Sun, 6 Dec 2015 21:36:15 -0800 Subject: [PATCH 35/37] Replaced #if defined with #ifdef statements in encoder_driver.ino --- .../src/libraries/ROSArduinoBridge/encoder_driver.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/encoder_driver.ino b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/encoder_driver.ino index e1792bb..85d401d 100644 --- a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/encoder_driver.ino +++ b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/encoder_driver.ino @@ -1,7 +1,7 @@ /* ************************************************************* Encoder definitions - Add a "#if defined" block to this file to include support for + Add an "#ifdef" block to this file to include support for a particular encoder board or library. Then add the appropriate #define near the top of the main ROSArduinoBridge.ino file. @@ -27,7 +27,7 @@ if (i == LEFT) return encoders.YAxisReset(); else return encoders.XAxisReset(); } -#elif defined ARDUINO_ENC_COUNTER +#elif ARDUINO_ENC_COUNTER volatile long left_enc_pos = 0L; volatile long right_enc_pos = 0L; static const int8_t ENC_STATES [] = {0,1,-1,0,-1,0,0,1,1,0,0,-1,0,-1,1,0}; //encoder lookup table From 9fb4e4e604e16f0a28c2605d14b37310c764d097 Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Sun, 6 Dec 2015 21:37:18 -0800 Subject: [PATCH 36/37] Now include sensor topic names in INFO statements during startup. --- ros_arduino_python/nodes/arduino_node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros_arduino_python/nodes/arduino_node.py b/ros_arduino_python/nodes/arduino_node.py index eae7a73..103179d 100755 --- a/ros_arduino_python/nodes/arduino_node.py +++ b/ros_arduino_python/nodes/arduino_node.py @@ -129,7 +129,7 @@ class ArduinoROS(): # self.sensors[len(self.sensors)]['output_pin'] = params['output_pin'] self.mySensors.append(sensor) - rospy.loginfo(name + " " + str(params)) + rospy.loginfo(name + " " + str(params) + " published on topic " + rospy.get_name() + "/sensor/" + name) # Initialize the base controller if used if self.use_base_controller: From ca9dc66cd3e5ede6c9c94cd728d4ef5bb07a0d6a Mon Sep 17 00:00:00 2001 From: Patrick Goebel Date: Sun, 6 Dec 2015 21:42:07 -0800 Subject: [PATCH 37/37] Changed #if defined to #ifdef in motor_driver.ino --- .../src/libraries/ROSArduinoBridge/motor_driver.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/motor_driver.ino b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/motor_driver.ino index c822ef5..27c76bc 100644 --- a/ros_arduino_firmware/src/libraries/ROSArduinoBridge/motor_driver.ino +++ b/ros_arduino_firmware/src/libraries/ROSArduinoBridge/motor_driver.ino @@ -9,7 +9,7 @@ #ifdef USE_BASE -#if defined POLOLU_VNH5019 +#ifdef POLOLU_VNH5019 /* Include the Pololu library */ #include "DualVNH5019MotorShield.h"