WF4.0 基础篇 (五) 数据的传递 Variable变量

本文介绍如何在WF4.0中定义和使用变量,包括变量的基本概念、定义方式及通过Assign活动进行赋值的方法。

 

本节主要介绍如何在WF4.0中使用变量,以及为变量赋值

 

本文例子下载:

http://files.cnblogs.com/foundation/VariablesSample.rar

http://files.cnblogs.com/foundation/AssignSample.rar

数据的传递 Variable变量

Variable变量

System.Activities.Variable 类

类名

System.Activities.Statements.

文件

System.Activities.dll

结构说明

继承 System.Activities.LocationReference

是一个 abstract 类

功能说明

 

 

变量说明

1.只有具备[Variables]属性的Activity才可以定义变量

 

2.[Variables] 的数据类型为System.Collections.ObjectModel.Collection<System.Activities.Variable>

 

 

 

3.在定义变量的[Activity]内部的[Activity]可以访问变量,在定义变量的[Activity]外部的[Activity]无法访问变量

 

其XAML结构如下

<Activity ... >

<Sequence DisplayName="mySequenceA" ... >

<Sequence.Variables>

<Variable x:TypeArguments="x:String" Name="v1" />

<Variable x:TypeArguments="x:String" Name="v2" />

</Sequence.Variables>

<sap:WorkflowViewStateService.ViewState>

<scg3:Dictionary x:TypeArguments="x:String, x:Object">

<x:Boolean x:Key="IsExpanded">True</x:Boolean>

</scg3:Dictionary>

</sap:WorkflowViewStateService.ViewState>

<Sequence DisplayName="mySequenceB" sap:VirtualizedContainerService.HintSize="200,100">

<Sequence.Variables>

<Variable x:TypeArguments="x:String" Name="v3" />

<Variable x:TypeArguments="x:String" Name="v4" />

</Sequence.Variables>

<sap:WorkflowViewStateService.ViewState>

<scg3:Dictionary x:TypeArguments="x:String, x:Object">

<x:Boolean x:Key="IsExpanded">True</x:Boolean>

<x:Boolean x:Key="IsPinned">False</x:Boolean>

</scg3:Dictionary>

</sap:WorkflowViewStateService.ViewState>

</Sequence>

</Sequence>

</Activity>

 

为具备[Variables]属性的Activity添加变量

 

使用变量

可在Activity的表达式类型属性里直接赋予变量名

 

运行结果

 

Assign 赋值

类名

System.Activities.Statements.Assign

文件

System.Activities.dll

结构说明

继承 CodeActivity

是一个 sealed类

定义了OutArgument 类型[To属性] 与 InArgument 类型[Value属性]

override 了 [Excute方法] 与 [CacheMetadata方法]

功能说明

1.可以对流程内定义的参数,变量赋值

2.两个参数的类型必须是兼容的。 兼容性在运行时验证

    To 属性 : 要赋值的对象

    Value 属性 : 要赋的值,可以使用表达式方式

 

 

例子:

1.在Sequence容器中定义一个变量[v1],类型为"String",默认值为"wxwinter"

2.用WriteLine在屏幕上输出变量[v1]的值

3.用[Assign]将变量[v1]赋值为"wxd"

4.用WriteLine在屏幕上输出变量[v1]的值

5.用[Assign]将变量[v1]赋值为"lzm"

6.用WriteLine在屏幕上输出变量[v1]的值

 

 

运行结果

https://spart.readthedocs.io/en/latest/这文献中有介绍运动学和动力学建模,我现在有函数dae,被用于gpops-Ⅱ求解p-自适应伪谱法内容如下:function dae = SC_3DoF_Robot_Dae(sol) % ------------------------------------------------------------- % % 微分方程 % ------------------------------------------------------------- % % Use robot as the global variable global robot; % Get the number of joint angles nJ = robot.n_q;% nj=3,关节数 % Gets structure parameters % t = sol.time; x = sol.state; u = sol.control; % p = sol.parameter; % 获取时间序列的长度 num_timesteps = size(x, 1); % 初始化导数结果矩阵 q0dot = zeros(num_timesteps, 4); % 四元数的导数 r0dot = zeros(num_timesteps, 3); % 位移的导数 w0dot = zeros(num_timesteps, 3); % 角速度的导数 v0dot = zeros(num_timesteps, 3); % 线速度的导数 qmdot = zeros(num_timesteps, nJ); % 关节角度的导数 umdot = zeros(num_timesteps, nJ); % 关节角速度的导数 % Traverse the state at each point in time for t = 1:num_timesteps % --------------------------------------------- % % 分解当前时间点的状态变量 % --------------------------------------------- % q0 = x(t, 1:4); % 基座四元数表示 (四元数: 1x4) r0 = x(t, 5:7); % 基座位移 (3x1) w0 = x(t, 8:10); % 基座角速度 (3x1) v0 = x(t, 11:13); % 基座线速度 (3x1) qm = x(t, 14:14+nJ-1); % 关节角度 (nJx1) um = x(t, 14+nJ:14+2*nJ-1); % 关节角速度 (nJx1) % The angular velocity and linear velocity of the base are combined into the base velocity u0 u0 = [w0, v0]; % Normalized quaternion q0(1:4) = q0(1:4) / norm(q0(1:4)); % % 将四元数转化为旋转矩阵 R为旋转矩阵 R0 = quat_DCM(q0); % There is no external influence wF0 = zeros(6, 1); % The external force of the base 6 degrees of freedom is 0 wFm = zeros(6, robot.n_links_joints); % The linkage six degrees of freedom external force is 0 % Controllable input - force/momen
最新发布
03-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值