1、在MATLAB 官网answer中,找到如何发布/订阅机器人关节状态信息流。

来源:https://ww2.mathworks.cn/matlabcentral/answers/270072-joint_states-publisher

A:Hello, I am using the Robotics Toolbox on Matlab to work on the Baxter robot. While I subscribe to a topic like /robot/joint_states and create a publisher for the same, instead of receiving the stream of joint angle sets I just receive one set of joint angles. The commands I am using are the following:

 joint_state_sub = rossubscriber('/robot/joint_states');state_pub = receive(joint_state_sub,10);
Also in the publisher I am unable to understand the value 10, as even if I change it to 100 or any other value  I still get the same result.

Q:The receive function waits up to N (10, 100, etc.) seconds to receive the NEXT incoming message in the stream -- it is not meant to receive the entire stream.

There are plenty of ways to receive the whole data set by repeatedly calling receive (Waits for the next message) or using the LatestMessage property (picks the last received message, can get the same message multiple times in a row if no new ones come in).

代码:

msg = receive(joint_state_sub,10);
msg = joint_state_sub.LatestMessage;

One way you could do it is in a for-loop. For example, suppose you want to receive the next 5000 messages that come in:

代码:

% Preallocate buffer of 5000 elements -- assuming there are 3 joints in this robot, hence 3 columns.
angles = zeros(5000,3);
% Loop through and receive
for idx = 1:5000state_msg = receive(joint_state_sub,10);angles(idx,:) = state_msg.Position;
end

By the way, it might be useful to also pick out the time stamps for each message if you want to plot these. To do this, you can use the Header portion of the message:

代码:

t_sec = state_msg.Header.Time.Stamp.Sec;
t_nsec = state_msg.Header.Time.Stamp.Nsec;
...
times(idx) = double(t_sec) + 1e-9*double(t_nsec)

2、从Simulink®生成独立的ROS节点

     来源:https://ww2.mathworks.cn/examples/robotics/mw/robotics-ex31008889-generate-a-standalone-ros-node-from-simulink

Generate a Standalone ROS Node from Simulink®

This example shows you how to generate and build a standalone ROS node from a Simulink model.

Introduction

In this example, you configure a model to generate C++ code for a standalone ROS node. You then build and run the ROS node on an Ubuntu® Linux® system.

在此示例中,您将配置模型以为独立ROS节点生成C ++代码。 然后,您可以在Ubuntu®Linux®系统上构建并运行ROS节点

Prerequisites先决条件

  • This example requires Simulink Coder™.
  • A Ubuntu Linux system with ROS and an SSH server installed 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 Robotics System Toolbox™ examples (see Get Started with Gazebo and a Simulated TurtleBot for instructions).
  • Review the Feedback Control of a ROS-enabled Robot example.

Task 1 - Configure a Model for Code Generation

In this task, you configure a model to generate C++ code for a standalone ROS node. The model is the proportional controller introduced in the Feedback Control of a ROS-enabled Robot example.

  • Open the robot feedback control model. Select Edit > Select All, then Edit > Copy.
  • Open a new Simulink model. Select Edit > Paste.
  • Delete the Simulation Rate Control block.
  • Click on Simulation > Model Configuration Parameters.
  • The model requires variable-sized arrays, so enable it by checking Code Generation > Interface > Software environment > Support > variable-size signals. Go to Hardwarde Implementation > Advanced Parameters and check Use Embedded Coder features to enable this option.
  • In the Hardware Implementation pane of the Configuration Parameters dialog, set Hardware board to Robot Operating System (ROS), and click Apply. The Hardware board settings section contains settings specific to the generated ROS package, such as information to be included in the package.xml file. Change Maintainer name to ROS Example User.

  • In the Solver pane of the Configuration Parameters dialog, ensure that Solver Type is set to Fixed-step, and set Fixed-step size to 0.05. In generated code, the Fixed-step size defines the actual time step, in seconds, that is used for the model update loop (see About Model Execution). It can be made smaller (e.g., 0.001 or 0.0001) but for current purposes 0.05 is sufficient.

  • Click OK to close the Configuration Parameters dialog. Save the model as RobotController.slx.

Task 2 - Configure the Connection to the ROS Device

A ROS device is any Linux system that has ROS installed and is capable of building and running a ROS node. If you have Simulink Coder, you can generate code for a standalone ROS node. If your system is connected to a ROS device, Simulink can also transfer the generated code to the ROS device, build an executable, and run the resulting ROS node (this is referred to as "deploying" the ROS node).

In this task, you decide if you want to generate code for the ROS node or if you want to build and run it on a ROS device. If you are connected to a ROS device, you can configure Simulink to use it as a deployment target for your ROS node.

  • Click on Simulation > Model Configuration Parameters.
  • In the Hardware Implementation pane of Configuration Parameters dialog, click on Build Options. The selected Build action affects the behavior of Simulink when building the model. None (the default setting) only generates the code for the ROS node, without building it on an external ROS device. Build and load generates the code, transfers it to an external device and builds a ROS node executable. If you select Build and run, the resulting node executable is started automatically at the end of the build.

  • Set the Build action to Build and run
  • Configure the connection to your external ROS device. Click Edit to open the device configuration dialog. In this dialog, you can enter all the information that Simulink needs to deploy the ROS node. This includes the IP address or host name of your ROS device, your login credentials, and the Catkin workspace. Change Catkin workspace to ~/catkin_ws_test.

ROS Folder is the location of the ROS installation on the ROS device. If you do not specify this folder, the settings test (see next step) tries to determine the correct folder for you.

  • If the ROS device is turned on and accessible from your computer, you can verify the connection settings by clicking Test. The test verifies every device setting and display warnings and errors in the Simulink Diagnostic Viewer if problems are found. If possible, the test also suggests how the problems can be fixed. Click Test now.

  • Most likely, the Catkin workspace ~/catkin_ws_test does not exist on the target device. The test detects this problem and suggests to create the folder and initialize the workspace. Click Fix to apply this action automatically. After a few seconds, you should see a green notice that the folder has been created successfully. To verify that the Catkin workspace is now available, click Test in the connection settings dialog again. The warning has disappeared and the Catkin workspace is ready to build your ROS node.

  • Change the device connection settings and test them until no other warnings or errors are shown. If an automatic fix to your settings is possible, Simulink suggests it by displaying the Fix button. Once you have a good set of settings, click OK in the connection settings dialog to save the settings.

The connection settings are not specific to a single model, but apply to all ROS models in Simulink.

Task 3 - Generate the C++ ROS Node

In this task, you generate code for a standalone ROS node, and automatically transfer, build, and run it on the ROS device. You exercise the generated ROS node using a ROS master running on the ROS device.

1. In MATLAB®, change the current folder to a temporary location where you have write permission.

2. The code generation process first prepares the model for simulation to ensure that all blocks are properly initialized. This preparation requires a valid connection to a ROS master.

In MATLAB, you can use the rosdevice object to start a ROS master on the ROS device. If you provide no arguments, rosdevice uses the device connection settings you entered in the Simulink dialog to connect to the ROS device.

d = rosdevice

runCore(d);

3. Use rosinit to connect MATLAB to the ROS master running on the ROS device:

rosinit(d.DeviceAddress)

4. Tell Simulink to use the same ROS connection settings as MATLAB by selecting Tools > Robot Operating System > Configure Network Addresses, and setting the ROS Master and Node Host network addresses to Default.

You only have to execute steps 2 - 4 once per MATLAB session, not every time you generate a ROS node.

5. Click on Code > C/C++ Code > Deploy to Hardware. If you get any errors about bus type mismatch, close the model, clear all variables from the base MATLAB workspace, and re-open the model.

Click on the View Diagnostics link at the bottom of the model toolbar to see the output of the build process.

6. Once the code generation completes, the ROS node is transferred to the Catkin workspace on your ROS device. The node builds there and starts to run automatically.

The generated node connects to the ROS master running on the ROS device.

7. Use rosnode to list all running nodes is the ROS network. "robotcontroller" should be in the displayed list of nodes.

rosnode list

You can use rostopic to verify that the deployed node publishes data on the ROS topic to control the robot motion:

rostopic info /mobile_base/commands/velocity

Task 4 - Run and Verify the ROS Node

In this task, you run the newly-built ROS node and verify its behavior using a MATLAB-based robot simulator.

1. In MATLAB, type ExampleHelperSimulinkRobotROS to start the Robot Simulator. The simulator automatically connects to the ROS master running on the ROS device. If you want to connect to a Gazebo-based robot simulation, see Connect to a ROS-enabled Robot from Simulink.

sim = ExampleHelperSimulinkRobotROS

2. Verify that the simulated robot moves toward the goal (the Desired Position constant specified in the model). The robot stops once it reaches the goal [-10, 10].

3. Click Reset Simulation to reset the robot's position to [0, 0]. The robot starts to move immediately towards the goal position.

4. In MATLAB, you can manage ROS nodes generated by Simulink with the rosdevice object. Once a Simulink model is deployed, you can use rosdevice to run and stop the node at any point, without having to rebuild it in Simulink.

The AvailableNodes property shows the deployed robotcontroller node. You can verify that the node is running by calling the isNodeRunning function.

d = rosdevice

isNodeRunning(d, 'robotcontroller')

5. Stop the ROS node from running.

stopNode(d, 'robotcontroller')

isNodeRunning(d, 'robotcontroller')

6. Click the Reset Simulation button in the simulation window. The robot stays at location [0,0] and does not move.

  • Now restart the node.

runNode(d, 'robotcontroller')

  • The robot should start moving towards the goal position again.

7. Once you are done verifying, you can clean up the system state as follows.

  • Stop the node running on the target device

stopNode(d, 'robotcontroller')

  • On the host computer, close the Robot Simulator figure window and type rosshutdown at the MATLAB command line.

rosshutdown

Advanced Topics and Troubleshooting

Specify ROS network settings in Simulink: By default, Simulink uses the ROS connection settings from rosinit in MATLAB. To override these settings and to specify ROS connection settings in Simulink, select Tools > Robot Operating System > Configure Network Addresses, and set the ROS Master and Node Host network addresses:

Generated C++ code archive: No matter what Build action you select (None, Build and load, Build and run), Simulink always generates two files in your current folder: an archive containing the C++ source code (RobotController.tgz in our example) and a shell script for extracting and building the C++ code manually (build_ros_model.sh). If your MATLAB computer is not connected to the ROS device, you can transfer the files manually and build them there.

Processor-specific generated code: If you use blocks from other products (such as Computer Vision System Toolbox™), the generated code may include processor-specific optimizations that lead to compilation problems when building the ROS node on Linux. In these cases, you need to let Simulink know the platform on which the generated code is compiled. You can do this through the Hardware Implementation pane of the Model Configuration Parameters dialog.

Install additional ROS packages: Robotics System Toolbox includes many ROS message types (e.g., for Baxter® or PR2®) that are not part of the standard ROS distribution. If your Simulink model includes non-standard or custom message types, you are able to simulate and generate code successfully. However, in order to build the generated ROS node, you need to first download and install all the required packages. Here is one way to do it (assume that the required package is baxter_core_msgs).

On the MATLAB prompt:

d = rosdevice;

openShell(d);

On the Linux shell:

# Refresh the list of available packages

sudo apt-get update

# Search the list for ROS Baxter packages (e.g., ros-indigo-baxter-core-msgs)

apt-cache search baxter

# Download and install the required package

sudo apt-get install ros-indigo-baxter-core-msgs

Note that this command may take several minutes to complete.

Running ROS Master in MATLAB: In the example above, you connected to a ROS master running on the ROS device. Alternatively, you can create a ROS master in MATLAB. Use rosinit at the MATLAB command line:

rosinit('NodeHost', <IP address of your computer>)

For example, if the IP address of your host computer is 172.28.194.92, use the following command:

rosinit('NodeHost', '172.28.194.92')

The NodeHost setting is important to ensure that the generated ROS node is able to communicate to the master on MATLAB. Note: The generated ROS node will use the NodeHost IP address to communicate to the global ROS node in MATLAB, so ensure that the specified IP address is accessible from the ROS device (for example, using ping). See the Connect to a ROS Network example for more details on the significance of the NodeHost setting.

Tasking mode: Simulink can generate code for either multi-tasking or single-tasking modes (see Time-Based Scheduling and Code Generation). By default, generated ROS code uses single-tasking mode (a single thread for all the rates) without real-time scheduling. This allows the generated ROS code to execute without sudo privileges, but can lead to less predictable performance.

If you require more predictable performance, you can configure the model to use multi-tasking. In the Solver pane of the Configuration Parameters dialog enable Treat each discrete rate as a separate task to enable multi-tasking. In generated code, this creates a separate thread for each rate in the model and uses prioritized scheduling for the threads.

To run the ROS node, you need to have administrative privileges on the ROS device. Simulink automatically detects if your privileges are insufficient when the model is deployed to the target device.

Summary

This example showed you how to configure a Simulink model to generate C++ code for a standalone ROS node. It also showed how to transfer, build, and verify the ROS node.

Copyright 2014-2017 The MathWorks, Inc.

3、ROS包上使用readMessages()会得到不完整的TF数据(版本原因2018a和之前版本。。。)

https://ww2.mathworks.cn/matlabcentral/answers/394157-using-readmessages-on-ros-bag-gives-incomplete-tf-data

4、与机器人工具箱兼容的ROS版本(应该都支持,只要Message type一致

  来源:https://ww2.mathworks.cn/matlabcentral/answers/345066-what-are-the-ros-versions-compatible-with-the-robotics-toolbox

回答:In general, different ROS distributions (Groovy, Hydro, Indigo) can communicate with each other, as long as they agree on the definition of the message type that they are interchanging. definitions do not change very often and a set of definitions is included for ROS Hydro in Robotics System Toolbox.

If you need support for message types that are not included in Robotics System Toolbox(or that changed between ROS distributions), you can use the custom message support package present at the following URL to add the new message type to MATLAB and Simulink:

http://www.mathworks.com/matlabcentral/fileexchange/49810-robotics-system-toolbox-interface-for-ros-custom-messages

If you want to re-define shipping message types to a different version, then you can follow the instructions described in the following MATLAB Answers post:

https://www.mathworks.com/matlabcentral/answers/283695-updating-existing-custom-message-types-with-rosgenmsg

Through this mechanism, MATLAB should be able to communicate to any version of ROS.

In terms of Baxter support, there are several demos of using Baxter with the toolbox, for example at the MATLAB Expo in 2015: http://www.matlabexpo.com/uk/2015/demo-stations.html

5、如何在Simulink中为Baxter机器人使用反向运动学求解器(回答模糊)

来源:https://ww2.mathworks.cn/matlabcentral/answers/325012-how-to-use-inverse-kinematics-solver-for-the-baxter-robot-in-simulink

解答说有文档:http://docs.ros.org/hydro/api/baxter_core_msgs/html/index-msg.html

6、使用Joint Trajectory Action Server移动Baxter的关节节点运行时错误(未解答)

https://ww2.mathworks.cn/matlabcentral/answers/356393-moving-baxter-s-joints-using-joint-trajectory-action-server

7、simulink中baxter_core_msgs / JointCommand的问题(阵列大小设置)

来源:https://ww2.mathworks.cn/matlabcentral/answers/226385-problems-of-baxter_core_msgs-jointcommand-in-simulink

问题:

I tried to control baxter robot using simulink, but I find there may be some problem of creating topic. 1, there is no names(data type, string[]) for baxter_core_msgs/JointCommand; 2, the Msg.command input port requires 128X1 elements of array, while actually we only need 7X1 array to publish the topic e.g. '/robot/limb/left/joint_command'. what's the 128X1 elements of array composed of? it works in matlab manuscripts,as follows, pub=rospublisher('/robot/limb/left/joint_command','baxter_core_msgs/JointCommand'); Msg=rosmessage('baxter_core_msgs/JointCommand');

command=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];% here we can see it's 7X1, not 128X1 declared in simulink. names=[{'left_w0'}, {'left_w1'}, {'left_w2'}, {'left_e0'}, {'left_e1'}, {'left_s0'}, {'left_s1'}]; mode=1; Msg.Command=int64(command);

Msg.Mode=int32(1); Msg.Names=(names); send(pub,Msg);

Looking forward to your answers! Thanks,

回答:128X1 is the default size. You can change this by going to Tools>>Robot Operating System and set the value in Manage Size Arrays. Please see this doc link for more information: http://www.mathworks.com/help/robotics/ug/manage-array-sizes-in-simulink-ros.html

8、BaxterComm WithSim()使用类时发生错误。()

https://ww2.mathworks.cn/matlabcentral/answers/412178-baxtercommwithsim-class

回答:下载Baxter Communicator Class

地址:https://jp.mathworks.com/matlabcentral/fileexchange/63564-baxter-communicator-class

9、打开或关闭baxter抓手

https://ww2.mathworks.cn/matlabcentral/answers/330259-open-and-close-baxter-s-gripper

代码但是错误:

rosinit('169.254.9.127') % ip address of baxter
rostopic info /robot/end_effector/right_gripper/command
pub = rospublisher('/robot/end_effector/right_gripper/command')
msg = rosmessage('baxter_core_msgs/EndEffectorCommand')
showdetails(msg)
msg.Id=65538
msg.Command= 'grip'
msg.Sender= 'foo'
msg.Sequence= 1
send(pub,msg)% nothing happens
msg.Command= 'release'
send(pub,msg) %nothing happens again
rosshutdown

回答:

I had the same problem. After some searching I managed to figure it out. The way to do this is through the script gripper_action_server.py

Use rosrun baxter_interface gripper_action_server.py

This will start an node for baxter gripper control

then in Matlab use rosaction list. You should now see 2 actions, one for the left gripper and one for the right.
然后在MATLAB中:

[actClient,goalMsg] = rosactionclient('/robot/end_effector/right_gripper/gripper_action');waitForServer(actClientgoalMsg = 100       % fully open打开sendGoalAndWait(actClient,goalMsg,10)goalMsg = 0         % fully closed关闭sendGoalAndWait(actClient,goalMsg,10)

MATLAB 控制baxter机器人相关信息(个人记录--学习用)相关推荐

  1. MATLAB与Baxter机器人通信---网络环境配置篇

    1.前记:在做MATLAB控制Baxter机器人的实验搭建过程中遇到的网络通信问题,这几个名词让人头疼. 主机名--IP--域名 以下记录方便查询! https://blog.csdn.net/hou ...

  2. Baxter机器人相关配置

    一.新建ROS工作空间并编译 mkdir -p baxter_ws/src cd ~/baxter_ws/src catkin_init_workspace cd ~/baxter_ws catkin ...

  3. ROS环境下Baxter机器人控制记录

    1.前记: 这篇博文为自己学习是的记录,做这一切的目的就是熟悉ROS环境下如何控制Baxter机器人做运动.以便将来对其控制的扩展,如基于视觉(单目,双目,或Kinect)交互的控制,基于leap m ...

  4. 一种从Robotstudio环境中导出机器人模型并在MATLAB下使其可视化的研究记录

    1.前记:回到学校反而没时间记录了自己瞎折腾的东西了,允我长长的叹一口气   '_' // 先提一下,在这篇MATLAB机器人可视化博客中提到了如何使CAD模型的机器人在MATLAB环境下可视化的问题 ...

  5. m半分布式JAC联合接纳控制与用户位置信息的垂直切换matlab仿真

    目录 1.算法描述 2.仿真效果预览 3.MATLAB核心程序 4.完整MATLAB 1.算法描述 随着无线通信技术的飞速发展,为支持多种不同无线接入技术.不同系统间协作.不同业务类型及终端差异性等需 ...

  6. Ubuntu18.04+ROS melodic 控制UR5机器人(持续更新)

    目录 0 前言 1 前置准备工作 1.1 环境配置 1.1.1 使用虚拟机安装Ubuntu系统 1.1.2 ROS melodic安装 1.2 工作空间配置 1.2.1 创建工作空间 1.2.2 导入 ...

  7. ar编码matlab仿真_机器人常用可视化仿真工具

    机器人系统设计离不开仿真工具的支持.机器人仿真让我们在没有物理硬件的情况下也可以快速对算法进行验证:或者提高安全性,避免实验损伤我们的设备(比如在增强学习中,就需要大量random的explorati ...

  8. 利用MATLAB控制HFSS进行仿真

    利用MATLAB控制HFSS联合进行仿真 说明 HFSS是一款三维仿真软件,经常用在天线设计领域,在设计天线时我们经常为了使天线达到需要的性能指标使用各种优化算法来对天线进行优化,但是HFSS自带的o ...

  9. 计算光学成像(COI)实验室技能——matlab控制thorlabs位移平台(ActiveX控件)

    计算光学成像(COI)实验室技能--matlab控制thorlabs位移平台   本文将介绍如何用matlab代码控制thorlabs位移平台(其他支持ActiveX控件的硬件实现方法类似).通过代码 ...

最新文章

  1. linux /dev/snd,linux – / dev / tcp去了哪里?
  2. Jquery操作Cookie,保存商品ID值至本地文件中
  3. html图片与周围元素边界5px,css3如何将图像设置为元素周围的边框
  4. 北大计算机博进高校,他是北大第一位博士,留校任教却连做三件“傻事”,博导都没评上...
  5. How to include library manually into maven local repository?
  6. jquery $加一个点后面加个名称的意思
  7. 前后端分离 ---购物车
  8. java 获取文件大小_利用百度AI OCR图片识别,Java实现PDF中的图片转换成文字
  9. js_md5加密和base64的加密解密
  10. MYSQL中的日期转换
  11. mysql实体监听器_监听器模式(Listener)
  12. QCC3040---battery module
  13. 方法finalizer()的应用
  14. Android 腾讯地图 选点定位,仿微信发送位置
  15. |函数相乘分离 函数增长速度|day6
  16. Intrinsics函数Tips与踩坑
  17. 计算机网络回环测试命令,实验二 常用网络测试命令.doc
  18. 10 面阿里,7 面头条,6 个 offer, 你猜我进阿里没?
  19. 华为时习知,让企业培训更简单!
  20. JTAG接口到SWD接口连接

热门文章

  1. 韩国社交软件Kakao Talk要开网络银行,社交软件+银行的模式会怎么转?
  2. [逆向工具] 详解pbtk解析steam中的protobuf协议
  3. 涉嫌行贿 三星掌门人等韩企大佬将首次集体接受质询
  4. 拼命加班撸Excel,准点下班的新人却被升职
  5. Android仿QQ圆形头像
  6. 年后跳槽:哪些迹象告诉我们,公司可能不行了?
  7. CLLocationManager定位经纬度,MKReverseGeocoder地址解析, MKMapView 地图显示 iphone
  8. Spring IOC循环依赖问题
  9. 【POJ2325】Persistent Numbers 贪心+高精度/低精度
  10. oracle 日历每个月的第一天显示为中文的月份