生成代码to Manually Deploy a ROS Node from金宝app
This example shows you how to generate C++ code from a Simulink®model to deploy as a standalone ROS node. The code is generated on your computer and must be manually transferred to the target ROS device. No connection to the hardware is necessary for generated the code. For an automated deployment of a ROS node, seeGenerate a Standalone ROS Node from Simulink®。
Prerequisites
This example requires金宝appSimulink Coder™和嵌入式编码器™。
A Ubuntu Linux system with ROS is necessary for building and running the generated C++ code. You can use your own Ubuntu ROS system, or you can use the Linux virtual machine used for ROS Toolbox™ examples. SeeGet Started with Gazebo and Simulated TurtleBotfor instructions on how to install and use the virtual machine.
Review theFeedback Control of a ROS-Enabled Robotexample, which details the Simulink model that the code is being generated from.
Configure A Model for Code Generation
配置模型以生成C ++代码的独立ROS节点的C ++代码Configuration Parameters。The model used here is the proportional controller introduced in theFeedback Control of a ROS-Enabled Robot例子。
Open the proportional controller model.
edit robotROSFeedbackControlExample
Copy the entire model to a new blank Simulink model.
删除Simulation Rate Controlblock.
On the Apps tab, underControl Systems, 点击机器人操作系统(ROS)。
在里面机器人操作系统(ROS)打开的对话框,选择机器人操作系统(ROS)
来自罗斯Networkdrop-down. This opens up the罗斯工具条中的选项卡,显示在Connect部分。
在里面Prepare部分罗斯tab, clickHardware Settingsto open the model configuration parameters dialog box.
TheHardware board settings部分包含特定于生成的ROS软件包的设置,例如包含的信息package.xml
文件。改变维护者名称to罗斯Example User
和click好的。
在里面求解器pane of theConfiguration Parametersdialog, ensure the类型被设定为Fixed-step
, the求解器被设定为ode3(Bogacki-Shampine)
和theFixed-step size被设定为0.05
。在生成的代码中,固定步骤的大小定义了用于模型更新循环的实际时间步。看Execution of Code Generated from a Model(Simulink Coder)for more information.
在里面Code Generationpane, ensure可变大小信号is enabled.
Click好的to close theConfiguration Parametersdialog. Save the model asRobotController.slx
。
配置代码生成的构建选项
After configuring the model, you must specify the build options for the target hardware and set the folder or building the generated code.
ClickDeploy在下面罗斯标签。然后在下面Deployment, 点击Build Model此设置确保为ROS节点生成代码,而无需在外部ROS设备上构建它。
Generate and Deploy the Code
Start a ROS master in MATLAB®。This ROS master is used by Simulink for the code generation steps.
在里面MATLAB command window type:
石榴石
将当前文件夹设置为写入目录。该文件夹是当您构建模型时将存储代码的位置。
Under theC代码tab, click生成代码或按Ctrl+b
开始代码生成模型。
Once the build completes, two new files are written to your folder.
RobotController.tgz
- 一个包含C ++代码的档案build_ros_model.sh
- 用于提取和构建C ++代码的外壳脚本
手动将两个文件传输到目标计算机。如果您使用ROS设备连接罗斯迪夫
, you can send files usingPutfile
。Otherwise, this step assumes you are using the Linux virtual machine used for Robotics System Toolbox™ examples. The virtual machine is configured to accept SSH and SCP connections.如果您使用自己的Linux系统,请咨询您的系统管理员,以获取安全传输文件的安全方法。
Ensure your host system (the system with yourRobotController.tgz
和build_ros_model.sh
文件)有一个SCP客户端。对于Windows®systems, the next step assumes that PuTTY SCP client (pcsp.exe
) is installed.
使用SCP将文件传输到Linux虚拟机上的用户主任。用户名是用户
和password ispassword
。代替
使用您的虚拟机IP地址。
Windows主机系统:
pscp.exe RobotController.tgz build_ros_model.sh user@
: Linux or苹果系统主机系统:
scp RobotController.tgz build_ros_model.sh user@
:
Thebuild_ros_model.sh
文件不是该模型的特定特定的。多种模型只需要传输一次。
On the Linux system, execute the following commands to create a Catkin workspace. You may use an existing Catkin workspace.
mkdir -p ~/catkin_ws_simulink/src cd ~/catkin_ws_simulink/src catkin_init_workspace
Decompress and build the node there using the following command in Linux. Replace
with the path to your catkin workspace.
cd〜 ./build_ros_model.sh robotcontroller.tgz
如果那不起作用,请确保build_ros_model.sh
通过输入以下命令将其设置为可执行文件。
chmod +x build_ros_model.sh
生成的源代码不在~/catkin_ws_simulink/src/robotcontroller/
。Review the contents of thepackage.xml
文件。验证节点可执行文件是使用以下方式创建的:
file ~/catkin_ws_simulink/devel/lib/robotcontroller/robotcontroller_node
If the executable was created successfully, the command lists information about the file.
现在,该模型可以作为设备上的独立ROS节点运行。
可选的:然后,您可以使用此命令运行节点。代替
with the path to your catkin workspace.
~//devel/lib/robotcontroller/robotcontroller_node