




已阅读5页,还剩24页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
附录 A 倒立摆的平衡器 导言 此计划的目标是建立和实施一个倒立摆的平衡器,在垂直两维平面,使用比例积分微分( PID )的反馈控制。 倒立摆的平衡是一个无线电控制汽车改装,加入有机玻璃平台和倒立摆与自由旋转枢轴。电气组成部分,平衡器,汇集了计算的硬件( Atmel 的 mega32 微控制器) ,一投入倾角传感器(美国数字光学轴角编码器) ,和一个输出电机驱动器(美国国家半导体 lmd18200 H 桥)到一个单一的委员会,其唯一的目的是为自主控制的议案,汽车,以保持钟摆从下降。 机械 学院与航空航天工程的反馈控 制系统,当然在康奈尔大学,我们的愿望是要整合的知识,稳定不稳定的系统使用反馈控制( mae478 ) ,快速,灵活的计算能力,微控制器( ece476 ),和使用真实世界的工程工具和预算的限制,强加给我们的项目经理。结果是一种简单,廉价,及游艺设备,完成了我们预定的目标。 高层次设计 : 机源自反馈控制系统( mae478 ) ,当然,我们都是目前就读英寸,我们要尝试在一个项目的地方,我们可以落实反馈控制器与微控制器。问题是什么来控制。之后做一些研究,我们发现了斯坦福大学 ee281 项目由杰弗里班布里 奇。这种 “ 自我平衡的机器人 ” 项目,试图设计一个足机器人平衡本身使用的反馈控制与 Atmel mega163 微控制器。班布里奇企图平衡杆直接相连的两个轮子。他很快就加入了第三轮的支持和枢轴后,两个车轮的设计创造了不想要的旋转运动约纵轴。此外,班布里奇用倾角传感器测量机器人的角度。不过,倾斜传感器被证明是不准确的,由于结合机器人的水平加速度和 ARM 的引力 freefall 。 基本结构的反馈控制系统是如下图所示。该倾角传感器读减去参考的角度,以产生错误。这个错误是用来计算电机控制参数,使用 PID 控制算法(下文讨论) 。电机控制,然后发送到设备上。我们决定继续我们的反馈控制系统的 SISO (单输入单输出) ,而不是的 MIMO (多输入多输出)为简单起见,以帮助我们的黑箱建模。参考的角度是唯一的输入该系统,和反馈控制使用的错误的角度,从范围和计算电动机输出。 我们有限的机械工程能力,随着短期的时间内完成项目,最惠国待遇,使用一种预制的汽车。 1 4 轮车的经验,不会转动的议案,班布里奇在他所遇到的项目。 RadioShack 公司的广泛的选择玩具的无线电控制车,使 我们的甄选过程中十分容易。一旦一个稳定的车辆与快速反应的特点被发现和修改,以举行一次倒立摆,搜索转而寻找一个可靠的,高分辨率的角度传感装置。两个最可行的选择是一种基于 MEMS 加速度计或光学编码器。经初步测试,模拟加速度无法执行,以及为数字编码器。因此, 1024 赫兹革命(心肺复苏术)光学轴角编码器由美国数字成为我们的角度传感器。这是一个巨大的进步超过了倾斜传感器,由于编码没有受到影响,所带来的影响的严重性,或汽车的加速度。 该 Atmel 的 mega32 微控制器使用,而非该 mega163 由于其优越的速度,为外 部中断采样的编码数据,并更加多才多艺计时器选项。初步黑箱测试的汽车的直流电动机的能力,给了我们一个好主意的汽车的性能。不同的驾驶情况观察,包括单方向的驾驶执照和振荡的议案。整理后,电机控制,我们提出的测试传感器。光学编码器的输入信号,很快就转化为一个错误的角度引用从最初计数的价值。 最后设计阶段,是比例积分微分( PID )的控制器与角误差,以汽车的速度和方向(见方程下文) 。比例任期(一)适用于电压,以汽车比例错误。这个值影响了车的反应时间 ;更高的比例来说,速度更快汽车的回应不惜牺牲系统的稳定性。积分任 期(二)将正确的任何稳态误差会出现因任何反应迟缓由电动+ 噪音 倾角传感器 机动 控制 + MCU PID 控制 设备 + 错误 摆角 + + + 机。积分控制将给予汽车一点点额外的 “ 推 ” ,以确保正确的追踪的参考角度。不过,较高的积分控制任期将创造振荡是要么无法或可能投掷系统的不稳定。最后,衍生金融工具的任期(三)是用来理顺的变化,误差随着时间的推移。这个名词,通常可以理顺振荡的车辆在牺牲慢的反应。微调这三个变量,根据系统的行为将允许汽车,以平衡倒立摆。 ni t t ne r r o rne r r o rCte r r o rBne r r o rA 1 )1()()( 程序 和 硬件设计 硬件 设计 所需的硬件倒立摆的平衡器,可以很容易被分成 2 子系统:机械和电气。 机械工 业: 我们的首要目标是迅速取得设备的能力正向和反向的议案,与快速的过渡和快速加速。缺乏知识的机械车设计和能力,以齿轮马达正确足够的转矩动议的购物车,我们迅速通过的想法使用的无线电控制汽车,作为我们的基地。测试后的各种钢筋混凝土车从 RadioShack 公司,我们找到了车,似乎有表现,我们需要的,随着稳固的基地,便很容易让一个钟摆仪器安装。 汽车的直流电动机是设在方便的位置,在车尾下方的汽车。 6 节 AA 电池被制造商的定义电源 ;因此,我们知道我们的电力供应将不得不供应至少 9伏特。六个机管局的安装与休息,在过去 的接触电池匣和一个电流表(一套来衡量目前的)在一系列的措施,目前所得出的装置。与汽车没有在负载情况下(即没有在地板上与车轮在空气中) ,设备提请 300 毫安。我们估计,在负载情况下,汽车至少需要 600-800 毫安运行与足够的电源。通过搜查后,许多电源供应器,在菲利普斯大会堂数字实验室,我们发现一个 12V 的 1500 毫安电力供应从RadioShack 公司,这将是足够多的为我们的需要。这是后来发现荷载作用下,快速转型期的议案,该装置实际上是提请大约 900 毫安从供应。 选择后,我们的设备,我们下一步的任务是建立一个 倒立摆对汽车。一树脂玻璃钢板是用来建立一个平台上,重视钟摆(见图片 9 ) 。这板是有担保,以汽车与 4 螺栓在每一个角落的车辆。在该中心的平台,两个括号内放置与内部的角度谈到对方,连一个 6.3 “ 螺丝钉,并用来创造的支点钟摆(见图 3 ) 。最后, 38 条 “ 棒( 3 / 8 ” 直径)是拧成的中心顶端括弧内为创造我们的钟摆。这似乎是奇怪,有一个 38 “ 杆以上的 12个 ” 汽车。杆的高度,按照设计,不过,行为在我们的青睐,作为规模较大的转动惯量(及更高的质心) ,实际上拖慢杆的初步运动。新增加的重量,以车辆将健全有害的影 响,汽车的悬架系统。因此, 4弹性条带,放在靠近汽车在以锁定的冲击,在一个压缩的立场。 与钟摆会议上顶端支架,螺丝署理作为一个契机,我们下一步的任务是能够探测到的角度和方向,钟摆的倾斜。我们的第一选择是一个基于 MEMS 加速度 电子设备 产品 -adxl202e 。不过,初步检验证明,该加速度计的模拟信号不会为我们提供了该决议,我们需要的角度来检测。数位输出的无铅表面贴装 adxl202e被停用,与印刷电路板,我们用来挂载。因此,我们拒绝向美斯处,那里我们可以借用 1024cpr (赫兹革命)光学轴角编码器从 mae478 的反馈实验室。 而不是使用编码器的轴作为支点,我们决定使用办法,将付诸表决的最低金额应力对微妙的一件设备。编码器被放置在同向平行钟摆的括号内。高度编码器的轴是不结盟与枢纽,有效地创造一个假想线从枢轴,以编码器的轴。最后,一个 PIN 是连接到轴的编码器,塑胶铁包裹,并连接到摆的支架。托架有一个 0.096 “ 钻孔以上的契机,例如,该引脚将紧密配合,没有滑倒 ;因此,当钟摆动议,该编码器的轴旋转(见图 3 ,图 3 和图 4 ) 。 电气: 一旦不稳定,摆组装和安装在汽车,电气线路要设计的接受信息,从光学编码器 ,处理信息,然后控制车辆在正向和反向的议案。我们并不需要任何无线电控制电路或转折的能力,为我们的设计 ;因此,汽车的马达线的其余部分隔开制造商的电路由刈割电线,导致汽车。应用潜力,汽车,导致会造成电机的自旋在一个方向,虽然扭转了极性对线索将导致直流电动机,以针在相反的方向。控制汽车的正向和反向的议案,我们需要一个简单的四开关装置(见图 1 )这将确保保护,以免在短期内的直流电源,即是开关 1 和第 4或第 2和第 3不可能封闭在同一时间内。经营电机在一个方向,只要关闭开关 1 和第 3款 ;逆向运作,开放交换机 1和第 3条和关闭开 关 2和 4 。停止电机完全,只需打开所有开关。 而非身体落实每个开关作为一个晶体管,美国国家半导体 lmd18200t H 桥使用。这方便, 11 引脚封装,可接受多达 55v 供电电压及可提供高达 3A 条输出电流。该设备包含 4 -开关安装需要为我们的电机控制,随着保护二极管和电路,以确保有是从来没有在短期内从供应至地面。连接后,供应(引脚 6 )和地面(引脚 7 ) ,只有 3的投入,控制运作的汽车。休息位(引脚 4 )是用来有效地短期的输出终端连接到电动机。没有一个电位差的全国汽车线索,设备不运作。高突破位执行此功能 ;低打 破位将允许目前流经汽车。方向的汽车是确定的方向位(引脚 3 ) 。当方向是高,输出 1 (引脚 2 )将源的同时,输出 2 (引脚10 )将下沉,反之亦然为低的方向位。最后,速度,汽车是由脉宽调制( PWM )信号引脚 5的 H 桥。速度是成正比的脉冲宽度在此输入 ;越高,占空比,更高的速度运动。此外,为了增加业绩, 0.01 F 的电容器放在从每个输出其相应的 Bootstrap PIN 和 100 F 的旁路电容供应(汽车之间的供应和地面) ,以吸纳循环电流的电感负载,因为每制造商的建议。如果没有这个 100 F 的电容 器,汽车的行为是非常呆滞。汽车是连接到 H 桥通过一个 2针头(见图 2 , J3中) 。 2 更多 2 针标题被用于调试目的。首先是放置在平行的 2引脚电机头(见图 2 , j2 )这种电压全国汽车可轻易加以衡量。第二头被放置在一系列之间的 H 桥的输出 2 (引脚 10 )和相应的汽车导致的措施,目前经历的发动机。正常运作下,跳线应放在全国,这头(见图 2 , J1 中) 一旦硬件驱动电机被确定,我们提出建立一个独立的委员会,例如,所有的控制将是该车辆。使用六的 “ X 2 -1/16 ” 效能董事会,我们开始奠定了必要的组件为 Atmel 的 mega32 单片机的运行没有沙头角 - 500 发展局。我们的初步委员会使用一个单一的 12V 电源提供动力都 MCU 和汽车。德克萨斯仪器 ua7805ckcs电压调节器是用来把一个 5V 的规管,以微控制器。 1 0.1 F 的电容器至地面被放置在对方的监管,以阻止任何噪音对线从重置的 MCU 。一个 16 MHz 的晶体放在全国 xtal1 (引脚 13 )和 xtal2 (引脚 12 ) ,与 27 酚醛电容器至地面,在每个管脚。最后,一个 2x3 的标题被用来允许在系统编程的 mega32 (见图 2 ) 。该 vcc 线在 ISP 的标题是残 疾人士。连接 ISP 的 5V 的路线,从而使在 vcc 从沙头角 - 500 编程期间,到单片机的规管 vcc 线,直接来自 12V 电源供应,可能会导致两用品战斗对方,如果他们双方就在同一时间内。因此,我们决定最好的选择将是禁用的 ISP 的 vcc 路线,始终使用我们的 12V 电源线。不过,这需要董事会来提供动力,当外部编程。该( ISP 引脚 1 ) ,( ISP 引脚 3 ) ,( ISP 引脚 4 ) , ( ISP 引脚 5 ) ,( ISP 引脚 6 )线连接到单片机的引脚 7 , 8 , 6 , 9 ,和 11 ,分别完成在系统编程设置。最后,我们 专门 portd.4 , d.5 ,和草 6对微控制器为 3电机控制信号的 ;突破,脉宽调制,和方向。 加入的光学编码器电路的最后一步所需的硬件,以平衡摆。输出通道 A 和 B从编码器(引脚 3和 5分别)被用来触发外部中断对 引脚 2 , 3的 分 离 。编码器是连接到电路使用 1x5 针头,其中发表 5 五,地面,和渠道 A 和 B线,由单片机编码。 (见图 2 , j4 )至于对电力,似乎只有一件事阻止我们的电路在这一点上。 一旦我们的软件,准备进行测试,问题与硬件几乎立即浮现 ;最激烈正在噪音问题 orignating 从马达。因为只有一,电力 供应使用的( 12V 的,以汽车和规管,以 5V 的为微控制器) ,噪音时创建的汽车将改变方向,将旅行下来,地面线和重置的 MCU ,其中有一个绝对的最高评级二 毫安直流电流对 vcc 和接地引脚。身体分开,地面线(但所有领导到同一供应地面)并没有帮助。这是进一步看到测试时使用沙头角 - 500 和一个单独的 H 桥对原型面包板电路。由于噪音不断重置的 MCU 和唯一的线连接沙头角 - 500 ,以 H桥是地面,一个孤立的地面计划已被用作。因此,我们从一个单一的供应,设计,以两用品, 5V 的电源,以微控制器和编码器,和 12V 的严格 的动力马达。 完全孤立汽车电路,不仅构成 H 桥,从微控制器,三 4n35 光电隔离器是用来分离三线微控制器(打破,脉宽调制,和方向)从他们的 H桥对口单位。这个装置使用了红外线二极管,把光敏三极管上下车。当电流通过二极管,晶体管,基本上是一个封闭的开关,抛空至地面,在我们的应用。当光电二极管是小康,晶体管是一个开放的电路和输出是高, 12V 的,虽然 1 卡 拉电阻。由于 12V 电源供应是不规范和通常的产出约 14v ,两个主导的在一系列被放在之间的 12V电源和下拉线,使电压约为 11v 。这样做是因为 H 桥的绝对最大输入评级 12V的对销 3,4 ,和 5 。光电隔离器是一个逆变装置,因此,而非输入一个信号,参照地面,我们用 5V 的作为投入和引用它的每三个信号。一旦信号倒置通过光电隔离器的晶体管,正确的信号传递给 H桥,与例外,一个合乎逻辑的高是 12V的,而不是 5V的。由于光电隔离器使用 图像 接收红外信号,是没有物理连接之间的微控制器的电路, H桥。因此,无噪音,从汽车可以到微控制器。 加入三个光电隔离器所作的电路板布局非常紧凑。因此,只有一个电源开关是使用。开关控制的 MCU 的权力,而 12V 的电机功率是总是连接。这是值得一提的注意,如果 没有输入信号来在向 H 桥,电机不运行。这两个电源供应器连接到董事会与两针的标题。完全分离的理由之间的电机和微控制器解决所有的噪音问题,并允许用于高速电机的过渡没有单片机复位。 程序设计 -有三个主要职能,在最后的控制器代码:传感器(编码器)输入, P ID控制计算,和电机控制输出。该马达控制器代码( 测试电力 )的书面第一。该直流电动机的控制,通过一个 H 桥和三信号控制打破( /关闭) ,速度和方向的汽车。这些信号输出从插针,港口总署署长微控制器,以针对 H 桥。速度,汽车是由一个脉宽调制( PWM )信号。目前交付 给马达是成正比的脉宽,从而百分比免税周期决定的速度,汽车。因为我们不知道在什么频率输出的 PWM 信号,以及如何敏锐地免税周期会影响速度,汽车,我们希望写一电动机驱动器的代码可能会改变双方的 PWM 信号的频率和占空比期与安心。为此,我们挑选港口署署长微控制器。该 控制器 ( pd5 )针对港口 d可以作为一种外部输出定时器 1的输出比较模式。 “ 快速 PWM 模式 ” 运作,定时器 1 提供了一个高频率 PWM 波形的一代。柜台为定时器 1 是递增的从零发展到顶端,然后重新启动从零。该 控制器 是集( PIN 是一套高 5V 的)时,柜台达到顶端 的价值。该 控制器 是清除( PIN是低 于 0 V )时,有一个比较匹配之间的柜位和 ocr1a 登记。因此,顶端计数器的值(随时钟分频器的价值)决定了频率和 ocr1a 登记值确定责任周期的 PWM信号被输出(见图 4 ) 。在 “ 快速 PWM 模式 ” 的三定时器就 mega32 ,只有定时器 1 允许设置顶端的价值在 icr1 登记,而不是固定值。这使得变频调速 PWM信号。 ocr1a 和 icr1 选民登记册,都是 16 位正式选民登记册,因此,价值观,不得不订定使用两个写操作,与高字节始终书面前低字节。 测试频率和占空比期间的 PWM 信号驱动直流 电动机,测试代码(无效 速度测试 )是书面,其中利用按钮就沙头角 - 500 发展局。两个按钮被定义为增加或减少价值的登记,而在效果增加了还是减少了频率的 PWM 信号。两个按钮被定义为增加或减少价值的登记,在效果增加了还是减少了免税周期的 PWM 信号。当改变这些登记的价值观,代码已检查的价值少于价值。如果价值,成为大于 1值,比较符合之间的柜台绝不会发生,因为定时器 1计数器将重置为零。一个按钮的定义是要切换的方向信号和另一个按钮的定义是要切换突破的信号。使用此执行,我们发现设置 icr1 价值 300 是足够的控制电机。这是相当 于有 208.3hz PWM 信号( ( 16e6hz/256 ) / 300 = 208.3hz ) 。 接下来,我们制定了一个函数(无效 电力控制 )在汽车测试代码,我们在那里计划 接受 输出的 PID 控制器。的 PID 计算,将使用的角度看,钟摆计算速度上,以推动购物车。标志的错误将确定的方向运动车。的功能 ,电力控制 ,接受输出的PID 计算,并列出的速度(占空比期) ,方向(注册的 PID 控制输出),和会期的时间,其中去在这个速度。之后,这些参数都设置,打破是关闭的(一套低) ,并要等到计时器运行。当计时器运行,休息是打开 的(高)和功能的目的。这是很重要的注意,时间计时器决定率在哪个 PID 的计算是演出。后的功能结束后,代码可以追溯到的 PID 计算(见图 5 )凡误差的角度来看,是用来计算新的速度和方向。使用这项新功能,我们在测试速度有多快车可以振荡。试验证明,车是有能力改变方向,速度不够快,性格行为,我们怀疑这将是需要平衡的一个不稳定的钟摆。 之后,我们决定编码器会是一个更好的传感器测量倾斜超过 1加速度计,我们写了传感器控制器代码。编码转换实时轴角,速度和方向,分为两个频道的 TTL方波产出与指数脉冲。该决议是 1024cpr (赫 兹革命),或 1024 周期每 360 机械程度的轴旋转。方波输出的是对双方的渠道,一旦每个周期。当轴旋转在一个顺时针旋转,频道 b 导致渠道的一个 6.3 的周期,当旋转轴是在一个轮换,导致频道 1频道 B的 6.3 的周期。该指数也输出脉冲,一旦每个周期时,双方频道 A和频道 B 的低。 (见图 6 )保持追踪,其中的两个频道,云高,首先,我们可以跟踪的旋转轴。通过测量时间之间的上升 /下降边缘之间的 CH 。 A 和 B 的方波输出,我们可以计算的速度,轴的自转。不过,我们不关心速度,轴的倾斜,所以这是没有计算。在另一方面,我们关心的角度轴, 可维持的轨道上来计数每个周期,该编码器的产出。 获得单片机的过程中的所有数据输出从编码器演变成一场棘手的任务。 1024 赫兹革命转化为一千零二十四分之三百六十 = 0.35 机械度,每个周期。每 0.35度,编码器输出的两方波和一个索引脉冲。第一次尝试在试图计数,每个编码周期与单片机利用外部中断引脚对港口 D 类(草 2 )连接到脉冲输出的编码。外部中断服务程序是安装程序引发的对每一个下降沿该指数的输出。根据规格,编码器,渠道之一,将继续高企于最 300ns 后的下降沿 着 脉冲。因为它需时约 35周期进入的 ISR ( 2e - 6或 2 s 时) ,电压对频道 A 和 B是检查在开始的 ISR 。如果渠道之一是高,另一种是低,大家都知道的方向旋转,并可以递增 /递减计数器。执行此 工作,以及时 快速旋转,而不是缓慢的一个方向,当缓慢旋转,而不是快速在其他的方向。这可能是由于这一事实,即 ISR 公司所引发的对一下降和该频道的水平正在发生变化太快相比的 ISR 的时间。 经过痛苦的尝试调试执行此,我们决定尝试另一种执行两个外部中断( int0/d.2和 int1/d.3 )连接到两个通道输出的编码。外部中断服务例程被触发对每一个合乎逻辑的变化 。期间,国际专线分销渠道, 0th 位的全球未签名的烧焦变 传感器频道 将切换。期间,国际专线分销渠道 B区,第一位的 传感器频道 变量将切换。之后,每比特切换在每个 ISR 公司,价值的 传感器频道 变量将进行检查。如果该值的 传感器频道 相当于 1 ( 0x01 )在国际专用线路分销渠道,它将意味着 ch.a 是领导 ch.b ,从而反顺时针旋转的轴。如果该值的 传感器频道 相当于 2 ( 0x02 )在国际专用线路分销渠道 b ,这将意味着 ch.b 是领导 ch.a ,从而顺时针旋转的轴。每一个周期的顺时针旋转,反变, 传感器 ,是由一递增,并为每个周期的反顺时针旋转, 传感器 变量 递增 。本实施工作,像一个魅力的各种转速在两个方向。该 传感器 变量被宣布为一个未签名的 量 ,是因为我们知道一旦钟摆是安装在汽车,一系列的钟摆会少于 90 度(三百六十分之一千 二十四 * 90 = 256 ) 。该 传感器 是初始化在 128 ,使柜台可以指望高达 45 度,在两个方向。 一旦传感器的输入和电动机输出功率为代码进行了测试,独立,两个逻辑被合并和测试第一没有 PID 的计算( 控制 ) 。此代码是用来驱动汽车与手册的旋转编码器轴。在重启该计划,汽车是不与任何驱动电压。当轴旋转,为超 过 15 度,在一个方向,电机驱动,在一个方向。如果轴是带回原来的立场,汽车被截停。如果轴旋转,为超过 15 度,在其他方向,电机驱动,在相反方向。使用此程式码,我们保证,该传感器的输入和电动机输出的逻辑正在共同努力。 实施 PID 控制的计算是相当简单的( 平衡 ) 。比例(金伯利进程) ,积分(安) ,和 驱动 (科威特第纳尔)常数的定义是在开始的代码。值得注意的是,三角洲吨的价值观,在 PID 控制方程的吸收到这些常数。在 PID 控制 ( )函数,误差的角度看,是计算方式的差异 传感器 价值和 内部传感器 价值。在重启该计划, 传感器 初始化向 内部传感器 的价值和不断更新通过外部中断从编码器。这个错误,可以正面或负面的价值,然后用来计算 比例 ,积分,和衍生产品的条款。变数投浮动,为这些计算,因为常数可十进制的价值观。这三个条款是补充说,迹象的总和确定的方向,然后其绝对值是采取。这个新的计算值是速度,汽车,或的免税周期的 PWM 信号。这个值是检查对 电力最大 变数,是改变它的价值如果超过该值。这是为了确保免税周期的 PWM 信号从来没有超过预定的阈值(最多100 ) 。新的计算值,然后转嫁到 电力控制 () 。 流动的代码是在图 5 。在为了防 止汽车行驶在高速在一个方向时,钟摆完全下降到一方,安全性的功能( 安全检测 ( ) )实施,在每年年底的 PID 的计算周期。该 安全检测 功能有两个 安全 检查功能。第一功能检查的角度看,钟摆倾斜( 传感器 ) ,如果超过大约 40 度,从参考点,那么我们假设车没有机会平衡钟摆再次站和汽车的运作。第二个特征检查,如果车的举动上述预定的速度( 安全速度 )在一方向,在一段时间内( 安全监控器 ) 。这部分的安全功能,是要确保安全,并不完全依赖于角度读的钟摆从编码器。钟摆可以初始化在任何角度,使汽车可以经营高速即使单片机没有注册的角 度来看,钟摆有下降到一方。 结果设计的 PID 常数的测定通过系统的试验和错误。最初,积分和衍生产品的条款被设为零和的比例来说,是逐步增加,直到系统到不稳定的。一旦我们知道的最高比例来说,我们说,衍生金融工具来说,顺利的振动车。整体来说,仍然维持在零,因为振荡所带来的积分,任期造成平衡器表现不佳。 我们运行平衡器,由出发与钟摆平衡。设置所有的初始条件为零,允许编码器初始化后复位并创建一个参考角度。轻踏向上方的不稳定钟摆是所有这一切都是需要启动平衡的过程。该平衡器,迅速调整自己,以收回错误的角 度。钟摆成功完成 5-7 复苏时期的平均之前,电动机 /车的特点抑制快速反应需要收回的角度来看。初步证明,平衡的问题,倒立摆的平衡是可以解决的,但我国机械的限制,即穷人的电动机 /汽车性能(齿轮火车延误和软车轮的延误,与楼,造成了延误,该系统如下图所示) ,让我们从最终的壮举无限的平衡。 只要有一个坚持以安装程序,任何人都可以经营倒立摆的平衡器。程序如下: 1 )连接 5V 和 12V 电源线,以正确的插针,电路板。 2 )与两间电力供应富裕,平衡摆在车内。 3 )打开该 12V 电源,以功率电动机。 4 )打开该 5V 的供应,让初始化编码器。 5 )轻轻塔顶部的钟摆在任何方向。 看到一个视频的倒立摆的平衡 8 秒 该装置将不加干预与任何其它设备在房间内。只有高频率的设备,董事会是 16 兆赫的晶体,其领导都很短,与电容器至地面,为使所有的噪音极小。该 RF 电路的钢筋混凝土车是残疾人士,以便不干扰别人 的电路,更遑论我们自己。最后, PWM 信号是,在如此低的频率( 208.3 赫兹) ,并通过屏蔽电缆等,它不会辐射干扰别人的电路。注意:这些频率是不一样的那些被转交由学生与RF 项目。这几乎可以确保无干扰的项目之间。 金属棒用来作为一个钟摆可以创建一个危险的情况时,放置在移动的车辆中。因此,我们要求所有的观察员尊重一个 10 安全区。此外,在软件安全性的特点是实施申请休息,以汽车旅行,如果在一个方向以上的 2 秒没有改变方向,或如果 MCU 的进程,钟摆已下跌了超过 40 度。 什么我们会做不同的下一次 假设预算约束,是不会删除,我们会选择我们的赛车更仔细,和基地的决定,不仅回应,但也对机械设计和稳定(摇摆,暂停等) 。钟摆将得到加强,这种运动会受到限制向垂直面,没有旋转运动在钟摆,从而导致过剩的压力,编码和可能的错误的传感器读数。 反馈作用 倾角传感器 机动控制 + MCU PID 控制 设备 错误 摆角 + + ejwT 我们的整个设计过程中围绕着什么,我们学会了在 mae478 。在接近年底时该学期(和项目结束时) ,反馈的过程中开始从系统的分析,以控制器的设计与系统建模。采用的技术,我们学会了在接近年底时的学期在初步设计阶段(在中东的学期) ,将有一定创造了更强有 力的和精确的控制。能力模型的机械系统,使用灰盒分析(而不是黑箱分析) ,以及适用于预示着阴谋,并根轨迹设计创造的主导极点和零点使系统执行的方式,我们希望它也将有为更符合设计过程中,更多的知识,两国之间的课程可集成。最后,噪音问题是拖出约四天,而我们试图一蹴即我们原来的董事会。一分钟这个问题的观察和噪声对地面线来看,与示波器(显示非常高的噪声峰值 1 V 左右,在振幅) ,新董事会成员的设计(与孤立的 MCU 和汽车电路) ,应已通过。这将给予我们更多时间来微调 PID 控制器和可能,理顺了一些机械的瓶颈阻碍我们从较长的 平衡时间。 结论 整个项目,我们的一个忧虑是,汽车 /汽车 的 应是不够好,为我们的理想的任务,这是在事实属实。汽车无法平衡摆下去。延误,原产于都齿轮火车和软的轮胎(在接触地板) ,会造成延误,我们的系统,最终将它不稳定。延误作出不可能车赶上来,即使它的速度计算是正确的。不过,虽然我们无法平衡摆下去,有限的平衡,取得我们的主要目标,这是为了平衡摆。数额的时间,我们的平衡是出于我们一方面与我们目前的财政预算案,但原型清楚地表明,该项目可以做的,尽管与质量部分。我们有信心通过使用我们的电路和逻辑有更健全的 机械安装和明显调整 PID 参数,该系统可以实现最终的壮举无限期的平衡。 所有方面的设计我们自己。当然,思想都是从 mae478 的反馈控制实验室,但是他们没有执行,在同样的方式。此外,我们也要求外界的帮助,从人与机械工程背景,在我们的汽车 /摆设计。该守则的执行情况和电路的设计是我们自己。我们没有时间,不过,为了编造的立场,独立的董事会。因为我们需要一个原型,无论如何,性能董事会电路作了经过无数小时的焊接和调试两个不同的电路(单与双电源供应器) ,我们决定时间将可更好地分配在微调 PID 控制器,而不是比编 造一个董事会。 尽管在短期内的 一个月和力学所遇到的障碍,我们相当高兴的数额完成。该项目是一个持续的学习过程和结果,以其中一个最有价值的经验,在康奈尔大学。 附录 B Inverted Pendulum Balancer Introduction The goal of this project was to build and implement an inverted pendulum balancer, in the vertical two dimensional plane, using Proportional-Integral-Derivative (PID) feedback control. The inverted pendulum balancer is a radio controlled car modified by adding a plexiglass platform and an inverted pendulum with free rotating pivot. The electrical component of the balancer brings together computational hardware (Atmel Mega32 microcontroller), an input angle sensor (US Digital Optical Shaft Encoder), and an output motor driver (National Semiconductor LMD18200 H-Bridge) onto a single board whose sole purpose is to autonomously control the motion of the car in order to keep the pendulum from falling. Motivated by the School of Mechanical & Aerospace Engineerings Feedback Control Systems course at Cornell University, our desire was to integrate the knowledge of stabilizing an unstable system using feedback control (MAE478), the fast, flexible computing power of microcontrollers (ECE476), and the use of real-world engineering tools and budgetary constraints imposed on us by project managers. The result was a simple, cheap, and fun device that completed our desired goal. High Level Design Our motivation originated from Feedback Control Systems (MAE478), a course that we are both currently enrolled in. We wanted to attempt at a project where we could implement a feedback controller with a microcontroller. The question was what to control. After doing some research, we found a Stanford University EE281 project by Geoffrey Bainbridge. This Self-Balancing Robot project attempted to design a one-legged robot which balances itself using a feedback control with Atmel Mega163 microcontroller. Bainbridge attempted to balance a rod directly connected by two wheels. He quickly added a third supporting wheel and pivot after the two wheel design created unwanted rotational motion about the vertical axis. In addition, Bainbridge used a tilt sensor to measure the robots angle. However, the tilt sensor proved to be inaccurate due to the combination of the robots horizontal acceleration and the arms gravitational freefall. The basic structure of the feedback control system is shown below. The angle sensor reading is subtracted from the reference angle to produce the error. This error is used to calculate the motor control parameters using the PID algorithm (discussed below). The motor control is then sent to the device. We decided to keep our feedback control system SISO (single-input single-output) instead of MIMO (multi-input multi-output) for simplicity to help with our black-box modeling. The reference angle is the only input to the system, and the feedback control uses the error in angle from the reference and calculates a motor output. Our limited mechanical engineering ability, along with the short timeframe to complete the project, favored the use of a prefabricated car. A four-wheeled vehicle would not experience the rotational motion that Bainbridge encountered in his project. RadioShacks extensive selection of toy Radio Controlled cars made our selection process very easy. Once a stable vehicle with fast response characteristics was discovered and modified to hold an inverted pendulum, the search turned to finding a reliable, high-resolution angle sensing device. The two most viable choices were a + Noise Angle Sensor Motor control + MCU PID Control Device + Error Ref.Angle + + + MEMS accelerometer or optical encoder. After initial testing, the analog accelerometer could not perform as well as the digital encoder. Therefore, the 1024 cycles per revolution (CPR) optical shaft encoder from US Digital became our angle sensor. This is a vast improvement over the tilt sensor, as the encoder was not affected by the effects of gravity or the cars acceleration. The Atmel Mega32 microcontroller was used instead of the Mega163 due to its superior speed, for external interrupt sampling of the encoder data, and more versatile timer options. Initial black-box testing of the cars DC motor capabilities gave us a good idea of the cars performance. Different driving scenarios were observed, including single-direction driving and oscillatory motion. Upon finishing motor control, we moved on to testing the sensor. The optical encoders input signals were quickly converted to an error angle referenced from its initial count value. The final design stage was the Proportional-Integral-Derivative (PID) Controller to relate angle error to motor velocity and direction (see equation below). The proportional term (A) applied a voltage to the motor proportional to the error. This value affected the carts response time; higher the proportional term, the faster the cars response at the expense of system stability. The integral term (B) would correct any steady-state error that would occur due to any sluggish response by the motor. Integral control would give the motor a little extra “push” to ensure correct tracking of the reference angle. However, a higher integral control term would create oscillations that are either unrecoverable or may throw the system to instability. Finally, the derivative term (C) is used to smooth out changes in error over time. This term can usually smooth out the oscillations in the vehicle at the expense of slower response. Fine-tuning of these three variables according to system behavior will allow the car to balance the inverted pendulum. ni t tne r r o rne r r o rCte r r o rBne r r o rA1)1()()( Program & Hardware Design Hardware Deisgn - The hardware required for the inverted pendulum balancer can easily be separated into 2 subsystems: Mechanical and Electrical. Mechanical: Our first priority was to quickly acquire a device capable of forward and reverse motion, with quick transitions and fast acceleration. Lacking the knowledge of mechanical cart design and the ability to gear a motor correctly for sufficient torque to move the cart, we quickly adopted the idea of using a radio controlled car as our base. After testing various RC cars from RadioShack, we found a car that seemed to have the performance we required, along with a sturdy base which would easily allow for a pendulum apparatus to be installed. The vehicles DC motor was located in an easily accessible location at the rear underside of the car. Six AA batteries were the manufacturers defined power source; therefore, we knew our power supply would have to supply at least 9 volts. The six AAs were installed with a break in the last contact of the battery holder and an ammeter (DVM set to measure current) in series to measure the current drawn by the device. With the car not under load (i.e. not on the floor with the wheels in the air), the device drew 300 mA. We estimated that under load, the car would require at least 600-800 mA to run with enough power. After rummaging through many power supplies in the Phillips Hall Digital Lab, we found a 12v 1500mA power supply from RadioShack, which would be more than enough for our needs. It was later discovered that under load and quick transition in motion, the device actually drew approximately 900mA from the supply. Upon choosing our device, our next task was to build an inverted pendulum on the car. A Plexiglas plate was used to create a platform on which to attach the pendulum (see Image 9 ). This plate was secured to the car with 4 bolts at each corner of the vehicle. At the center of the platform, two brackets were placed with their inside angles touching each other, connected by a ” screw, and used to create the pivot of the pendulum (see Figure 3). Finally, a 38” rod (3/8” diameter) was screwed into the center of the top bracket to create our pendulum. It would seem strange to have a 38” rod above a 12” car. The rods height, by design, however, acts in our favor, as the larger moment of inertia (and higher center of mass) actually slow down the rods initial movement. The added weight to the vehicle would amplify the unwanted effects of the cars suspension system. Therefore, four elastic bands were placed around the car in order to lock the shocks in a compressed position. With the pendulum sitting on the top bracket, and the screw acting as a pivot, our next task was to be able to detect the angle and direction of the pendulums tilt. Our first option was a MEMS accelerometer from Analog Devices, ADXL202E. However, initial tests proved that the accelerometers analog signal would not provide us with the resolution that we required for angle detection. The digital output of the leadless, surface mount ADXL202E was disabled with the PCB that we used to mount it. Therefore, we turned to the MAE department, where we were able to borrow a 1024CPR (cycles per revolution) optical shaft encoder from MAE478s feedback lab. Rather than using the encoders shaft as the pivot, we decided to use an approach that would put the least amount of stress on the delicate piece of equipment. The encoder was placed in parallel with the pendulums bracket. The height of the encoders shaft was aligned with the pivot, effectively creating an imaginary line from the pivot to the encoders shaft. Finally, a pin was attached to the shaft of the encoder, with plastic tie-wraps, and connected to the pendulums bracket. The bracket had a 0.096” hole drilled above the pivot such that the pin would fit tightly, without slipping; therefore, when the pendulum moved, the encoders shaft rotated (See Figure 3, Image 3 and Image 4). Electrical: Once the unstable pendulum was assembled and mounted on the car, an electrical circuit had to be designed to accept information from the optical encoder, process the information, and then control the vehicle in forward and reverse motion. We did not need any radio control circuitry or turning capabilities for our design; therefore, the cars motor lines were separated from the rest of the manufacturers circuitry by clipping the wires leading to the motor. Applying a potential to the motor leads will cause the motor to spin in one direction, while reversing the polarity on the leads will cause the DC motor to pin in the opposite direction. To control the cars forward and reverse motion, we required a simple 4-switch device (See Figure 1) that would ensure protection against a short of the DC supply, that is, switches 1 and 4 or 2 and 3 could never be closed at the same time. To operate the motor in one direction, simply close switches 1 and 3; for reverse operation, open switches 1 and 3 and close switches 2 and 4. To stop the motor completely, simply open all switches. Rather than physically implementing each switch as a transistor, the National Semiconductor LMD18200T H-Bridge was used. This convenient, 11-pin package accepts up to 55V supply voltage and can deliver up to 3A of output current. The device contains the 4-switch setup required for our motor control, along with protection diodes and circuitry to ensure there is never a short from the supply to ground. Upon connecting the supply (pin 6) and ground (pin 7), only 3 inputs control the operation of the motor. A break bit (pin 4) is used to effectively short the output terminals connected to the motor. Without a potential difference across the motor leads, the device does not operate. A high break bit implements this feature; a low break bit will allow current to flow through the motor. The direction of the motor is determined by the direction bit (pin 3). When direction is high, output 1 (pin 2) will source while output 2 (pin 10) will sink, and vice versa for a low direction bit. Finally, the speed of the motor is determined by a pulse-width modulated (PWM) signal at pin 5 of the H-Bridge. Speed is directly proportional to the pulse width at this input; the higher the duty cycle, the higher the speed of the motor. In addition, for increased performance, 0.01 F capacitors were placed from each output to its corresponding bootstrap pin and a 100 F supply bypass capacitor (between motor supply and ground) to absorb the recirculating currents of the inductive loads, as per manufacturers recommendations. Without this 100 F capacitor, the motor behavior was very sluggish. The motor was connected to the H-Bridge through a 2-pin header (See Figure 2, J3). Two more 2-pin headers were used for debugging purposes. The first was placed in parallel to the 2-pin motor header(See Figure 2, J2) such that voltage across the motor could easily be measured. The second header was placed in series between the H-bridges output 2 (pin 10) and the corresponding motor lead to measure current going through the motor. Under normal operation, a jumper should be placed across this header (See Figure 2, J1) Once the hardware to drive the motor was identified, we moved to creating a stand-alone board such that all controls would be on the vehicle. Using a 6” x 2-1/16” Perf Board, we began laying out the necessary components for the Atmel Mega32 microcontroller to run without the STK-500 development board. Our initial board used a single 12V supply to provide power to both the MCU and the motor. A Texas Instrument UA7805CKCS voltage regulator was used to bring a regulated 5V to the MCU. A 0.1 F capacitor to ground was placed on each side of the regulator to block any noise on the line from resetting the MCU. A 16 MHz crystal was placed across XTAL1 (pin 13) and XTAL2 (pin 12), with a 27 pF capacitor to ground at each pin. Finally, a 2x3 header was used to allow for In-System Programming of the Mega32 (See Figure 2). The Vcc line in the ISP header was disabled. Connecting the ISPs 5V line, which brings in Vcc from the STK-500 during programming, to the MCUs regulated Vcc line, which comes directly from the 12V power supply, could lead to the two supplies fighting each other if they were both on at the same time. Therefore, we decided that the best option would be to disable the ISPs Vcc line, and always use our 12V supply line. This, however, required the board to be powered externally when programming. The MISO (ISP pin 1), SCK (ISP pin 3), MOSI (ISP pin 4), Reset (ISP pin 5), and Ground (ISP pin 6) lines were connected to the MCUs pins 7, 8, 6, 9, and 11 respectively to complete the In-System Programming setup. Finally, we dedicated PORTD.4, D.5, and D.6 on the MCU as the 3 motor control signals; Break, PWM, and Direction respectively. Adding the optical encoder to the circuit was the final step in the hardware required to balance the pendulum. Output channels A and B from the encoder (pins 3 and 5 respectively) were used to trigger external interrupts on PORTD.2, D.3 respectively. The encoder was connected to the circuit using a 1x5-pin header, which delivered +5V, ground, and Channels A and B lines from the MCU to the encoder. (See Figure 2, J4) Turning on the power seemed the only thing stopping our circuitry at this point. Once our software was ready to be tested, problems with the hardware surfaced almost immediately; the most drastic being noise issues orignating from the motor. Since only one power supply was used (12V to the motor and regulated to 5V for the MCU), noise created when the motor would change directions would travel down the ground line and reset the MCU, which had an absolute maximum rating of 200mA DC current on Vcc and ground pins. Physically separating the ground lines (but all leading to the same supply ground) did not help. This was further seen when tested using the STK-500 and a separate H-Bridge on a prototype bread-board circuit. Since noise kept resetting the MCU and the only line connecting the STK-500 to the H-bridge was ground, an isolated ground scheme had to be used. Therefore, we went from a single supply design to two supplies, 5V to power the MCU and the encoder, and 12V strictly to power the motor. To completely isolate the motor circuitry, which only consists of the H-Bridge, from the MCU, three 4N35 opto-isolators are used to detach the three MCU lines (break, PWM, and direction) from their H-Bridge counterparts. This device uses an infared diode to turn a phototransistor on and off. When current passes through the diode, the transistor is essentially a closed switch, shorting to ground in our application. When the photodiode is off, the transistor is an open circuit and the output is high, 12V though a 1 kOhm pull-up resistor. Since the 12V power supply is not regulated and usually outputs around 14V, two LEDs in series were placed between the 12V supply and the pull-up line to bring the voltage to approximately 11V. This was done because of the H-Bridges absolute maximum input rating of 12V on pins 3,4, and 5. The opto-isolator is an inverting device, therefore, rather than inputting a signal referenced to ground, we used 5V as the input and referenced it to each of the three signals. Once the signals are inverted through the opto-isolators transistor, the correct signals are passed to the H-bridge, with exception that a logical high is 12V rather than 5V. Since the opto-isolators use phototransistors that receive IR signals, there is no physical connection between the MCUs circuitry to the H-bridge. Therefore, no noise from the motor can go to the MCU. Adding the three opto-isolators made board layout very tight. Therefore, only one power switch is used. The switch controls MCU power, while 12V motor power is always connected. It is worthy to note that if no input signals come in to the H-Bridge, the motors do not run. Both power supplies are connected to the board with two-pin headers. The complete separation of grounds between the motor and MCU solved all noise issues, and allowed for high-speed motor transitions without MCU reset. Program Design - There are three main functions in the final controller code: sensor (encoder) input, PID control calculation, and motor control output. The motor controller code (test_motor.c) was written first. The DC motor is controlled via a H-Bridge and three signals control the break (on/off), speed, and direction of the motor. These signals were outputted from the pins on Port D of the microcontroller to pins on the H-bridge. The speed of the motor is controlled by a pulse-width-modulated (PWM) signal. The current delivered to the motor is proportional to the pulse-width, thus the percentage of duty-cycle period determines the speed of the motor. Since we did not know at what frequency to output the PWM signal and how sensitively the duty-cycle period would affect the speed of the motor, we wanted to write a motor driver code that could change both the PWM signal frequency and duty-cycle period with ease. For this reason, we picked Port D of the microcontroller. The OC1A (PD5) pin on port D can serve as an external output for Timer 1s Output Compare mode. The Fast PWM Mode operation on Timer 1 provides a high frequency PWM waveform generation. The counter for Timer 1 is incremented from zero to TOP then restarts from zero. The OC1A is set (pin is set high 5V) when the counter reaches the TOP value. The OC1A is cleared (pin is set low 0V) when there is a compare match between the counter and OCR1A register. Thus, the TOP value of the counter (along with the clock prescaler value) determines the frequency and the OCR1A register value determines the duty-cycle period of the PWM signal being outputted (See Figure 4). In Fast PWM Mode of the 3 timers on Mega32, only Timer 1 allowed to set the TOP value in ICR1 register instead of fixed values. This allowed for variable frequency of PWM signal. OCR1A and ICR1 registers are both 16-bit registers, thus the values had to be set using two write operations, with the high byte always written before the low byte. Two unsigned integer global varialbes, motor_PWM_period and motor_PWM_duty were declared. The function motor_updateDuty() set the high and low bytes of motor_PWM_duty to OCR1AH and OCR1AL respectively. The function motor_updatePeriod() set the high and low bytes of motor_PWM_period to ICR1H and ICR1L respectively. To test the frequency and the duty-cycle period of the PWM signal driving a DC motor, test code (void test_speed() was written which utilized the pushbuttons on the STK-500 development board. Two buttons were defined to increase or decrease the value of the ICR1 register, which in effect increased or decreased the frequency of the PWM signal. Two buttons were defined to increase or decrease the value of the OCR1A register, wihch in effect increased or decreased the duty-cycle period of the PWM signal. When changing these register values, the code had to check that the value of OCR1A was less than the value of ICR1. If the OCR1A value became larger than the ICR1 value, a compare match between the counter and OCR1A would never happen because the Timer 1 counter would reset to zero at ICR1 value. One button was defined to toggle the direction signal and another button was defined to toggle the break signal. Using this implementation, we found that setting the ICR1 value to 300 is sufficient for controlling the motor. This was equivalent to having 208.3Hz PWM signal (16e6Hz/256)/300=208.3Hz). Next, we developed a function (void motor_controller() in the motor test code, where we planned to accpet the output of the PID controller. The PID calculation would use the angle of the pendulum to calculate the speed at which to drive the cart. The sign of the error would determine the direction of the movement of the cart. The function, motor_controller(), accepts the output of the PID calculation and sets the speed (duty-cycle period), direction (sign of the PID output), and duration of time for which to go at this speed. After these parameters are set, the break is turned off (set low) and waits until the timer runs out. When the timer runs out, the break is turned on (set high) and the function ends. It is important to note that the duration of timer determines the rate at which the PID calculation is performed. After the function ends, the code goes back to the PID calculation (see Figure 5) where error of the angle is used to calculate the new speed and direction. Using this new function, we tested how quickly the cart can oscillate. The test proved that the cart was capable of changing directions fast enough, the character behavior that we suspected that would be required to balance an unstable pendulum. After we decided that an optical encoder would be a better sensor for measuring tilt than an accelerometer, we wrote the sensor controller code. The encoder converts real-time shaft angle, speed, and direction into two channel TTL square wave outputs with index pulse. The resolution is 1024CPR (cycles per revolution), or 1024 cycles per each 360 mechanical degrees of shaft rotation. The square wave is outputted on both channels once per cycle. When the shaft is rotating in a clockwise rotation, channel B leads channel A by of cycle period, and when the shaft is rotating in a counterclockwise rotation, channel A leads channel B by of cycle period. The index pulse also outputted once per cycle when both channel A and channel B are low. (See Figure 6) By keeping track of which one of the two channels goes high first, we can keep track of the rotation of the shaft. By measuring the timing between rising/falling edges between Ch. A and B square wave outputs, we can calculate the speed of the shafts rotation. We, however, do not care about the velocity of the shafts tilt so it was not calculated. On the other hand, we do care about the angle of the shaft, which can be kept track of by counting every cycle that the encoder outputs. To get the MCU to process all the data outputted from the encoder turned out to be a tricky task. 1024 cycles per revolution translates into 360/1024=0.35 mechanical degrees per cycle. For every 0.35 degrees, the encoder outputs two square waves and an index pulse. The first attempt at trying to count each encoder cycle with the MCU utilized the External Interrupt pin on Port D (D.2) connected to the index pulse output of the encoder. The external interrupt service routine was setup to be triggered on every falling edge of the index output. According to the specifications of the encoder, one of the channels would go high at most 300ns after the falling edge of the index pulse. Since it takes approximately 35 cycles to enter an ISR (2e-6 or 2s), the voltage on channel A and B are checked at the beginning of the ISR. If one of the channels is high and the other is low, we know the direction of the rotation and can increment/decrement the counter accordingly. With this implementation, the counter seemed to work well when rotated fast but not slow in one direction and when rotated slow but not fast in the other direction. This was probably due to the fact that the ISR was triggered on a falling edge and that the channels levels were changing too fast compared to the ISR duration. After painful attempt at debugging this implementation, we decided to try another implementation with two external interrupts (INT0/D.2 and INT1/D.3) connected to the two channel outputs of the encoder. The external interrupt service routines were triggered on every logical level change. During the ISR for Channel A, the 0th bit of the global unsigned char variable sensor_channel would be toggled. During the ISR for Channel B, the 1st bit of the sensor_channel variable would be toggled. After each bit toggle in each ISR, the value of the sensor_channel variable would be checked. If the value of sensor_channel equaled 1 (0x01) in the ISR for Channel A, it would imply Ch.A was leading Ch.B, thus counter-clockwise rotation of the shaft. If the value of the sensor_channel equaled 2 (0x02) in the ISR for Channel B, it would imply Ch.B was leading Ch.A, thus clockwise rotation of the shaft. For every cycle of clockwise rotation, the counter variable, sensor_index, was incremented by one and for every cycle of counter-clockwise rotation, the sensor_index variable was decremented by one. This implementation worked like a charm for various speed of rotation in both directions. The sensor_index variable was declared as an unsigned char, because we knew that once the pendulum was mounted on the car, the range of the pendulum would be less than 90 degrees (1024/360*90=256). The sensor_index was initialized at 128 so that the counter can count up to 45 degrees in both directions. Once the sensor input and the motor output codes were tested independently, the two logics were merged together and tested first without the PID calculations (controller.c). This code was used to drive the motor with manual rotation of the encoder shaft. At reset of the program, the motor is not driven with any voltage. When the shaft is rotated for more than 15 degrees in one direction, the motor was driven in one direction. If the shaft is brought back to the original position, the motor was stopped. If the shaft was rotated for more than 15 degress in the other direction, the motor was driven in the reverse direction. Using this code, we assured that the the sensor input and motor output logic were working together. Implementing the PID control calculation was pretty straight forward (balancer.c). The proportional (kp), integral (ki), and drivative (kd) constants were defined at the beginning of the code. It is worth noting that the delta t values in the PID equation are absorbed into these constants. In the pid_controller() function, the error of the angle is calculated by taking the difference between the sensor_index value and the init_sensor_index value. At reset of the program, the sensor_index is initialized to the init_sensor_index value and is constantly updated via external interrupts from the encoder. This error, which can be positive or negative value, is then used to calculate the prorportional, integral, and derivative terms. The variables are cast to float for these calculations because the constants could be decimal values. The three terms are added, the sign of the sum determines the direction, and then its absolute value is taken. This newly calculated value is the speed of the motor, or the percent of duty-cycle period of PWM signal. This value is checked against the max_motor_duty variable, and is changed to its value if it exceeds the value. This is to ensure that the duty-cycle period of the PWM signal never exceeds a predefined threshold (at most 100 percent). The new calculated value is then passed on to the motor_controller(). The flow of code is diagramed in Figure 5. In order to prevent the car from moving at high speed in one direction when the pendulum completely fell to one side, a safety feature (safty_check() was implemented at the end of each PID calculation cycle. The safety_check function has two saftely check features. The first feature checks the angle of the pendulum tilt (sensor_index) and if it exceeds approximately 40 degrees from the reference point, then we assume that the cart has no chance of balancing the pendulum again and stops the motor operation. The second feature checks if the cart moves above a predefined speed (safety_speed) in one direction for a period of time (safety_timer). This part of the safety feature is to ensure that the safety does not solely rely on the angle reading of the pendulum from the encoder. The pendulum can be initialized at any angle, so the motor can be operating at high speed even if the MCU does not register the angle of the pendulum as having fell to one side. Results of the Design The PID constants were determined through systematic trial and error. Initially, the integral and derivative terms were set to zero and the proportional term was gradually increased until the system went unstable. Once we knew the maximum proportional term, we added the derivative term to smooth the oscillation of the cart. The integral term remained at zero because the oscillation caused by the integral term caused the balancer to behave poorly. We run the balancer by starting off with the pendulum balanced. Setting all initial conditions to zero allows the encoder to initialize upon reset and create a reference angle. A light tap to the top of the unstable pendulum is all that is required to start the balancing process. The balancer quickly adjusts itself to recover the error in the angle. The pendulum successfully completes 5-7 recovery periods on average before the motor/car characteristics inhibit the quick response needed to recover the angle. The initial balancing proves that the problem of the inverted pendulum balancer can be solved, yet our mechanical limitations, namely poor motor/car performance (gear train slippage and soft-wheel slippage with the floor, which creates delay in the system as shown below), keep us from the ultimate feat of infinite balance. As long as one adheres to the setup procedures, anyone can operate the inverted pendulum balancer. The procedure is as follows: 1) Connect 5V and 12V power lines to correct pins on the circuit board. 2) With both power supplies off, balance the pendulum on the car. Delay block inideated by e(jwT) term Angle sensor Motor control + MCU PID Control Device Error Ref. Angle + + ejwT 3) Turn on the 12V supply to power motor. 4) Turn on the 5V supply to allow initialization of encoder. 5) Gently tap the top of the pendulum in any direction. See a video of the inverted
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 厂长职位聘任与劳动合同
- 美食街运营管理合作协议范本
- 乡下人家教学课件下载
- 2024-2025学年山东省聊城市高一下学期期中考政治试题及答案
- 高中一年级生物《基因指导蛋白质的合成(第1课时)》
- 建筑信息模型与人工智能融合技术考核试卷
- 化妆品中的酒精成分对皮肤屏障损害研究考核试卷
- 国际体育赛事规则与赛事转播限制考核试卷
- 高中英文试题及答案
- 智能家居纺织品应用分析考核试卷
- 摄影设备采购合同范例
- 2022 消化内科专业 药物临床试验GCP管理制度操作规程设计规范应急预案
- 三级安全教育试题(公司级、部门级、班组级)
- 整流器并联运行控制策略
- 农业土壤检测技术行业发展前景及投资风险预测分析报告
- 广东省深圳市罗湖区2023-2024学年二年级下学期期末考试数学试题
- 初级美发师题库
- DZ∕T 0214-2020 矿产地质勘查规范 铜、铅、锌、银、镍、钼(正式版)
- 博奥工程量清单计价软件操作指南
- 2024年度-《医疗事故处理条例》解读
- (2024年)面神经炎课件完整版
评论
0/150
提交评论