ROS动作编程

ROS程序设计--动作编程与分布式编程 ros 进行动作编程是进行嵌入式开发的一个核心步骤,也是帮助我们更好的了解机器学习的一项重要基础,通过动作编程,我们可以了解到机器人是如何进行我们人类行为得规划的,这也为我们未来进入人工智能打下一个良好的开端。[在这里插入图片描述](https://img-blog.csdnimg.cn/208813e85ffe41bf996ec956e1d6e2b7.png。参考链接:https://blog.csdn.net/m0_72668380/article/details/129642622。 阅读详情


ROS动作编程

一、在工程包中创建项动作编程需要的文件

1、 创建小乌龟移动的“服务文件”turtleMove.cpp

1 、新建一个终端,这里命名为终端 1,然后进入工程包 comm 下的 src 文件中
命令:cd ~/ros/src/comm/src
2 、新建服务文件 turtleMove.cpp
命令:cd ~/ros/src/comm/src
3 、将如下 C++语言代码写入 turtleMove.cpp 文件中,保存后关闭!
命令:gedit turtleMove.cpp

/*
此程序通过通过动作编程实现由 client 发布一个目标位置
然后控制 Turtle 运动到目标位置的过程
*/
#include <ros/ros.h>
#include <actionlib/server/simple_action_server.h>
#include "comm/turtleMoveAction.h"
#include <turtlesim/Pose.h>
#include <turtlesim/Spawn.h>
#include <geometry_msgs/Twist.h>
typedef actionlib::SimpleActionServer<comm::turtleMoveAction> Server;
struct Myturtle
{
float x;
float y;
float theta;
}turtle_original_pose,turtle_target_pose;
ros::Publisher turtle_vel;
void posecallback(const turtlesim::PoseConstPtr& msg)
{
ROS_INFO("turtle1_position:(%f,%f,%f)",msg->x,msg->y,msg->theta);
turtle_original_pose.x=msg->x;
turtle_original_pose.y=msg->y;
turtle_original_pose.theta=msg->theta;
}
// 收到 action 的 goal 后调用该回调函数
void execute(const comm::turtleMoveGoalConstPtr& goal, Server* as)
{
comm::turtleMoveFeedback feedback;
ROS_INFO("TurtleMove is working.");
turtle_target_pose.x=goal->turtle_target_x;
- 3 -
turtle_target_pose.y=goal->turtle_target_y;
turtle_target_pose.theta=goal->turtle_target_theta;
geometry_msgs::Twist vel_msgs;
float break_flag;
while(1)
{
ros::Rate r(10);
vel_msgs.angular.z = 4.0 *
(atan2(turtle_target_pose.y-turtle_original_pose.y,
turtle_target_pose.x-turtle_original_pose.x)-turtle_original_pose.theta);
vel_msgs.linear.x = 0.5 *
sqrt(pow(turtle_target_pose.x-turtle_original_pose.x, 2) +
pow(turtle_target_pose.y-turtle_original_pose.y, 2));
break_flag=sqrt(pow(turtle_target_pose.x-turtle_original_pose.x, 2) +
pow(turtle_target_pose.y-turtle_original_pose.y, 2));
turtle_vel.publish(vel_msgs);
feedback.present_turtle_x=turtle_original_pose.x;
feedback.present_turtle_y=turtle_original_pose.y;
feedback.present_turtle_theta=turtle_original_pose.theta;
as->publishFeedback(feedback);
ROS_INFO("break_flag=%f",break_flag);
if(break_flag<0.1) break;
r.sleep();
}
// 当 action 完成后,向客户端返回结果
ROS_INFO("TurtleMove is finished.");
as->setSucceeded();
}
int main(int argc, char** argv)
{
ros::init(argc, argv, "turtleMove");
ros::NodeHandle n,turtle_node;
ros::Subscriber sub =
turtle_node.subscribe("turtle1/pose",10,&posecallback); //订阅小乌龟的位置
信息
turtle_vel =
turtle_node.advertise<geometry_msgs::Twist>("turtle1/cmd_vel",10);//发布控
制小乌龟运动的速度
// 定义一个服务器
- 4 -
Server server(n, "turtleMove", boost::bind(&execute, _1,
&server), false);
// 服务器开始运行
server.start();
ROS_INFO("server has started.");
ros::spin();
return 0;
}

文件创建完毕
请添加图片描述

2、创建小乌龟“发布目标位置文件”turtleMoveClient.cpp

1)、在相同的目录下,创建“发布目标位置”文件 turtleMoveClient.cpp
命令:touch turtleMoveClient.cpp
2、将如下 C++代码写入目标位置文件 turtleMoveClient.cpp 中,如下:
命令:gedit turtleMoveClient.cpp

#include <actionlib/client/simple_action_client.h>
#include "comm/turtleMoveAction.h"
#include <turtlesim/Pose.h>
#include <turtlesim/Spawn.h>
#include <geometry_msgs/Twist.h>
typedef actionlib::SimpleActionClient<comm::turtleMoveAction>
Client;
struct Myturtle
{
float x;
float y;
float theta;
}turtle_present_pose;
// 当 action 完成后会调用该回调函数一次
void doneCb(const actionlib::SimpleClientGoalState& state,
const comm::turtleMoveResultConstPtr& result)
{
- 5 -
ROS_INFO("Yay! The turtleMove is finished!");
ros::shutdown();
}
// 当 action 激活后会调用该回调函数一次
void activeCb()
{
ROS_INFO("Goal just went active");
}
// 收到 feedback 后调用该回调函数
void feedbackCb(const comm::turtleMoveFeedbackConstPtr& feedback)
{
ROS_INFO(" present_pose : %f %f %f",
feedback->present_turtle_x,
feedback->present_turtle_y,feedback->present_turtle_theta);
}
int main(int argc, char** argv)
{
ros::init(argc, argv, "turtleMoveClient");
// 定义一个客户端
Client client("turtleMove", true);
// 等待服务器端
ROS_INFO("Waiting for action server to start.");
client.waitForServer();
ROS_INFO("Action server started, sending goal.");
// 创建一个 action 的 goal
comm::turtleMoveGoal goal;
goal.turtle_target_x = 1;
goal.turtle_target_y = 1;
goal.turtle_target_theta = 0;
// 发送 action 的 goal 给服务器端,并且设置回调函数
client.sendGoal(goal, &doneCb, &activeCb, &feedbackCb);
ros::spin();
return 0;
}

请添加图片描述

3、在功能包目录下创建 action 文件夹

1、进入工程包目录
命令:cd ~/ros/src/comm
2、创建 action 文件夹
命令:mkdir action
3、在 action 文件夹下创建 turtleMove.action 文件

  1. 进入 action 文件夹
    命令:cd action
  2. 创建 turtleMove.action 文件
    命令:touch turtleMove.action
  3. 将如下代码写入 turtleMove.action 文件中,如下:
    命令:gedit turtleMove.action
# Define the goal
float64 turtle_target_x # Specify Turtle's target position
float64 turtle_target_y
float64 turtle_target_theta
---
# Define the result
float64 turtle_final_x
float64 turtle_final_y
float64 turtle_final_theta
---
# Define a feedback message
- 7 -
float64 present_turtle_x
float64 present_turtle_y
float64 present_turtle_theta

请添加图片描述

4、修改CMake和package文件

在CMakeLists.txt文件末尾添加如下代码:

add_executable(turtleMoveClient src/turtleMoveClient.cpp)
target_link_libraries(turtleMoveClient ${catkin_LIBRARIES})
add_dependencies(turtleMoveClient ${PROJECT_NAME}_gencpp)
add_executable(turtleMove src/turtleMove.cpp)
target_link_libraries(turtleMove ${catkin_LIBRARIES})
add_dependencies(turtleMove ${PROJECT_NAME}_gencpp)

请添加图片描述
在该文件中找到find_package函数方法,修改为如下:

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  message_generation
  actionlib_msgs
  actionlib
)

请添加图片描述

继续在该文件中找到add_action_files函数一项,默认是用#注释掉了的,这里我们找到后修改为如下代码:

 add_action_files(
   FILES
   turtleMove.action
 )

注意:以上turtleMove.action为我们在action文件夹下面创建的文件名字turtleMove.action请添加图片描述

继续在该文件中找到generate_messages函数一项,默认也是#注释,这里修改为如下代码

generate_messages(
   DEPENDENCIES
   std_msgs
   actionlib_msgs
 )

请添加图片描述
找到catkin_package函数一项,修改为如下代码:

#  INCLUDE_DIRS include
#  LIBRARIES comm
#  CATKIN_DEPENDS roscpp rospy std_msgs
#  DEPENDS system_lib
 CATKIN_DEPENDS roscpp rospy std_msgs
  message_runtime

请添加图片描述
修改package.xml文件内容
将文件中build_depend一栏、替换为如下代码:

<buildtool_depend>catkin</buildtool_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_depend>message_generation</build_depend>
  <build_depend>actionlib</build_depend>
  <build_depend>actionlib_msgs</build_depend>
  <build_export_depend>roscpp</build_export_depend>
  <build_export_depend>rospy</build_export_depend>
  <build_export_depend>std_msgs</build_export_depend>

将文件中exec_depend一栏、替换为如下代码:

<exec_depend>roscpp</exec_depend>
  <exec_depend>rospy</exec_depend>
  <exec_depend>std_msgs</exec_depend>
  <exec_depend>message_runtime</exec_depend>
  <exec_depend>actionlib</exec_depend>
  <exec_depend>actionlib_msgs</exec_depend> 

请添加图片描述

5、运行程序进行测试

编译文件

catkin_make

注册程序

 source ./devel/setup.bash

请添加图片描述
新建一个终端,命令为终端2,启动ros
请添加图片描述
再新建一个终端,命名为终端3,运行我们的小海龟,出现小海龟窗口,我们命名为窗口3
请添加图片描述
在新建一个终端,命名为终端4,运行我们的目标位置程序代码:
进入ros工作空间

cd ~/ros

程序注册

source ./devel/setup.bash

运行turtleMoveClient.cpp,记住,输入该命令,但不忙按回车

rosrun comm turtleMoveClient

请添加图片描述
在终端1运行turtleMove,记住,输入如下命令,也不忙按回车

rosrun comm turtleMove

开始测试,终端1回车、终端4回车,出现如下画面,则我们动作编程的实验完美成功:
请添加图片描述
实验成功,我们在终端1 Ctrl+c关闭运行的程序,完成实验

总结

ros进行动作编程是进行嵌入式开发的一个核心步骤,也是帮助我们更好的了解机器学习的一项重要基础,通过动作编程,我们可以了解到机器人是如何进行我们人类行为得规划的,这也为我们未来进入人工智能打下一个良好的开端,这次实验中出现了编译失败的过程,但我并未直接解决该问题,我是通过创建一个新的工作空间来解决编译问题。

参考

https://blog.csdn.net/qq_42451251/article/details/104747355?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522167878017216782428610630%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=167878017216782428610630&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_ecpm_v1~rank_v31_ecpm-1-104747355-null-null.142v73pc_search_v2,201v4add_ask,239v2insert_chatgpt&utm_term=void%20feedbackCb%28const%20comm%3A%3AturtleMoveFeedbackConstPtr%26%20feedback%29&spm=1018.2226.3001.4187

ROS编程实现 步骤一:定义msg文件在文件夹中创建msg文件夹,跟消息相关定义都存放在msg文件夹中,方便管理,创建文件person.msg,打开文件,将下列文件放入person.msg文件中。uint8 sexuint8 age步骤二:在package.xml中添加功能包依赖在文件夹中打开文件,添加下面的语句</一个是编译依赖,编译依赖是一个动态产生message的功能包;一个是执行依赖,执行依赖是一个执行message的功能包。步骤三:在CMakeLists.txt添加编译选项。 阅读详情

相关推荐

ROS动作编程练习

参考链接:https://blog.csdn.net/qq_42451251/article/details/104664926。存放工程开发相关文件的文件夹,其中主要包括src,build,devel,install文件夹。2.向ROS Master注册节点信息,包括发布的话题名和话题中的消息类型。打开callBackYuan.cpp文件,输入如下代码。4.在回调函数中完成服务功能的处理,并反馈应答数据。1.设置需要编译的代码和生成的可执行文件。1.设置需要编译的代码和生成的可执行文件。

m0_64363794的博客 2004

机器人操作系统ROS(6)动作编程

机器人操作系统ROS动作编程

_____ 833

ROS基础——动作编程

ROS基础——动作编程 什么是动作(action) 一种问答通信机制 带有连续反馈 可以在任务过程中止运行 基于ROS的消息机制实现 Action的接口 goal:发布任务目标 cancel:请求取消任务 status:通知客户端当前的状态 feedback:周期反馈任务运行的监控数据 result:向客户端发送任务的执行结果,只发布一次 一、定义action文件 cd ~/catkin_ws/src/learning_action/action sudo gedit DoDishes.action

TBMmagic的博客 839

【ROS 编程进阶】

在~/catkin_ws/src/learning_service 目录下,创建 srv 文件夹及 Person.srv 文件,在终端输入uint8 ageuint8 sex。

YYANyk的博客 588

ros2动作编程-server

我们这一节开始学习ros2的动作编程,(预留动作编程原理)将创建运行一个动作服务器节点和动作客户端节点实现斐波那契数列的运算。 首先我们进入我们的消息功能包添加一个action文件夹幷在里面新建一个Fibonacci.action文件,内容如下: #goal int32 order --- #result int32[] sequence --- #feedback int32[] partial...

qq825255961的博客 1397

机器人动作编程中文版

机器人动作编程是一个热门话题,本软件配合宙斯机器人把双走机器人的动作变得非常容易,其中的算法,编程思想是非常有意义的。

ROS 入门 —— 动作编程

ROS 入门 —— 动作编程 客户端发送一个运动目标,模拟机器人运动到目标位置的过程,包含服务端和客户端的代码实现,要求带有实时位置反馈 什么是动作? 机器人是一个复杂的智能系统,并不仅仅是键盘遥控运动、识别某个目标这么简单,我们需要实现的是送餐、送货、分拣等满足具体场景需求的机器人 在这些应用功能的实现中,另外一种 ROS 通信机制也会被常常用到——那就是动作。从这个名字上就可以很好理解这个概...

ppqppl的博客 800

ModusToolbox 实战避坑指南|从环境配置到项目构建

本文是一份详尽的ModusToolbox实战避坑指南,手把手教你从环境配置到项目构建。重点解决了Windows系统下的安装、关键环境变量CY_TOOLS_PATHS的设置、PowerShell执行策略调整以及利用URL Modifier工具优化GitHub资源下载等核心难题,旨在帮助开发者,特别是英飞凌(Infineon)芯片用户,顺利搭建开发环境并成功运行第一个Hello World程序。

t1u2v的博客 597

ROS基础学习—话题、服务、动作编程

在ROS(Robot Operating System)中,工作空间(Workspace)是一个用户可以用来组织并构建自定义ROS软件包的文件夹结构。通常,这个工作空间被称为,得名于ROS的构建系统catkin。一个典型的catkin工作空间包含以下几个部分:src (source)目录:这是工作空间的核心目录,包含所有的ROS软件包源代码。当你创建一个新的ROS工作空间时,会从创建这个目录开始。任何你下载或创建的自定义ROS软件包都应该放在这个目录下。build目录。

LX567567的博客 2002

OMNET++ INET框架学习教程(一)

在自组网学习的道路上摸石头过河,帮你快速入门OIMNET++平台下的INET框架。

NLDwangzhe的博客 6569

ILI9488 TFT屏驱动与触摸协同开发指南

TFT-LCD显示模块是嵌入式人机交互系统的核心外设,其工作原理依赖于专用显示控制器(如ILI9488)对GRAM显存的精确读写,并通过SPI等串行总线接收指令与图像数据。理解RGB接口时序、寄存器初始化流程及DC/CS信号控制逻辑,是实现稳定显示的基础技术前提;而四线电阻式触摸功能则需配合XPT2046类ADC控制器,通过独立SPI或模拟时序完成坐标采集。该方案兼顾低功耗、高集成与工程可移植性,广泛应用于工业HMI、仪器仪表及STM32F407等MCU平台的教学与产品开发。本文围绕3.5英寸320×480

weixin_33814090的博客 152

ROS kinetic 动作编程

Action接口goal    发布任务目标cancel    请求取消任务status    通知客户端当前的状态feedback    周期反馈任务运行的监控数据result    向客户端发送任务的执行结果,只发布一次自定义动作消息消息类型定义actionkinetic@vm:~$ mkdir ~/catkin_ws/src/learning_communication/actionkine...

Geek猫的专栏 2394

Python爬虫实战:使用最新技术抓取采购网招标公告信息

本文将详细介绍如何使用Python最新爬虫技术构建一个高效的采购网招标公告信息抓取系统。我们将从爬虫基础概念讲起,逐步深入到高级技巧,包括异步处理、反爬虫对策、数据解析与存储等,并提供完整的代码实现。本文旨在为读者提供一套完整的网络数据采集解决方案,适用于各类政府采购平台和商业招标网站。网络爬虫(Web Crawler)是一种自动抓取互联网信息的程序或脚本,它们按照一定的规则,自动地浏览万维网并提取所需数据。在现代商业环境中,爬虫技术广泛应用于价格监控、竞争情报收集、市场研究等领域。

2201_76125261的博客 1626

ROS机器人006-ROS通信编程(动作编程)

一、什么是动作编程 前面我们已经学习了服务编程和消息编程,服务编程主要是客户端提交给服务器数据,服务器处理数据后返回给客户端,动作编程也是服务端和客户端,但是应答式的服务,客户端提交动作,服务端进行完成,并实施报告进度 二、定义自定义动作消息 1.定义action文件 同样也是用三横杠分割,这里为两个三横杠 第一个为:动作的目标信息(ID) 第二个为:动作的结果信息(是否完成) 第三个为:动作周...

weixin_39193953的博客 915

超大规模系统(千万级用户)中实现字段级权限控制

摘要:本文提出了一套分布式架构下的字段级权限优化方案,结合RBAC+ABAC混合模型与技术手段实现性能与安全的平衡。方案包括:1)权限模型优化,采用RBAC预计算基础权限与ABAC动态校验敏感字段;2)数据层优化,实现动态字段过滤与加密存储;3)多级缓存策略与预计算机制提升性能;4)分布式架构设计,通过网关校验和策略引擎集群保证扩展性。最终在千万级用户系统中实现99.9%可用性,权限校验延迟控制在50ms以内。

从技术实践立足,从项目管理方法论延伸思考 1359

操作系统 | 知识梳理 | 复习(上)

操作系统复习

知识库搭建ing 3484

ROS(七)之动作编程:action文件

文章目录一、动作编程1.概念2.3.4.二、代码1.定义action文件 一、动作编程 1.概念 动作(action): 一种问答通信机制 带有连续反馈 可以在任务过程中中止运行 基于ROS的消息机制实现 Action的接口 goal:发布任务目标 cancel:请求取消任务 status:通知客户端当前服务器的状态 feedback:周期反馈任务运行的监控数据 result:向客户端发...

sandalphon4869的博客 3249

移动端实战指南:深入理解 & 接入 IAB OMSDK

OMSDK(OpenMeasurementSDK)是IABTechLab推出的标准化测量工具,用于统一移动端/原生App广告的可见性和验证流程。其核心包括Native库(采集设备数据)和OMID JavaScript层(实现通信),通过标准化接口让开发者只需接入一套SDK即可兼容多个测量厂商,减少冲突和性能损耗。v1.4版本强化了对CTV和原生App场景的支持,而v1.5新增了画中画检测等功能。集成流程需通过IAB技术实验室注册下载,并遵循严格的命名空间规则。测试阶段需嵌入验证脚本并通过指定工具验证

帅次的博客 1203

练习ROS动作编程

-----

LX567567的博客 482

innovus:给channel加soft blockage

dbGet [dbGet top.fplan.pBlkgs.name finishfp_place_blkg_* -p].boxes就可以获得channel坐标。意思是给30um以下的channel加soft blk,至于channel的坐标,通过抓取该soft blk去获取,比较容易。工具自己加入的placement blockage命名上叫finishfp_place_blkg_*ICC2中有给channel自动加soft blockage的命令,相应的innovus也有类似的命令,我们可以使用。

m0_61544122的博客 493

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

ROS学习记录:动作编程

动作编程:客户端发送一个运动目标,模拟机器人运动到目标位置的过程,包含服务端和客户端的代码实现,要求带有实时位置反馈 一、在工作空间下创建功能包 cd ~/catkin_ws/src catkin_create_pkg learn_action std_msgs rospy roscpp actionlib actionlib.msgs 二、在创建的功能包learn_action的src目录下创...

白码王子小张的博客 876

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

ros 动作编程

动作编程 在learning_communication 目录下创建一个文件夹action,在srv里面再创建一个 AddTwolnts.srv文件,在这个文件里面写入以下代码 # Define the goal uint32 dishwasher_id # Specify which dishwasher we want to use --- # Define the result uin...

qinshanjy的博客 1035

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

InTheHand.Net.Personal+BlueTooth4,蓝牙开发

项目中有蓝牙开发的必备dll,现在网上相关的文档博客不少,有的说的多有的说少,但是却很少有这两个dll,分享一下。

ROS动作编程之控制小乌龟运动到目标位置

通过动作编程由client发布目标位置,然后控制小乌龟运动到目标位置,并实时反馈位置信息 1、TurtleMove_server.cpp文件 /*    此程序通过通过动作编程实现由client发布一个目标位置    然后控制Turtle运动到目标位置的过程 */ #include <ros/ros.h> #include <actionlib/server/simp...

Young的博客 7088

ROS | 动作通信的编程实现

ROS | 动作通信的编程实现1. 创建功能包2. 节点编程与动作消息定义2.1 案例说明2.2 动作消息的定义2.3 创建.cpp文件2.4 动作客户端编程2.5 action服务器编程3. 配置与编译3.1 在CMaKeLists.txt中添加编译选项3.2 在package.xml中添加功能包依赖3.3 编译文件4. 话题可视化 1. 创建功能包 在ROS工作空间ROS_ws的src文件夹目录下创建一个功能包,命名为action_task。 2. 节点编程与动作消息定义 2.1 案例说明 客户端发送

Rome was not built in a day. 1877
上一篇: 初识线性回归(Excel-Python实现)
下一篇: ROS分布式通信
Error (12007)
博客等级 码龄6年 271粉丝 52原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址