个传播行为,4个隔离级别,
Spring事务的传播行为和隔离级别
[
transaction
behavior and
isolated level
]
事务的传播行为和隔离级别
[
transaction
behavior and
isolated level
]
Spring中事务的定义:
一、Propagation
:
key属性确定代理应该给哪个方法增加事务行为。这样的属性最重要的部份是传播行为。有以下选项可供使用:
PROPAGATION_REQUIRED
-
-
支持当前事务,如果当前没有事务,就新建一个事务。这是最常见的选择。
PROPAGATION_SUPPORTS
-
-
支持当前事务,如果当前没有事务,就以非事务方式执行。
PROPAGATION_MANDATORY
-
-
支持当前事务,如果当前没有事务,就抛出异常。
PROPAGATION_REQUIRES_NEW
-
-
新建事务,如果当前存在事务,把当前事务挂起。
PROPAGATION_NOT_SUPPORTED
-
-
以非事务方式执行操作,如果当前存在事务,就把当前事务挂起。
PROPAGATION_NEVER
-
-
以非事务方式执行,如果当前存在事务,则抛出异常。
很多人看到事务的传播行为属性都不甚了解,我昨晚看了j2ee without
ejb的时候,看到这里也不了解,甚至重新翻起数据库系统的教材书,但是也没有找到对这个的分析。今天搜索,找到一篇极好的分析文章,虽然这篇文章是重点分析PROPAGATION_REQUIRED
和 PROPAGATION_REQUIRED_NESTED的
解惑 spring 嵌套事务 /** * @date 2006-11-24 * @note 转载自http://www.javaeye.com/topic/35907?page=1 */ * * * * * * * * TransactionDefinition 接口定义* * * * * * * * * * * * * * * * * * * /** * Support a current transaction, create a new one if none exists. * Analogous to EJB transaction attribute of the same name. * This is typically the default setting of a transaction definition. */ int PROPAGATION_REQUIRED = 0; /** * Support a current transaction, execute non-transactionally if none exists. * Analogous to EJB transaction attribute of the same name. * Note: For transaction managers with transaction synchronization, * PROPAGATION_SUPPORTS is slightly different from no transaction at all, * as it defines a transaction scopp that synchronization will apply for. * As a consequence, the same resources (JDBC Connection, Hibernate Session, etc) * will be shared for the entire specified scope. Note that this depends on * the actual synchronization configuration of the transaction manager. * @see org.springframework.transaction.support.AbstractPlatformTransactionManager#setTransactionSynchronization */ int PROPAGATION_SUPPORTS = 1; /** * Support a current transaction, throw an exception if none exists. * Analogous to EJB transaction attribute of the same name. */ int PROPAGATION_MANDATORY = 2; /** * Create a new transaction, suspend the current transaction if one exists. * Analogous to EJB transaction attribute of the same name. * Note: Actual transaction suspension will not work on out-of-the-box * on all transaction managers. This in particular applies to JtaTransactionManager, * which requires the javax.transaction.TransactionManager to be * made available it to it (which is server-specific in standard J2EE). * @see org.springframework.transaction.jta.JtaTransactionManager#setTransactionManager */ int PROPAGATION_REQUIRES_NEW = 3; /** * Execute non-transactionally, suspend the current transaction if one exists. * Analogous to EJB transaction attribute of the same name. * Note: Actual transaction suspension will not work on out-of-the-box * on all transaction managers. This in particular applies to JtaTransactionManager, * which requires the javax.transaction.TransactionManager to be * made available it to it (which is server-specific in standard J2EE). * @see org.springframework.transaction.jta.JtaTransactionManager#setTransactionManager */ int PROPAGATION_NOT_SUPPORTED = 4; /** * Execute non-transactionally, throw an exception if a transaction exists. * Analogous to EJB transaction attribute of the same name. */ int PROPAGATION_NEVER = 5; /** * Execute within a nested transaction if a current transaction exists, * behave like PROPAGATION_REQUIRED else. There is no analogous feature in EJB. * Note: Actual creation of a nested transaction will only work on specific * transaction managers. Out of the box, this only applies to the JDBC * DataSourceTransactionManager when working on a JDBC 3.0 driver. * Some JTA providers might support nested transactions as well. * @see org.springframework.jdbc.datasource.DataSourceTransactionManager */ int PROPAGATION_NESTED = 6;
在这篇文章里,他用两个嵌套的例子辅助分析,我这里直接引用了。
ServiceA {
/**
* 事务属性配置为 PROPAGATION_REQUIRED
*/
@Transactional(propagation=Propagation.REQUIRED)
void methodA() {
ServiceB.methodB();
}
}
ServiceB {
/**
* 事务属性配置为 PROPAGATION_REQUIRED
*/
@Transactional(propagation=Propagation.REQUIRED)
void methodB() {
}
}
1:
PROPAGATION_REQUIRED
加入当前正要执行的事务不在另外一个事务里,那么就起一个新的事务
比如说,ServiceB.
methodB的事务级别定义为PROPAGATION_REQUIRED,
那么由于执行ServiceA.
methodA的时候,
ServiceA.
methodA已经起了事务,这时调用ServiceB.
methodB,ServiceB.
methodB看到自己已经运行在ServiceA.
methodA
的事务内部,就不再起新的事务。而假如ServiceA.
methodA运行的时候发现自己没有在事务中,他就会为自己分配一个事务。
这样,在ServiceA.
methodA或者在ServiceB.
methodB内的任何地方出现异常,事务都会被回滚。即使ServiceB.
methodB的事务已经被
提交,但是ServiceA.
methodA在接下来fail要回滚,ServiceB.
methodB也要回滚
2: PROPAGATION_SUPPORTS
如果当前在事务中,即以事务的形式运行,如果当前不再一个事务中,那么就以非事务的形式运行
3:
PROPAGATION_MANDATORY
必须在一个事务中运行。也就是说,他只能被一个父事务调用。否则,他就要抛出异常
4:
PROPAGATION_REQUIRES_NEW
这个就比较绕口了。 比如我们设计ServiceA.
methodA的事务级别为PROPAGATION_REQUIRED,ServiceB.
methodB的事务级别为PROPAGATION_REQUIRES_NEW,
那么当执行到ServiceB.
methodB的时候,ServiceA.
methodA所在的事务就会挂起,ServiceB.
methodB会起一个新的事务,等待ServiceB.
methodB的事务完成以后,
他才继续执行。他与PROPAGATION_REQUIRED
的事务区别在于事务的回滚程度了。因为ServiceB.
methodB是新起一个事务,那么就是存在
两个不同的事务。如果ServiceB.
methodB已经提交,那么ServiceA.
methodA失败回滚,ServiceB.
methodB是不会回滚的。如果ServiceB.
methodB失败回滚,
如果他抛出的异常被ServiceA.
methodA捕获,ServiceA.
methodA事务仍然可能提交。
5:
PROPAGATION_NOT_SUPPORTED
当前不支持事务。比如ServiceA.
methodA的事务级别是PROPAGATION_REQUIRED ,而ServiceB.
methodB的事务级别是PROPAGATION_NOT_SUPPORTED ,
那么当执行到ServiceB.
methodB时,ServiceA.
methodA的事务挂起,而他以非事务的状态运行完,再继续ServiceA.
methodA的事务。
6: PROPAGATION_NEVER
不能在事务中运行。假设ServiceA.
methodA的事务级别是PROPAGATION_REQUIRED, 而ServiceB.
methodB的事务级别是PROPAGATION_NEVER ,
那么ServiceB.
methodB就要抛出异常了。
7:
PROPAGATION_NESTED
理解Nested的关键是savepoint。他与PROPAGATION_REQUIRES_NEW的区别是,PROPAGATION_REQUIRES_NEW另起一个事务,将会与他的父事务相互独立,
而Nested的事务和他的父事务是相依的,他的提交是要等和他的父事务一块提交的。也就是说,如果父事务最后回滚,他也要回滚的。
而Nested事务的好处是他有一个savepoint。
ServiceA {
/**
* 事务属性配置为 PROPAGATION_REQUIRED
*/
@Transactional(propagation=Propagation.REQUIRED)
void methodA() {
try {
//savepoint
@Transactional(propagation=Propagation.NESTED)
ServiceB.methodB(); //PROPAGATION_NESTED 级别
} catch (SomeException) {
// 执行其他业务, 如 ServiceC.methodC();
}
}
}
也就是说ServiceB.
methodB失败回滚,那么ServiceA.
methodA也会回滚到savepoint点上,ServiceA.
methodA可以选择另外一个分支,比如
ServiceC.
methodC,继续执行,来尝试完成自己的事务。
但是这个事务并没有在EJB标准中定义。
二、Isolation Level
(
事务隔离等级)
:
1、Serializable:最严格的级别,事务串行执行,资源消耗最大;
2、REPEATABLE
READ:保证了一个事务不会修改已经由另一个事务读取但未提交(回滚)的数据。避免了“脏读取”和“不可重复读取”的情况,但是带来了更多的性能损失。
3、READ COMMITTED:
大多数主流数据库的默认事务等级,保证了一个事务不会读到另一个并行事务已修改但未提交的数据,避免了“脏读取”。该级别适用于大多数系统。
4、Read Uncommitted:保证了读取过程中不会读取到非法数据。隔离级别在于处理多事务的并发问题。
我们知道并行可以提高数据库的吞吐量和效率,但是并不是所有的并发事务都可以并发运行,这需要查看数据库教材的可串行化条件判断了。
这里就不阐述。
我们首先说并发中可能发生的3中不讨人喜欢的事情
1: Dirty
reads
-
-
读脏数据。也就是说,比如事务A的未提交(还依然缓存)的数据被事务B读走,如果事务A失败回滚,会导致事务B所读取的的数据是错误的。
2: non-
repeatable reads
-
-
数据不可重复读。比如事务A中两处读取数据-
total-
的值。在第一读的时候,total是100,然后事务B就把total的数据改成200,事务A再读一次,结果就发现,total竟然就变成200了,造成事务A数据混乱。
3: phantom reads
-
-
幻象读数据,这个和non-
repeatable reads相似,也是同一个事务中多次读不一致的问题。但是non-
repeatable
reads的不一致是因为他所要取的数据集被改变了(比如total的数据),但是phantom
reads所要读的数据的不一致却不是他所要读的数据集改变,而是他的条件数据集改变。比如Select account.
id
where
account.
name
=
"ppgogo*"
,
第一次读去了6个符合条件的id,第二次读取的时候,由于事务b把一个帐号的名字由"dd"
改成"ppgogo1"
,结果取出来了7个数据。 Dirty
reads non-
repeatable reads phantom reads
Serializable
不会 不会 不会
REPEATABLE READ
不会 不会 会
READ
COMMITTED 不会 会 会
Read
Uncommitted 会 会 会
三、readOnly
事务属性中的readOnly标志表示对应的事务应该被最优化为只读事务。
这是一个最优化提示。在一些情况下,一些事务策略能够起到显著的最优化效果,例如在使用Object/
Relational映射工具(如:Hibernate或TopLink)时避免dirty
checking(试图“刷新”)。
四、Timeout
在事务属性中还有定义“timeout”值的选项,指定事务超时为几秒。在JTA中,这将被简单地传递到J2EE服务器的事务协调程序,并据此得到相应的解释。
转载自:http://blog.chinaunix.net/u1/55983/showart_2091761.html
附:@interface Transactional
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.transaction.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.transaction.TransactionDefinition;
/**
* Describes transaction attributes on a method or class.
*
* <p>This annotation type is generally directly comparable to Spring's
* {@link org.springframework.transaction.interceptor.RuleBasedTransactionAttribute}
* class, and in fact {@link AnnotationTransactionAttributeSource} will directly
* convert the data to the latter class, so that Spring's transaction support code
* does not have to know about annotations. If no rules are relevant to the exception,
* it will be treated like
* {@link org.springframework.transaction.interceptor.DefaultTransactionAttribute}
* (rolling back on runtime exceptions).
*
* <p>For specific information about the semantics of this annotation's attributes,
* consider the {@link org.springframework.transaction.TransactionDefinition} and
* {@link org.springframework.transaction.interceptor.TransactionAttribute} javadocs.
*
* @author Colin Sampaleanu
* @author Juergen Hoeller
* @since 1.2
* @see org.springframework.transaction.interceptor.TransactionAttribute
* @see org.springframework.transaction.interceptor.DefaultTransactionAttribute
* @see org.springframework.transaction.interceptor.RuleBasedTransactionAttribute
*/
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface Transactional {
/**
* A qualifier value for the specified transaction.
* <p>May be used to determine the target transaction manager,
* matching the qualifier value (or the bean name) of a specific
* {@link org.springframework.transaction.PlatformTransactionManager}
* bean definition.
*/
String value() default "";
/**
* The transaction propagation type.
* Defaults to {@link Propagation#REQUIRED}.
* @see org.springframework.transaction.interceptor.TransactionAttribute#getPropagationBehavior()
*/
Propagation propagation() default Propagation.REQUIRED;
/**
* The transaction isolation level.
* Defaults to {@link Isolation#DEFAULT}.
* @see org.springframework.transaction.interceptor.TransactionAttribute#getIsolationLevel()
*/
Isolation isolation() default Isolation.DEFAULT;
/**
* The timeout for this transaction.
* Defaults to the default timeout of the underlying transaction system.
* @see org.springframework.transaction.interceptor.TransactionAttribute#getTimeout()
*/
int timeout() default TransactionDefinition.TIMEOUT_DEFAULT;
/**
* <code>true</code> if the transaction is read-only.
* Defaults to <code>false</code>.
* <p>This just serves as a hint for the actual transaction subsystem;
* it will <i>not necessarily</i> cause failure of write access attempts.
* A transaction manager which cannot interpret the read-only hint will
* <i>not</i> throw an exception when asked for a read-only transaction.
* @see org.springframework.transaction.interceptor.TransactionAttribute#isReadOnly()
*/
boolean readOnly() default false;
/**
* Defines zero (0) or more exception {@link Class classes}, which must be a
* subclass of {@link Throwable}, indicating which exception types must cause
* a transaction rollback.
* <p>This is the preferred way to construct a rollback rule, matching the
* exception class and subclasses.
* <p>Similar to {@link org.springframework.transaction.interceptor.RollbackRuleAttribute#RollbackRuleAttribute(Class clazz)}
*/
Class<? extends Throwable>[] rollbackFor() default {};
/**
* Defines zero (0) or more exception names (for exceptions which must be a
* subclass of {@link Throwable}), indicating which exception types must cause
* a transaction rollback.
* <p>This can be a substring, with no wildcard support at present.
* A value of "ServletException" would match
* {@link javax.servlet.ServletException} and subclasses, for example.
* <p><b>NB: </b>Consider carefully how specific the pattern is, and whether
* to include package information (which isn't mandatory). For example,
* "Exception" will match nearly anything, and will probably hide other rules.
* "java.lang.Exception" would be correct if "Exception" was meant to define
* a rule for all checked exceptions. With more unusual {@link Exception}
* names such as "BaseBusinessException" there is no need to use a FQN.
* <p>Similar to {@link org.springframework.transaction.interceptor.RollbackRuleAttribute#RollbackRuleAttribute(String exceptionName)}
*/
String[] rollbackForClassName() default {};
/**
* Defines zero (0) or more exception {@link Class Classes}, which must be a
* subclass of {@link Throwable}, indicating which exception types must <b>not</b>
* cause a transaction rollback.
* <p>This is the preferred way to construct a rollback rule, matching the
* exception class and subclasses.
* <p>Similar to {@link org.springframework.transaction.interceptor.NoRollbackRuleAttribute#NoRollbackRuleAttribute(Class clazz)}
*/
Class<? extends Throwable>[] noRollbackFor() default {};
/**
* Defines zero (0) or more exception names (for exceptions which must be a
* subclass of {@link Throwable}) indicating which exception types must <b>not</b>
* cause a transaction rollback.
* <p>See the description of {@link #rollbackForClassName()} for more info on how
* the specified names are treated.
* <p>Similar to {@link org.springframework.transaction.interceptor.NoRollbackRuleAttribute#NoRollbackRuleAttribute(String exceptionName)}
*/
String[] noRollbackForClassName() default {};
}
enum Propagation:
/* * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.springframework.transaction.annotation; import org.springframework.transaction.TransactionDefinition; /** * Enumeration that represents transaction propagation behaviors for use * with the {@link Transactional} annotation, corresponding to the * {@link TransactionDefinition} interface. * * @author Colin Sampaleanu * @author Juergen Hoeller * @since 1.2 */ public enum Propagation { /** * Support a current transaction, create a new one if none exists. * Analogous to EJB transaction attribute of the same name. * <p>This is the default setting of a transaction annotation. */ REQUIRED(TransactionDefinition.PROPAGATION_REQUIRED), /** * Support a current transaction, execute non-transactionally if none exists. * Analogous to EJB transaction attribute of the same name. * <p>Note: For transaction managers with transaction synchronization, * PROPAGATION_SUPPORTS is slightly different from no transaction at all, * as it defines a transaction scope that synchronization will apply for. * As a consequence, the same resources (JDBC Connection, Hibernate Session, etc) * will be shared for the entire specified scope. Note that this depends on * the actual synchronization configuration of the transaction manager. * @see org.springframework.transaction.support.AbstractPlatformTransactionManager#setTransactionSynchronization */ SUPPORTS(TransactionDefinition.PROPAGATION_SUPPORTS), /** * Support a current transaction, throw an exception if none exists. * Analogous to EJB transaction attribute of the same name. */ MANDATORY(TransactionDefinition.PROPAGATION_MANDATORY), /** * Create a new transaction, suspend the current transaction if one exists. * Analogous to EJB transaction attribute of the same name. * <p>Note: Actual transaction suspension will not work on out-of-the-box * on all transaction managers. This in particular applies to JtaTransactionManager, * which requires the <code>javax.transaction.TransactionManager</code> to be * made available it to it (which is server-specific in standard J2EE). * @see org.springframework.transaction.jta.JtaTransactionManager#setTransactionManager */ REQUIRES_NEW(TransactionDefinition.PROPAGATION_REQUIRES_NEW), /** * Execute non-transactionally, suspend the current transaction if one exists. * Analogous to EJB transaction attribute of the same name. * <p>Note: Actual transaction suspension will not work on out-of-the-box * on all transaction managers. This in particular applies to JtaTransactionManager, * which requires the <code>javax.transaction.TransactionManager</code> to be * made available it to it (which is server-specific in standard J2EE). * @see org.springframework.transaction.jta.JtaTransactionManager#setTransactionManager */ NOT_SUPPORTED(TransactionDefinition.PROPAGATION_NOT_SUPPORTED), /** * Execute non-transactionally, throw an exception if a transaction exists. * Analogous to EJB transaction attribute of the same name. */ NEVER(TransactionDefinition.PROPAGATION_NEVER), /** * Execute within a nested transaction if a current transaction exists, * behave like PROPAGATION_REQUIRED else. There is no analogous feature in EJB. * <p>Note: Actual creation of a nested transaction will only work on specific * transaction managers. Out of the box, this only applies to the JDBC * DataSourceTransactionManager when working on a JDBC 3.0 driver. * Some JTA providers might support nested transactions as well. * @see org.springframework.jdbc.datasource.DataSourceTransactionManager */ NESTED(TransactionDefinition.PROPAGATION_NESTED); private final int value; Propagation(int value) { this.value = value; } public int value() { return this.value; } }
相关推荐
内容概要:本文详细介绍了基于西门子S7-200 PLC和组态王软件构建的八层电梯控制系统。首先阐述了系统的硬件配置,包括PLC的IO分配策略,如输入输出信号的具体分配及其重要性。接着深入探讨了梯形图编程逻辑,涵盖外呼信号处理、轿厢运动控制以及楼层判断等关键环节。随后讲解了组态王的画面设计,包括动画效果的实现方法,如楼层按钮绑定、轿厢移动动画和门开合效果等。最后分享了一些调试经验和注意事项,如模拟困人场景、防抖逻辑、接线艺术等。 适合人群:从事自动化控制领域的工程师和技术人员,尤其是对PLC编程和组态软件有一定基础的人群。 使用场景及目标:适用于需要设计和实施小型电梯控制系统的工程项目。主要目标是帮助读者掌握PLC编程技巧、组态画面设计方法以及系统联调经验,从而提高项目的成功率。 其他说明:文中提供了详细的代码片段和调试技巧,有助于读者更好地理解和应用相关知识点。此外,还强调了安全性和可靠性方面的考量,如急停按钮的正确接入和硬件互锁设计等。
内容概要:本文深入探讨了无人驾驶车辆使用动力学MPC(模型预测控制)算法进行蛇形线路径跟踪的技术细节。首先介绍了蛇形线的特点及其对无人驾驶车辆带来的挑战,随后详细讲解了动力学MPC算法的基础理论,包括车辆状态表示、运动方程建模以及控制输入的选择。接着重点阐述了如何通过定义合适的目标函数并加入适当的约束条件来优化MPC算法,使其能够高效地完成蛇形线路径跟踪任务。此外,文中还讨论了一些常见的错误做法和技术改进措施,如引入航向角误差补偿项、采用松弛变量处理约束条件等。最后,作者分享了多个实用的小技巧,例如预测时域内的速度适配和平滑处理、适当降低控制频率以提高跟踪精度等。 适合人群:对无人驾驶技术和控制算法感兴趣的科研人员、工程师及高校学生。 使用场景及目标:适用于研究无人驾驶车辆路径规划与控制领域的项目开发,旨在帮助读者掌握动力学MPC算法的具体应用方法,从而更好地解决实际工程问题。 其他说明:文章不仅提供了详细的理论推导和代码实现,还结合具体案例进行了充分的实验验证,确保所提出的解决方案具有较高的可行性和可靠性。
内容概要:本文详细介绍了BYVIN(比德文)电动四轮车控制器的技术细节,涵盖了硬件设计和软件实现两大部分。硬件方面,提供了PCB文件和PDF原理图,展示了电路板布局、元件位置及电路连接关系。软件方面,代码结构清晰,模块化设计良好,包括初始化、速度数据处理、PWM配置、故障保护机制等功能模块。文中还提到了一些独特的设计细节,如PWM死区补偿、故障分级处理、卡尔曼滤波估算电池电量等。此外,代码仓库中还包括了详细的注释和调试技巧,如CAN总线实时数据传输、硬件级关断+软件状态机联动等。 适合人群:具备一定嵌入式开发基础的研发人员,尤其是对STM32F4系列单片机和电动车辆控制系统感兴趣的工程师。 使用场景及目标:适用于希望深入了解电动四轮车控制器设计原理和技术实现的研究人员和开发者。目标是掌握电动四轮车控制器的硬件设计方法和软件编程技巧,提升实际项目开发能力。 其他说明:本文不仅提供了代码和技术细节,还分享了许多实战经验和设计思路,有助于读者更好地理解和应用这些技术。
内容概要:本文详细介绍了基于S7 300 PLC和组态王的车门包边机控制系统的设计与实现。主要内容涵盖I/O分配、梯形图编程、接线图设计以及组态王的画面构建。文中通过具体的实例展示了如何利用PLC实现车门包边机的精确控制,包括启动逻辑、电机与气缸控制逻辑等。此外,还讨论了接线图中的防干扰措施、梯形图中的特殊逻辑设计以及组态王中的动态效果实现方法。最终,通过合理的硬件配置和软件编程,实现了高效、稳定且直观的车门包边机控制系统。 适合人群:从事工业自动化领域的工程师和技术人员,尤其是熟悉PLC编程和组态软件使用的专业人士。 使用场景及目标:适用于汽车制造生产线中的车门包边机控制系统的开发与维护。目标是提高生产设备的自动化水平,增强系统的稳定性和可靠性,减少人工干预,提升生产效率。 其他说明:本文不仅提供了详细的理论讲解,还包括了许多实际操作中的经验和技巧,有助于读者更好地理解和应用相关技术。
基于C#实现的照片自动分拣程序+源码+项目文档,适合毕业设计、课程设计、项目开发。项目源码已经过严格测试,可以放心参考并在此基础上延申使用,详情见md文档 简单易用的照片自动分类工具,它能够自动读取照片的拍摄日期信息,并按照年月结构将照片整理到对应的文件夹中,帮助用户轻松管理大量照片文件。 主要功能 自动分类:根据照片的拍摄时间,自动将照片分类到对应的年月文件夹中 多格式支持:支持 JPG、JPEG、PNG、GIF 等常见图片格式 智能处理: 自动读取照片 EXIF 信息获取拍摄日期 当无法读取 EXIF 信息时,自动使用文件创建时间 智能处理文件重名冲突 高效处理: 采用并行处理技术,提高大量照片的处理速度 优化文件读取和移动操作,减少系统资源占用 自动调整并行任务数量,平衡系统负载
KUKA机器人相关文档
Tripple Farm:Match 3 Combination Game Complete Project 合成小镇三消Unity合成消除游戏项目游戏插件模版C# 支持Unity2020.3.4或更高 您知道像三合镇这样的著名益智游戏,并且您想制作一个自己的游戏。就是这样。这个包正好适合您。 这是一个完整的项目,您可以在零分钟内将其上传到 appstore 或 googleplay 商店。 基本规则: 3个或以上相同的道具可以匹配升级为新的道具。动物如果被困住,也可以合并。 羽毛: -移动(android/ios)就绪。 - 包含所有源代码。 -超过 12 座建筑/军团需要升级。 -三种特殊物品可以提供帮助。 - 三个不同的主题(场景和动物) -unity iap 支持 -Unity UI -广告位已准备好 -包含详细文档
内容概要:本文详细介绍了基于下垂控制的三相逆变器电压电流双闭环控制的仿真方法及其在MATLAB/Simulink和PLECS中的具体实现。首先解释了下垂控制的基本原理,即有功调频和无功调压,并给出了相应的数学表达式。随后讨论了电压环和电流环的设计与参数整定,强调了两者带宽的差异以及PI控制器的参数选择。文中还提到了一些常见的调试技巧,如锁相环的响应速度、LC滤波器的谐振点处理、死区时间设置等。此外,作者分享了一些实用的经验,如避免过度滤波、合理设置采样周期和下垂系数等。最后,通过突加负载测试展示了系统的动态响应性能。 适合人群:从事电力电子、微电网研究的技术人员,尤其是有一定MATLAB/Simulink和PLECS使用经验的研发人员。 使用场景及目标:适用于希望深入了解三相逆变器下垂控制机制的研究人员和技术人员,旨在帮助他们掌握电压电流双闭环控制的具体实现方法,提高仿真的准确性和效率。 其他说明:本文不仅提供了详细的理论讲解,还结合了大量的实战经验和调试技巧,有助于读者更好地理解和应用相关技术。
内容概要:本文详细记录了作者对EP100伺服驱动器进行的一系列优化和改进。主要内容包括:修复原厂代码中的多个致命Bug,如定时器配置冲突、PWM信号不触发、电流采样误差等问题;优化电机启动、增量编码器找零、串口通信、相序反转等功能;并对硬件进行了改进,如调整MOS管布局、优化滤波电容位置等。通过这些改动,显著提高了系统的稳定性、精度和可靠性。 适合人群:具有一定嵌入式系统开发经验的工程师,尤其是熟悉STM32单片机和伺服控制系统的技术人员。 使用场景及目标:适用于需要对现有伺服驱动器进行性能优化和技术改造的项目。主要目标是提高系统的稳定性和精度,解决原厂代码中存在的各种问题,确保伺服驱动器能够在高负载条件下正常工作。 其他说明:文中提供了详细的代码片段和硬件改进措施,帮助读者更好地理解和应用相关技术。同时,作者分享了许多实际操作中的经验和技巧,对于从事类似项目的工程师具有很高的参考价值。
内容概要:本文详细介绍了光储直流微电网中利用Simulink进行仿真建模的方法,重点探讨了光伏系统的最大功率点跟踪(MPPT)控制以及蓄电池和超级电容的功率分配策略。文中提供了具体的MATLAB代码实现,包括MPPT控制算法和低通滤波器(LPF)用于功率分配的具体参数设置。此外,还讨论了仿真过程中遇到的问题及解决方案,如避免系统震荡、优化直流母线电压控制等。 适合人群:从事电力电子、新能源发电、微电网研究的技术人员和研究人员,尤其适用于有一定Simulink使用经验和MATLAB编程基础的人群。 使用场景及目标:①理解和掌握光储直流微电网的工作原理;②学习如何使用Simulink搭建完整的光储并网系统仿真模型;③优化MPPT控制算法和功率分配策略,提高系统的稳定性和效率。 其他说明:文章强调了参数整定的重要性,并分享了许多实用的经验和技术细节,对于希望深入研究光储直流微电网仿真的读者非常有价值。
stm32 PWM学习专题附代码
2898702486frft2d.m
包括:源程序工程文件、Proteus仿真工程文件、配套技术手册等 1、采用51/52单片机作为主控芯片; 2、采用汇编语言编程; 3、采用8个DS18B20传感器检测8路温度; 4、采用数码管循环显示通道号及温度值; 5、采用74HC595驱动显示;
内容概要:本文详细介绍了如何使用MATLAB GUI构建一个功能丰富的图像处理工具箱。该工具箱涵盖了图像的基本操作如灰度化、边缘检测、直方图均衡化等功能,并提供了实时对比和多种算法选择。文中不仅展示了具体的代码实现,还深入探讨了每种算法背后的原理和技术细节。例如,灰度化采用NTSC标准权重进行RGB到灰度的转换,边缘检测使用Sobel和Canny算子,直方图均衡化则强调了在HSV空间处理V通道的重要性。此外,作者分享了许多实践经验,包括性能优化技巧、异常处理以及不同算法在特定场景下的表现。 适合人群:具有一定MATLAB基础的开发者、图像处理领域的研究人员及爱好者。 使用场景及目标:① 学习MATLAB GUI编程及其在图像处理中的应用;② 掌握常见的图像处理算法及其优化方法;③ 构建自己的图像处理工具箱,用于科研或工程项目。 其他说明:文章配有详细的代码示例和理论解释,有助于读者更好地理解和掌握相关知识点。同时,文中提到的一些优化技巧和注意事项对于提高程序性能和稳定性非常有用。
内容概要:本文详细介绍了如何使用Simulink搭建BLDC无刷直流电机的转速电流双闭环控制系统。首先,文章解释了电流环和转速环的设计要点,包括PI控制器参数的选择、电流采样的频率设置以及PWM生成模块的配置。接着,作者分享了一些实用的仿真技巧,如使用简化版卡尔曼滤波代替传统测速发电机、加入PWM载波频率的随机抖动以减少谐振噪声、以及针对常见错误的解决方案。此外,文中还提供了具体的MATLAB代码片段,帮助读者更好地理解和实现各个模块的功能。最后,文章强调了仿真过程中需要注意的关键点,如参数整定、故障注入模块的应用和仿真加速方法。 适合人群:从事电机控制研究的技术人员、电气工程专业的学生以及对BLDC电机仿真感兴趣的工程师。 使用场景及目标:适用于需要进行BLDC电机控制算法开发和测试的研究项目,旨在提高仿真效率并确保最终控制效果的稳定性。通过学习本文,读者能够掌握双闭环控制系统的搭建方法及其优化技巧。 其他说明:文中提供的代码和技巧均经过实际验证,具有较高的实用性。建议读者在实践中结合自身需求进行适当调整。
内容概要:本文详细介绍了微电网并离网下垂控制Simulink模型的设计与实现,特别针对MATLAB 2018版本。模型涵盖分布式电源、负荷、储能装置及控制模块,通过下垂控制实现微电网在并网和离网模式间的平稳切换与稳定运行。文中提供了详细的代码示例,解释了下垂控制的关键参数设定及其对系统稳定性的影响。此外,还讨论了并离网切换逻辑、锁相环设计、滤波器参数选择等问题,并给出了仿真技巧和性能评估方法。 适合人群:从事电力系统研究、微电网控制技术研发的专业人士和技术爱好者。 使用场景及目标:①研究微电网并离网控制策略;②验证下垂控制算法的有效性;③优化微电网系统的动态响应和稳定性;④测试不同工况下的系统性能。 其他说明:该模型在MATLAB 2018中表现出色,能够作为可靠的研究工具,帮助研究人员深入了解并离网下垂控制的原理与应用。
内容概要:本文详细介绍了FPGA处理周期信号的两种主要方法:状态机和计数器。首先,通过对两个具体版本的Verilog代码进行解析,展示了不同的处理逻辑和技术细节。版本一采用简单的移位操作,适用于信号放大的场景;版本二引入计数器,能够实现周期信号的累加,适用于统计数据的应用。接着,文章深入探讨了状态机和计数器两种实现方式的特点与优劣。状态机版本虽然调试友好,但在高频信号处理时可能存在时序问题;计数器版本资源占用少,适合高频或占空比不固定的场景。此外,还提供了具体的性能实测对比,如资源占用、最大频率和抗干扰能力等方面的数据。最后,给出了实际项目的选型建议,强调了根据具体需求选择合适的实现方案的重要性。 适合人群:具有一定FPGA开发经验的研发人员,尤其是从事数字电路设计、嵌入式系统开发的技术人员。 使用场景及目标:①帮助开发者理解FPGA处理周期信号的基本原理;②提供两种常见实现方案的具体代码示例及解析;③指导开发者根据实际项目需求选择最合适的实现方式。 其他说明:文中不仅提供了理论分析,还结合了实际案例,分享了作者在调试过程中遇到的问题及解决方案,有助于读者更好地理解和应用相关技术。
内容概要:本文详细介绍了电力市场节点出清电价(LMP)的概念及其计算方法,特别关注了节点边际电价的形成机制。作者通过Python代码实现了多个简化模型,展示了不同约束条件下(如线路容量、爬坡率等)对电价的影响。首先,文章通过一个三节点系统的例子,讲解了如何利用线性规划工具linprog进行出清计算,并探讨了线路阻塞对电价的影响。接着,进一步讨论了机组运行约束(如爬坡率、启停成本等)对LMP的具体影响。此外,还提到了一些实际工程中的特殊情况,如网络损耗和逆向调度效应。最后,给出了几个实操建议,帮助初学者更好地理解和应用这些概念。 适合人群:对电力市场感兴趣的初学者,尤其是希望深入了解节点电价计算原理的技术人员。 使用场景及目标:适用于想要通过编程方式理解电力市场运作机制的学习者;目标是让读者能够独立构建并分析简单的电力市场出清模型,从而掌握LMP的基本概念和应用场景。 其他说明:文中提供了详细的代码示例,便于读者跟随练习。同时强调了理解LMP对于电力市场参与者的重要性,以及它在资源配置中的作用。
内容概要:本文详细介绍了并联型有源电力滤波器(APF)在dq0坐标系下的谐波检测方法及其在Matlab/Simulink中的仿真实现。首先,通过Park变换将三相电流转换为旋转坐标系下的直流分量,再利用低通滤波器提取谐波分量。文中讨论了锁相环(PLL)、滤波器设计、电流跟踪策略以及补偿电流生成等关键技术,并提供了具体的代码实现和调试经验。此外,文章还分享了一些常见问题的解决方案,如电网电压跌落保护、死区补偿、THD优化等。 适合人群:从事电力电子、电力系统自动化领域的工程师和技术人员,尤其是对有源电力滤波器和电力谐波检测感兴趣的读者。 使用场景及目标:适用于希望深入了解APF工作原理及其实现方法的研究人员和工程师。通过学习本文,读者能够掌握如何在Simulink中构建APF仿真模型,进行谐波检测和补偿实验,从而提高电力系统的稳定性和效率。 其他说明:配套的参考文献和视频演示可以帮助读者更好地理解和实践相关技术。建议读者在实践中不断调整参数,以适应不同的应用场景。
KUKA机器人相关文档