arduinopid仿真软件

2016-01-12 16:43:36 CCJHDOPC 阅读数 6036
Arduino入门教程--连载
Arduino学习笔记
2016-03-24 14:03:37 xuanyuanlei1020 阅读数 5412

原文章地址:http://brettbeauregard.com/blog/2012/01/arduino-pid-autotune-library/

Arduino PID Autotune Library

终于,我发布了一个自动调PID参数的一个库来完善Arduino PID库文件。在我发布当前版本的PID库的时候,我做了大量的博客让读者明白,这个库内部是怎么运行的。但是也不是那么深入,这个也是这篇博客的目标。我会解释这个自动调谐库能够完成什么,是怎么完成的。

Attribution

很多年来,我都想写一个自动调谐库,但是因为我和雇主的一些协议,我不能发布一个。但是!当我发现William Spinelli 写的AutotunerPID Toolkit的时候,我便开始打算写一个了。我自己的公司对于我发布、评论和维持开源项目没有提出异议。

对于matlab的代码,我对于峰值检测部分做了一些微调,将标准形式(Kc, Ti, Td)调为理想形式(Kp, Ki, Kd),就像以往一样,所有的权利归于 Spinelli先生。

理论基础

对于一个PID控制器来说,最好的调谐参数 (Kp, Ki, Kd,) 是取决于控制器控制的是什么。一个烤箱的最佳调谐参数不一定是烤牛排工具( sous-vide cooker)的最佳参数。所有的自动调谐研究者都试图发现控制器控制的到底是什么,然后再计算调谐参数。自动调谐有许多的方法,但是大多数都是改变PID的输出,然后观察输入的响应。

这个库用到的方法是著名的延迟方法,它的工作方式如下:

最开始使output和input都是在稳态,然后使output在某个方向上改变某个位移D。当Input穿过触发线的时候,output改变为另一个方向的位移D。通过分析,峰峰值的距离和它们与输出的关系,这些自动调谐工具可以分辨出两种不同的过程。最终,不同的系统得到特定的PID参数。

应用

这个理论在理想条件下运行良好,但是在真实的世界,他并不运行的那么良好。因为在工作条件下,输入信号通常是噪音繁多,这将导致连个主要问题。

问题1:何时改变 When to step?

当含噪声的信号不断改变方向的时候,Input 有可能在会重复通过触发线很多次。这个问题可以导致输出会发生严重的震荡,如果更严重的话,会对物品造成损害。


我选择回避这种问题的方式是用户指定一个噪声带noise band。事实上,我们是创造两条触发线。因为,这两条线的距离是噪声的幅值(如果设置妥当),这样的话,因为噪声的原因多次触发的情况就会很少发生。

问题 #2: 峰值检测

在仿真世界,检测峰值很容易;当输入信号改变方向,那就有一个最大值和最小值(取决于是上升还是下降)。但是在一个有噪声的世界,这种方法就失效了。

每一个噪声信号都会造成一个方向的改变。为了处理这种问题,我加了一个“向后看"(“look-back time” )的参数 。当然这个是一个不好听的名字,请你一定要告诉我,如果你能想到一个更好的名字。

无论如何,用户定义一个窗口期,比如说10秒。那么这个库就会比较当前的点和前10秒钟点。如果当前点事最小或最大,那么这个点被标记为可能的峰值。当这个标志点从最大变为最小的时候,那么前一个点被认为是一个峰值。反之亦然。

另一种解释向后看的方式是,可疑点将被认作为一个峰值,如果它是最大或最小值在过去的一段时间或将来的一段时间。就像我说的,这个名字很糟糕。

其他…

  • The number of cycles performed will vary between 3 and 10. The algorithm waits until the last 3 maxima have been within 5% of each other. This is trying to ensure that we’ve reached a stable oscillation and there’s no external strangeness happening. This leads me to…
  • I’m not the biggest fan of Autotune. I’ve often said, and still believe, that a moderately trained person will beat an Autotuner every day of the week. There’s just so much that can go wrong without the algorithm knowing about it. That being said, Autotune is a valuable tool to help the novice get into the ballpark.
2018-11-14 19:24:01 woshi_ziyu 阅读数 1353

在本篇文章中,我们将主要介绍如何使用MATLB和Arduino开发板控制直流电机。如果您是初次使用MATLAB软件,建议您先学习如何使用MATLAB实现简单的LED闪烁。

创建用于控制直流电机的MATLAB图形用户界面

在设置Arduino开发板完成后,我们必须在MATLAB种构建GUI(图形用户界面)来控制直流电机。要启动GUI,请在命令窗口中输入以下命令

然后弹出一个窗口,选择创建一个新的空白GUI,如下图所示

现在我们可以选择制作三个按钮,分别用于进行顺时针旋转、逆时针旋转和停止,如下所示,

在这里插入图片描述

要调整大小或更改按钮的形状,只需在它上面单击,您就可以拖动按钮的角落。通过双击按钮,您可以更改该特定按钮的颜色、文字和标记。我们定制了三个按钮,如下图所示。

更多内容请参考以下链接:https://www.yiboard.com/thread-973-1-1.html

2020-01-25 12:30:19 qq_38288618 阅读数 1623

ROS与Arduino硬件之rosserial_arduino(win10)

大过节的,赶上现在这个病毒情况,为自己好为大家好,不出门瞎逛了,窝在家里写个贴吧。

虽说ROS的仿真软件gezabo功能很强悍,只要能写插件就可以模拟各种传感器执行器,
比如一个机器人有个显示器,这样的执行器就不易仿真,不如给现实的机器人上接个显示器来的快捷。

写gezabo插件也得有一定的功底。
还需要消耗人月,


最终机器人落地还得需要理论联系实际不是,不能让产品落地的创意也只能算臆想。


我们基于ros框架,快速搭建一个真实实验器械或机构时,需要的各种简单传感器和执行器。
比如给机器人系统加个数码管、超声、按键、舵机或者其他什么东西。
使用万能的Arduino开发制作是条捷径。
有了这样的传感器模块,就使得ros开发过程中灵活度很强,既不影响现有的系统,又能随意扩展。


当然开发这些模块我们可以自定义通讯协议,开发单片机程序,编写ros驱动节点进行协议解析,最终转换成ros消息,跟其他ros节点沟通。
不过ros生态已经准备了使用rosserial_arduino包的方案。
用此方案可以使arduino硬件内也可以像运行ros节点那样使用msg 和srv与上位机沟通。
硬件各个模块也变成了一个个节点,体现出ros分布式松耦合的特性,在开发过程中减少出错率,减少反复调试硬件的时间,减少协议通讯编代码的工作量。
其不足之处就是要额外占用单片机的一些资源。


总之这么好的懒人服务包怎么也要一啦

官方

http://wiki.ros.org/rosserial

简选前辈的博文
https://blog.csdn.net/wanzew/article/details/80030768
ROS学习之Arduino篇——rosserial_arduino包

1、源码安装

  cd <ws>/src
  git clone https://github.com/ros-drivers/rosserial.git
  cd <ws>
  catkin_make
  catkin_make install

2、把 ros_lib 安装到Arduino的开发环境中
sketchbook为Arduino安装以后的项目文件夹路径

  cd <sketchbook>/libraries
  rm -rf ros_lib
  rosrun rosserial_arduino make_libraries.py 

就是说,这样的操作可以把ros的头文件,移植成arduino使用的头文件


看起来so easy ,让我们在win10下试试(注:如果你是ubuntu那下面的有些问题可能不会出现)。

克隆不必多说,
catkin_make会遇到这样的问题
本地已经安装过相应的ros包了,编译安装时重复会报错
主要错误提示如下

add_executable cannot create target
  "make_libraries.py_executable_install_python" because another target with
  the same name already exists.  The existing target is an executable created
  in source directory

全文

D:\project\ros\zzz_arduino>catkin_make
Base path: D:\project\ros\zzz_arduino
Source space: D:\project\ros\zzz_arduino\src
Build space: D:\project\ros\zzz_arduino\build
Devel space: D:\project\ros\zzz_arduino\devel
Install space: D:\project\ros\zzz_arduino\install
####
#### Running command: "nmake cmake_check_build_system" in "D:\project\ros\zzz_arduino\build"
####

Microsoft (R) ?????????ù??? 14.23.28107.0 ??
??????? (C) Microsoft Corporation??  ?????????????

CMake Warning (dev) in CMakeLists.txt:
  No project() command is present.  The top-level CMakeLists.txt file must
  contain a literal, direct call to the project() command.  Add a line of
  code such as

    project(ProjectName)

  near the top of the file, but after cmake_minimum_required().

  CMake is pretending there is a "project(Project)" command on the first
  line.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Using CATKIN_DEVEL_PREFIX: D:/project/ros/zzz_arduino/devel
-- Using CMAKE_PREFIX_PATH: C:/opt/ros/melodic/x64;C:/opt/rosdeps/x64;C:/opt/vcpkg/installed/x64-windows
-- This workspace overlays: C:/opt/ros/melodic/x64
-- Using PYTHON_EXECUTABLE: C:/opt/python27amd64/python.exe
-- Using default Python package layout
-- Using empy: C:/opt/python27amd64/lib/site-packages/em.pyc
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: D:/project/ros/zzz_arduino/build/test_results
-- Found gtest: gtests will be built
-- Using Python nosetests: C:/opt/python27amd64/Scripts/nosetests-2.7.exe
-- catkin 0.7.18
-- BUILD_SHARED_LIBS is on
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 14 packages in topological order:
-- ~~  - rosserial (metapackage)
-- ~~  - rosserial_arduino
-- ~~  - rosserial_mbed
-- ~~  - rosserial_msgs
-- ~~  - rosserial_python
-- ~~  - rosserial_tivac
-- ~~  - rosserial_vex_cortex
-- ~~  - rosserial_vex_v5
-- ~~  - rosserial_xbee
-- ~~  - rosserial_client
-- ~~  - rosserial_server
-- ~~  - rosserial_embeddedlinux
-- ~~  - rosserial_test
-- ~~  - rosserial_windows
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin metapackage: 'rosserial'
-- ==> add_subdirectory(rosserial/rosserial)
-- +++ processing catkin package: 'rosserial_arduino'
-- ==> add_subdirectory(rosserial/rosserial_arduino)
-- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy
-- rosserial_arduino: 1 messages, 1 services
-- +++ processing catkin package: 'rosserial_mbed'
-- ==> add_subdirectory(rosserial/rosserial_mbed)
-- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy
-- rosserial_mbed: 1 messages, 1 services
CMake Error at C:/opt/ros/melodic/x64/share/catkin/cmake/platform/windows.cmake:140 (add_executable):
  add_executable cannot create target
  "make_libraries.py_executable_install_python" because another target with
  the same name already exists.  The existing target is an executable created
  in source directory
  "D:/project/ros/zzz_arduino/src/rosserial/rosserial_arduino".  See
  documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  C:/opt/ros/melodic/x64/share/catkin/cmake/catkin_install_python.cmake:52 (add_python_executable)
  rosserial/rosserial_mbed/CMakeLists.txt:27 (catkin_install_python)


-- +++ processing catkin package: 'rosserial_msgs'
-- ==> add_subdirectory(rosserial/rosserial_msgs)
-- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy
-- rosserial_msgs: 2 messages, 1 services
-- +++ processing catkin package: 'rosserial_python'
-- ==> add_subdirectory(rosserial/rosserial_python)
CMake Error at C:/opt/ros/melodic/x64/share/catkin/cmake/platform/windows.cmake:140 (add_executable):
  add_executable cannot create target
  "serial_node.py_executable_install_python" because another target with the
  same name already exists.  The existing target is an executable created in
  source directory
  "D:/project/ros/zzz_arduino/src/rosserial/rosserial_arduino".  See
  documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  C:/opt/ros/melodic/x64/share/catkin/cmake/catkin_install_python.cmake:52 (add_python_executable)
  rosserial/rosserial_python/CMakeLists.txt:9 (catkin_install_python)


-- +++ processing catkin package: 'rosserial_tivac'
-- ==> add_subdirectory(rosserial/rosserial_tivac)
-- +++ processing catkin package: 'rosserial_vex_cortex'
-- ==> add_subdirectory(rosserial/rosserial_vex_cortex)
CMake Error at C:/opt/ros/melodic/x64/share/catkin/cmake/platform/windows.cmake:140 (add_executable):
  add_executable cannot create target
  "make_libraries.py_executable_install_python" because another target with
  the same name already exists.  The existing target is an executable created
  in source directory
  "D:/project/ros/zzz_arduino/src/rosserial/rosserial_arduino".  See
  documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  C:/opt/ros/melodic/x64/share/catkin/cmake/catkin_install_python.cmake:52 (add_python_executable)
  rosserial/rosserial_vex_cortex/CMakeLists.txt:25 (catkin_install_python)


-- +++ processing catkin package: 'rosserial_vex_v5'
-- ==> add_subdirectory(rosserial/rosserial_vex_v5)
CMake Error at C:/opt/ros/melodic/x64/share/catkin/cmake/platform/windows.cmake:140 (add_executable):
  add_executable cannot create target
  "make_libraries.py_executable_install_python" because another target with
  the same name already exists.  The existing target is an executable created
  in source directory
  "D:/project/ros/zzz_arduino/src/rosserial/rosserial_arduino".  See
  documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  C:/opt/ros/melodic/x64/share/catkin/cmake/catkin_install_python.cmake:52 (add_python_executable)
  rosserial/rosserial_vex_v5/CMakeLists.txt:25 (catkin_install_python)


-- +++ processing catkin package: 'rosserial_xbee'
-- ==> add_subdirectory(rosserial/rosserial_xbee)
-- +++ processing catkin package: 'rosserial_client'
-- ==> add_subdirectory(rosserial/rosserial_client)
-- +++ processing catkin package: 'rosserial_server'
-- ==> add_subdirectory(rosserial/rosserial_server)
-- +++ processing catkin package: 'rosserial_embeddedlinux'
-- ==> add_subdirectory(rosserial/rosserial_embeddedlinux)
CMake Error at C:/opt/ros/melodic/x64/share/catkin/cmake/platform/windows.cmake:140 (add_executable):
  add_executable cannot create target
  "make_libraries.py_executable_install_python" because another target with
  the same name already exists.  The existing target is an executable created
  in source directory
  "D:/project/ros/zzz_arduino/src/rosserial/rosserial_arduino".  See
  documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  C:/opt/ros/melodic/x64/share/catkin/cmake/catkin_install_python.cmake:52 (add_python_executable)
  rosserial/rosserial_embeddedlinux/CMakeLists.txt:16 (catkin_install_python)


-- +++ processing catkin package: 'rosserial_test'
-- ==> add_subdirectory(rosserial/rosserial_test)
-- +++ processing catkin package: 'rosserial_windows'
-- ==> add_subdirectory(rosserial/rosserial_windows)
-- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy
CMake Error at C:/opt/ros/melodic/x64/share/catkin/cmake/platform/windows.cmake:140 (add_executable):
  add_executable cannot create target
  "make_libraries.py_executable_install_python" because another target with
  the same name already exists.  The existing target is an executable created
  in source directory
  "D:/project/ros/zzz_arduino/src/rosserial/rosserial_arduino".  See
  documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  C:/opt/ros/melodic/x64/share/catkin/cmake/catkin_install_python.cmake:52 (add_python_executable)
  rosserial/rosserial_windows/CMakeLists.txt:18 (catkin_install_python)


-- Configuring incomplete, errors occurred!
See also "D:/project/ros/zzz_arduino/build/CMakeFiles/CMakeOutput.log".
See also "D:/project/ros/zzz_arduino/build/CMakeFiles/CMakeError.log".
NMAKE : fatal error U1077: ??C:\opt\python27amd64\Lib\site-packages\cmake\data\bin\cmake.exe??: ???????0x1??
Stop.
Invoking "nmake cmake_check_build_system" failed

相关问题
https://answers.ros.org/question/212536/cmake-error-add_executable/

引用
add_custom_target cannot create target "pcl_ros_gencfg" because another
  target with the same name already exists.  The existing target is a custom
  target created in source directory "/home/gordon/catkin_ws/src/flight".
  See documentation for policy CMP0002 for more details.

CMake Error at navigation/voxel_grid/CMakeLists.txt:28 (add_executable):
  add_executable cannot create target "voxel_grid" because another target
  with the same name already exists.  The existing target is a shared library
  created in source directory
  "/home/gordon/catkin_ws/src/navigation/voxel_grid".  See documentation for
  policy CMP0002 for more details.

I know of one solution that is to use catkin_make_isolated to prevent these from happening but I was told that it will make the whole thing work slower.


!!!!!!!!!!!!!!
catkin_make_isolated
!!!!!!!!!!!!!!
不改变现有的环境,使用隔离编译。
又遇到一个小问题,Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. 原因是window版本和Ubuntu版本编译配置不同吧。

D:\project\ros\zzz_arduino>catkin_make_isolated

。。。。。。

[ 50%] Building CXX object CMakeFiles/rosserial_server_serial_node.dir/src/serial_node.cpp.obj
serial_node.cpp
Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For example:
- add -D_WIN32_WINNT=0x0501 to the compiler command line; or
- add _WIN32_WINNT=0x0501 to your project's Preprocessor Definitions.
Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP target).
D:\project\ros\zzz_arduino\devel_isolated\rosserial_msgs\include\rosserial_msgs/Log.h(50): error C2143: 语法错误: 缺少“}”(在“常数”的前面)
D:\project\ros\zzz_arduino\devel_isolated\rosserial_msgs\include\rosserial_msgs/Log.h(58): note: 查看对正在编译的 类 模板 实例化“rosserial_msgs::Log_<ContainerAllocator>”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/bind/placeholders.hpp(54): note: 查看对正在编译的 类 模板 实例化“boost::arg<9>”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/bind/placeholders.hpp(53): note: 查看对正在编译的 类 模板 实例化“boost::arg<8>”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/bind/placeholders.hpp(52): note: 查看对正在编译的 类 模板 实例化“boost::arg<7>”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/bind/placeholders.hpp(51): note: 查看对正在编译的 类 模板 实例化“boost::arg<6>”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/bind/placeholders.hpp(50): note: 查看对正在编译的 类 模板 实例化“boost::arg<5>”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/bind/placeholders.hpp(49): note: 查看对正在编译的 类 模板 实例化“boost::arg<4>”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/bind/placeholders.hpp(48): note: 查看对正在编译的 类 模板 实例化“boost::arg<3>”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/bind/placeholders.hpp(47): note: 查看对正在编译的 类 模板 实例化“boost::arg<2>”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/bind/placeholders.hpp(46): note: 查看对正在编译的 类 模板 实例化“boost::arg<1>”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/asio/use_future.hpp(138): note: 查看对正在编译的 类 模板 实例化“boost::asio::use_future_t<std::allocator<void>>::std_allocator_void”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/asio/use_future.hpp(146): note: 查看对正在编译的 类 模板 实例化“boost::asio::use_future_t<std::allocator<void>>”的引用
D:\project\ros\zzz_arduino\devel_isolated\rosserial_msgs\include\rosserial_msgs/Log.h(50): error C2059: 语法错误:“常数”
D:\project\ros\zzz_arduino\devel_isolated\rosserial_msgs\include\rosserial_msgs/Log.h(52): error C2143: 语法错误: 缺少“;”(在“}”的前面)
D:\project\ros\zzz_arduino\devel_isolated\rosserial_msgs\include\rosserial_msgs/Log.h(52): error C2238: 意外的标记位于“;”之前
D:\project\ros\zzz_arduino\src\rosserial\rosserial_server\include\rosserial_server/topic_handlers.h(111): warning C4267: “参数”: 从“size_t”转换到 “uint32_t”,可能丢失数据
D:\project\ros\zzz_arduino\src\rosserial\rosserial_server\include\rosserial_server/topic_handlers.h(178): warning C4267: “参数”: 从“size_t”转换到 “uint32_t”,可能丢失数据
NMAKE : fatal error U1077: “E:\PROGRA~3\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1423~1.281\bin\Hostx64\x64\cl.exe”: 返回代码“0x2”
Stop.
NMAKE : fatal error U1077: “"E:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\bin\HostX64\x64\nmake.exe"”: 返回代码“0x2”
Stop.
NMAKE : fatal error U1077: “"E:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\bin\HostX64\x64\nmake.exe"”: 返回代码“0x2”
Stop.
<== Failed to process package 'rosserial_server':
  Command '['D:\\project\\ros\\zzz_arduino\\devel_isolated\\rosserial_python\\env.bat', 'nmake']' returned non-zero exit status 2

Reproduce this error by running:
==> cd 'D:\project\ros\zzz_arduino\build_isolated\rosserial_server' && 'D:\project\ros\zzz_arduino\devel_isolated\rosserial_python\env.bat' nmake

Command failed, exiting.


新的问题
Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. 问题
解决
https://blog.csdn.net/sols000/article/details/85615819
在编译ASIO 时,出现编译警告Please define _WIN32_WINNT 解决办法


包含头文件 #include <sdkddkver.h>即可。

改一改源文件,不过还是有问题:

D:\project\ros\zzz_arduino>catkin_make_isolated
。。。。。。
[ 50%] Building CXX object CMakeFiles/rosserial_server_serial_node.dir/src/serial_node.cpp.obj
serial_node.cpp
D:\project\ros\zzz_arduino\devel_isolated\rosserial_msgs\include\rosserial_msgs/Log.h(50): error C2143: 语法错误: 缺少“}”(在“常数”的前面)
D:\project\ros\zzz_arduino\devel_isolated\rosserial_msgs\include\rosserial_msgs/Log.h(58): note: 查看对正在编译的 类 模板 实例化“rosserial_msgs::Log_<ContainerAllocator>”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/bind/placeholders.hpp(54): note: 查看对正在编译的 类 模板 实例化“boost::arg<9>”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/bind/placeholders.hpp(53): note: 查看对正在编译的 类 模板 实例化“boost::arg<8>”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/bind/placeholders.hpp(52): note: 查看对正在编译的 类 模板 实例化“boost::arg<7>”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/bind/placeholders.hpp(51): note: 查看对正在编译的 类 模板 实例化“boost::arg<6>”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/bind/placeholders.hpp(50): note: 查看对正在编译的 类 模板 实例化“boost::arg<5>”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/bind/placeholders.hpp(49): note: 查看对正在编译的 类 模板 实例化“boost::arg<4>”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/bind/placeholders.hpp(48): note: 查看对正在编译的 类 模板 实例化“boost::arg<3>”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/bind/placeholders.hpp(47): note: 查看对正在编译的 类 模板 实例化“boost::arg<2>”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/bind/placeholders.hpp(46): note: 查看对正在编译的 类 模板 实例化“boost::arg<1>”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/asio/use_future.hpp(138): note: 查看对正在编译的 类 模板 实例化“boost::asio::use_future_t<std::allocator<void>>::std_allocator_void”的引用
C:\opt\rosdeps\x64\include\boost-1_66\boost/asio/use_future.hpp(146): note: 查看对正在编译的 类 模板 实例化“boost::asio::use_future_t<std::allocator<void>>”的引用
D:\project\ros\zzz_arduino\devel_isolated\rosserial_msgs\include\rosserial_msgs/Log.h(50): error C2059: 语法错误:“常数”
D:\project\ros\zzz_arduino\devel_isolated\rosserial_msgs\include\rosserial_msgs/Log.h(52): error C2143: 语法错误: 缺少“;”(在“}”的前面)
D:\project\ros\zzz_arduino\devel_isolated\rosserial_msgs\include\rosserial_msgs/Log.h(52): error C2238: 意外的标记位于“;”之前
D:\project\ros\zzz_arduino\src\rosserial\rosserial_server\include\rosserial_server/topic_handlers.h(111): warning C4267: “参数”: 从“size_t”转换到 “uint32_t”,可能丢失数据
D:\project\ros\zzz_arduino\src\rosserial\rosserial_server\include\rosserial_server/topic_handlers.h(178): warning C4267: “参数”: 从“size_t”转换到 “uint32_t”,可能丢失数据
NMAKE : fatal error U1077: “E:\PROGRA~3\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1423~1.281\bin\Hostx64\x64\cl.exe”: 返回代码“0x2”
Stop.
NMAKE : fatal error U1077: “"E:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\bin\HostX64\x64\nmake.exe"”: 返回代码“0x2”
Stop.
NMAKE : fatal error U1077: “"E:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\bin\HostX64\x64\nmake.exe"”: 返回代码“0x2”
Stop.
<== Failed to process package 'rosserial_server':
  Command '['D:\\project\\ros\\zzz_arduino\\devel_isolated\\rosserial_python\\env.bat', 'nmake']' returned non-zero exit status 2

Reproduce this error by running:
==> cd 'D:\project\ros\zzz_arduino\build_isolated\rosserial_server' && 'D:\project\ros\zzz_arduino\devel_isolated\rosserial_python\env.bat' nmake

Command failed, exiting.


好吧,ubuntu还是跟windows不一样。有问题放一放,暂时不解决这个问题,注释掉注释掉!!所有相关的统统注释掉。CMakeLists.txt:注释

#add_executable(${PROJECT_NAME}_serial_node src/serial_node.cpp)
#target_link_libraries(${PROJECT_NAME}_serial_node ${catkin_LIBRARIES} ${PROJECT_NAME}_lookup)
#set_target_properties(${PROJECT_NAME}_serial_node PROPERTIES OUTPUT_NAME serial_node PREFIX "")
#add_dependencies(${PROJECT_NAME}_serial_node ${catkin_EXPORTED_TARGETS})

#add_executable(${PROJECT_NAME}_socket_node src/socket_node.cpp)
#target_link_libraries(${PROJECT_NAME}_socket_node ${catkin_LIBRARIES} ${PROJECT_NAME}_lookup)
#set_target_properties(${PROJECT_NAME}_socket_node PROPERTIES OUTPUT_NAME socket_node PREFIX "")
#add_dependencies(${PROJECT_NAME}_socket_node ${catkin_EXPORTED_TARGETS})

#add_executable(${PROJECT_NAME}_udp_socket_node src/udp_socket_node.cpp)
#target_link_libraries(${PROJECT_NAME}_udp_socket_node ${catkin_LIBRARIES} ${PROJECT_NAME}_lookup)
#set_target_properties(${PROJECT_NAME}_udp_socket_node PROPERTIES OUTPUT_NAME udp_socket_node PREFIX "")
#add_dependencies(${PROJECT_NAME}_udp_socket_node ${catkin_EXPORTED_TARGETS})

#install(
  #TARGETS
    #${PROJECT_NAME}_serial_node
    #${PROJECT_NAME}_socket_node
    #${PROJECT_NAME}_udp_socket_node
  #RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
#)

编译成功

 

是不是可以只取关键的包编译,进行转换呢?有待试验

-------------------------------------------------------------------------------------

执行命令

rosrun rosserial_arduino make_libraries.py 


命令生成rospack返回的所有包的头文件,包括msg、srv的头文件。
拷贝到arduino库libraries/ros_lib中
开发硬件程序时,可以include这些文件。
python部分代码

rospack = rospkg.RosPack()

# copy ros_lib stuff in 复制rosserial_arduino包内ros_lib的内容
rosserial_arduino_dir = rospack.get_path(THIS_PACKAGE)
shutil.copytree(rosserial_arduino_dir+"/src/ros_lib", path+"/ros_lib")
rosserial_client_copy_files(rospack, path+"/ros_lib/")#ros中所有包的头文件??

# generate messages依照ros中定义的 msg srv ,生成嵌入式程序用的消息 .h文件(自动移植)
rosserial_generate(rospack, path+"/ros_lib", ROS_TO_EMBEDDED_TYPES)

最后运行make_libraries.py提示需要Arduino sketchbook/libraries folder目录参数

D:\project\ros\zzz_arduino\a>rosrun rosserial_arduino make_libraries.py

make_libraries.py generates the Arduino rosserial library files.  It
requires the location of your Arduino sketchbook/libraries folder.

rosrun rosserial_arduino make_libraries.py <output_path>


好吧,先随意找个目录测试:

D:\project\ros\zzz_arduino\a>rosrun rosserial_arduino make_libraries.py D:\project\ros\zzz_arduino\a

Exporting to D:\project\ros\zzz_arduino\a
Exporting actionlib

  Messages:
    TestAction,TestActionFeedback,TestActionGoal,TestActionResult,TestFeedback,TestGoal,TestRequestAction,TestRequestActionFeedback,TestRequestActionGoal,TestRequestActionResult,TestRequestFeedback,TestRequestGoal,TestRequestResult,TestResult,TwoIntsAction,TwoIntsActionFeedback,TwoIntsActionGoal,TwoIntsActionResult,TwoIntsFeedback,TwoIntsGoal,TwoIntsResult,

Exporting actionlib_msgs

  Messages:
    GoalID,GoalStatus,GoalStatusArray,

Exporting actionlib_tutorials

  Messages:
    AveragingAction,AveragingActionFeedback,AveragingActionGoal,AveragingActionResult,AveragingFeedback,AveragingGoal,AveragingResult,FibonacciAction,FibonacciActionFeedback,FibonacciActionGoal,FibonacciActionResult,FibonacciFeedback,FibonacciGoal,FibonacciResult,

Exporting base_local_planner

  Messages:
    Position2DInt,

Exporting bond

  Messages:
    Constants,Status,

Exporting control_msgs

  Messages:
    FollowJointTrajectoryAction,FollowJointTrajectoryActionFeedback,FollowJointTrajectoryActionGoal,FollowJointTrajectoryActionResult,FollowJointTrajectoryFeedback,FollowJointTrajectoryGoal,FollowJointTrajectoryResult,GripperCommand,GripperCommandAction,GripperCommandActionFeedback,GripperCommandActionGoal,GripperCommandActionResult,GripperCommandFeedback,GripperCommandGoal,GripperCommandResult,JointControllerState,JointJog,JointTolerance,JointTrajectoryAction,JointTrajectoryActionFeedback,JointTrajectoryActionGoal,JointTrajectoryActionResult,JointTrajectoryControllerState,JointTrajectoryFeedback,JointTrajectoryGoal,JointTrajectoryResult,PidState,PointHeadAction,PointHeadActionFeedback,PointHeadActionGoal,PointHeadActionResult,PointHeadFeedback,PointHeadGoal,PointHeadResult,SingleJointPositionAction,SingleJointPositionActionFeedback,SingleJointPositionActionGoal,SingleJointPositionActionResult,SingleJointPositionFeedback,SingleJointPositionGoal,SingleJointPositionResult,

  Services:
    QueryCalibrationState,QueryTrajectoryState,

Exporting control_toolbox

  Services:
    SetPidGains,

Exporting controller_manager_msgs

  Messages:
    ControllersStatistics,ControllerState,ControllerStatistics,HardwareInterfaceResources,

  Services:
    ListControllers,ListControllerTypes,LoadController,ReloadControllerLibraries,SwitchController,UnloadController,

Exporting costmap_2d

  Messages:
    VoxelGrid,

Exporting diagnostic_msgs

  Messages:
    DiagnosticArray,DiagnosticStatus,KeyValue,

  Services:
    AddDiagnostics,SelfTest,

Exporting dynamic_reconfigure

  Messages:
    BoolParameter,Config,ConfigDescription,DoubleParameter,Group,GroupState,IntParameter,ParamDescription,SensorLevels,StrParameter,

  Services:
    Reconfigure,

Exporting gazebo_msgs

  Messages:
    ContactsState,ContactState,LinkState,LinkStates,ModelState,ModelStates,ODEJointProperties,ODEPhysics,WorldState,

  Services:
    ApplyBodyWrench,ApplyJointEffort,BodyRequest,DeleteLight,DeleteModel,GetJointProperties,GetLightProperties,GetLinkProperties,GetLinkState,GetModelProperties,GetModelState,GetPhysicsProperties,GetWorldProperties,JointRequest,SetJointProperties,SetJointTrajectory,SetLightProperties,SetLinkProperties,SetLinkState,SetModelConfiguration,SetModelState,SetPhysicsProperties,SpawnModel,

Exporting geometry_msgs

  Messages:
    Accel,AccelStamped,AccelWithCovariance,AccelWithCovarianceStamped,Inertia,InertiaStamped,Point,Point32,PointStamped,Polygon,PolygonStamped,Pose,Pose2D,PoseArray,PoseStamped,PoseWithCovariance,PoseWithCovarianceStamped,Quaternion,QuaternionStamped,Transform,TransformStamped,Twist,TwistStamped,TwistWithCovariance,TwistWithCovarianceStamped,Vector3,Vector3Stamped,Wrench,WrenchStamped,

Exporting laser_assembler

  Services:
    AssembleScans,AssembleScans2,

Exporting map_msgs

  Messages:
    OccupancyGridUpdate,PointCloud2Update,ProjectedMap,ProjectedMapInfo,

  Services:
    GetMapROI,GetPointMap,GetPointMapROI,ProjectedMapsInfo,SaveMap,SetMapProjections,

Exporting move_base_msgs

  Messages:
    MoveBaseAction,MoveBaseActionFeedback,MoveBaseActionGoal,MoveBaseActionResult,MoveBaseFeedback,MoveBaseGoal,MoveBaseResult,

Exporting nav_msgs

  Messages:
    GetMapAction,GetMapActionFeedback,GetMapActionGoal,GetMapActionResult,GetMapFeedback,GetMapGoal,GetMapResult,GridCells,MapMetaData,OccupancyGrid,Odometry,Path,

  Services:
    GetMap,GetPlan,SetMap,

Exporting navfn

  Services:
    MakeNavPlan,SetCostmap,

Exporting nodelet

  Services:
    NodeletList,NodeletLoad,NodeletUnload,

Exporting pcl_msgs

  Messages:
    ModelCoefficients,PointIndices,PolygonMesh,Vertices,

  Services:
    UpdateFilename,

Exporting polled_camera

  Services:
    GetPolledImage,

Exporting robotiq_2f_gripper_control

  Messages:
    Robotiq2FGripper_robot_input,Robotiq2FGripper_robot_output,

Exporting roscpp

  Messages:
    Logger,

  Services:
    Empty,GetLoggers,SetLoggerLevel,

Exporting roscpp_tutorials

  Services:
    TwoInts,

Exporting rosgraph_msgs

  Messages:
    Clock,Log,TopicStatistics,

Exporting rospy_tutorials

  Messages:
    Floats,HeaderString,

  Services:
    AddTwoInts,BadTwoInts,

Exporting rosserial_arduino

  Messages:
    Adc,

  Services:
    Test,

Exporting rosserial_mbed

  Messages:
    Adc,

  Services:
    Test,

Exporting rosserial_msgs

  Messages:
    Log,TopicInfo,

  Services:
    RequestMessageInfo,the rosdep view is empty: call 'sudo rosdep init' and 'rosdep update'
Unable to build service: rosserial_msgs/RequestMessageInfo
RequestParam,RequestServiceInfo,Unable to build service: rosserial_msgs/RequestServiceInfo


Exporting sensor_msgs

  Messages:
    BatteryState,CameraInfo,ChannelFloat32,CompressedImage,FluidPressure,Illuminance,Image,Imu,JointState,Joy,JoyFeedback,JoyFeedbackArray,LaserEcho,LaserScan,MagneticField,MultiDOFJointState,MultiEchoLaserScan,NavSatFix,NavSatStatus,PointCloud,PointCloud2,PointField,Range,RegionOfInterest,RelativeHumidity,Temperature,TimeReference,

  Services:
    SetCameraInfo,

Exporting shape_msgs

  Messages:
    Mesh,MeshTriangle,Plane,SolidPrimitive,

Exporting smach_msgs

  Messages:
    SmachContainerInitialStatusCmd,SmachContainerStatus,SmachContainerStructure,

Exporting std_msgs

  Messages:
    Bool,Byte,ByteMultiArray,Char,ColorRGBA,Duration,Empty,Float32,Float32MultiArray,Float64,Float64MultiArray,Header,Int16,Int16MultiArray,Int32,Int32MultiArray,Int64,Int64MultiArray,Int8,Int8MultiArray,MultiArrayDimension,MultiArrayLayout,String,Time,UInt16,UInt16MultiArray,UInt32,UInt32MultiArray,UInt64,UInt64MultiArray,UInt8,UInt8MultiArray,

Exporting std_srvs

  Services:
    Empty,SetBool,Trigger,

Exporting stereo_msgs

  Messages:
    DisparityImage,

Exporting tf

  Messages:
    tfMessage,

  Services:
    FrameGraph,

Exporting tf2_msgs

  Messages:
    LookupTransformAction,LookupTransformActionFeedback,LookupTransformActionGoal,LookupTransformActionResult,LookupTransformFeedback,LookupTransformGoal,LookupTransformResult,TF2Error,TFMessage,

  Services:
    FrameGraph,

Exporting theora_image_transport

  Messages:
    Packet,

Exporting topic_tools

  Services:
    DemuxAdd,DemuxDelete,DemuxList,DemuxSelect,MuxAdd,MuxDelete,MuxList,MuxSelect,

Exporting trajectory_msgs

  Messages:
    JointTrajectory,JointTrajectoryPoint,MultiDOFJointTrajectory,MultiDOFJointTrajectoryPoint,

Exporting turtle_actionlib

  Messages:
    ShapeAction,ShapeActionFeedback,ShapeActionGoal,ShapeActionResult,ShapeFeedback,ShapeGoal,ShapeResult,Velocity,

Exporting turtlesim

  Messages:
    Color,Pose,

  Services:
    Kill,SetPen,Spawn,TeleportAbsolute,TeleportRelative,

Exporting visualization_msgs

  Messages:
    ImageMarker,InteractiveMarker,InteractiveMarkerControl,InteractiveMarkerFeedback,InteractiveMarkerInit,InteractiveMarkerPose,InteractiveMarkerUpdate,Marker,MarkerArray,MenuEntry,

成功!
依葫芦画瓢,现在自定义一个msg和srv来生成arduino使用的头文件,开发个arduino ros节点试试吧。

2017-06-30 12:28:07 weixin_38403639 阅读数 2262

這是本人在大一的時候做的第一個小東西。也是當時大一寫的第一篇博客。近日重溫舊時光,來此修改。

它的用途:很多时候需要喝温水,然而刚接出来的开水往往很烫,不适合饮用。所以我们会选择把它晾在一边,忙别的事,忙着忙着就把水忘了,等到喝水的时候,它已经不是我们想要的温度了。这个水温监控器就是用来防止这样的现象,用户可以自己来设定温度,当水温比这个温度低的时候,它的蜂鸣器就会响,也就是提醒用户喝水。

它主要由四部分组成:
这里写图片描述

arduino uno不必赘述。

lcd1602液晶屏也很好在arduino上操作,具体可以参考arduino
官方例程。
LCD硬件电路如图:
这里写图片描述
值得说明的是,电位计是非常重要的,我一开始使用定值电阻,背光率難以调节到合適情況。

重点就在于如何实现温度传感器测温,这里我选择的是DS18B20,达拉斯公司推出的单总线温度传感器,易于操作而且经典。
它的硬件电路很简单:
这里写图片描述

写程序伊始,我参考的是一本讲arduino的教程,上面用到了两个头文件,分别是OneWire.h和DallasTemperature.h,结果就是,最初的尝试都没有成功。

在编译的时候,DallasTemperature.c会導致報错,百度后,把Wprogram.h改成arduino.h或者在其下面加一段关于arduino.h的代码,编译不再出错,但是测温会显示一个神奇的数字,127度。这说明DS18B20根本没有测温。

由於教程中使用老版本IDE,懷疑换一个旧版本会不会好,于是去下载了0022版本,结果仍是失望。

最後打开例程中Onewire的文件夹,发现了一个例程,DS18x20_Temperature。它是用来串口显示温度的,拿它来试了一下,在串口监视器成功地顯示温度。

然而在proteus里,仿真的结果仍是127度,所以抱着试一试的想法,在面包板上试了一下,直接在LCD显示出了实时温度。可见,proteus其实还有待改进,且Arduino的老教程也沒有太大看的意義。

以下是目前为止的原理图:
这里写图片描述
關於仿真,arduino在proteus里有专门的库,且CSDN上就有資源。

克服傳感器后,只剩下蜂鸣器和按键控制。原理图如图:这里写图片描述
这里写图片描述

需要注意的就是按键控制时,电路用了硬件消抖,程序里就不要再有软件消抖了,我过去试过这样做,按键会不起作用的。

至此,这个智能水温监控器就基本做完了,以下是代码:

#include <LiquidCrystal.h>
#include <OneWire.h>
LiquidCrystal lcd(12,11,5,4,3,2);
OneWire  ds(10);  // on pin 10
int beep = 9;
int add = 7;
int minus = 6;
float controline = 25;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.print("Hello world");  
  pinMode(beep, OUTPUT);
  pinMode(add,INPUT);
  pinMode(minus,INPUT);
}

void loop() {
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;
  
  if ( !ds.search(addr)) {
    ds.reset_search();
    delay(250);
    return;
  }
  
  for( i = 0; i < 8; i++) {
    Serial.write(' ');
    Serial.print(addr[i], HEX);
  }

  if (OneWire::crc8(addr, 7) != addr[7]) {
      return;
  }
  ds.reset();
  ds.select(addr);
  ds.write(0x44,1);         // start conversion, with parasite power on at the end
  
  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
  
  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad

  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
  }

  // convert the data to actual temperature

  unsigned int raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // count remain gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    if (cfg == 0x00) raw = raw << 3;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms
    // default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;

  if(digitalRead(add) == HIGH) controline += 1;
  if(digitalRead(minus)==HIGH) controline -= 1;
  if(celsius < controline) digitalWrite(beep,LOW);
  else digitalWrite(beep,HIGH);
  lcd.setCursor(0,0);
  lcd.print("Temp = ");
  lcd.print(celsius);
  lcd.print(" C");
  lcd.setCursor(0,1);
  lcd.print("Setting: ");
  lcd.print(controline);
}

原理圖如下。(画的有些难看)
这里写图片描述