7_Direct_Motor_Control

本文通过两个实验探讨了不同放大倍数(Kp)对直流电机(DCMotor)调速性能的影响。实验中使用了额定参数为220V55A1000r/min的电机,并设置了不同的电枢电流加载方式。结果显示,放大倍数增加能够有效减小转速降,提高系统硬度。
实验:P控制下的DCMotor Control


额定参数:
    220v 55A 1000r/min,
    电动势常数 Ce = 0.193V*min/r
    晶闸管放大倍数Ks = 44,
    电枢回路总电阻 R = 1Ω
    转速反馈系数 α = 0.0116;

负载(额定电流):

  电枢电流的加载采用斜坡函数( Ramp ):起始时间0.1s,上升斜率100;
 
  放大器放大倍数 Kp = 20;

First Expriment:( Kp = 20 )

  分析可知,空载时,空载转速为1000r/min;
  当负载电流增加时,转速略有下降,在0.64s时,电流达到额定,此时的转速约为997.4r/min, 系统的速降为△n = 2.6 r/min。

Second Expriment: ( Kp = 40 )

  可以看到,随着放大器的倍数增加,转速降减少,硬度增加,抗负载扰动增加。



/* * Copyright (c) 2021, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. (); OLED_Init(); */ #include "ti_msp_dl_config.h" #include "main.h" #include "stdio.h" #include "encoder.h" // 全局变量 uint32_t motor_state = 0, key_val = 0; float current_duty = 0.4; // 初始占空比70% uint16_t distVal = 0; uint8_t oled_buffer[32]; // 按键读取函数 uint32_t read_KeyVal(void) { static uint32_t key_state = 0; if(DL_GPIO_readPins(GPIO_button_PORT, GPIO_button_PIN_s2_PIN) == 0) { mspm0_delay_ms(20); // 消抖 if(DL_GPIO_readPins(GPIO_button_PORT, GPIO_button_PIN_s2_PIN) == 0) { if(key_state == 0) { key_state = 1; return 1; // 检测到有效按下 } } } else { key_state = 0; } return 0; } // 设置PWM占空比 void Set_Duty(float duty, uint8_t channel) { uint32_t compareValue; // 限制占空比范围 if(duty > 0.95) duty = 0.95; if(duty < 0.05) duty = 0.05; compareValue = 125- (uint32_t)(125* duty); if(channel == 0) { DL_TimerG_setCaptureCompareValue(PWM_0_INST, compareValue, DL_TIMER_CC_0_INDEX); } else if(channel == 1) { DL_TimerG_setCaptureCompareValue(PWM_0_INST, compareValue, DL_TIMER_CC_1_INDEX); } } // 左电机控制 void motor_1(uint8_t direction) { if(direction == 1) { // 正转 DL_GPIO_setPins(GPIO_Motor_PORT, GPIO_Motor_PIN_A1_PIN); DL_GPIO_clearPins(GPIO_Motor_PORT, GPIO_Motor_PIN_A2_PIN); } else { // 反转 DL_GPIO_setPins(GPIO_Motor_PORT, GPIO_Motor_PIN_A2_PIN); DL_GPIO_clearPins(GPIO_Motor_PORT, GPIO_Motor_PIN_A1_PIN); } } // 右电机控制 void motor_2(uint8_t direction) { if(direction == 1) { // 正转 DL_GPIO_setPins(GPIO_Motor_PORT, GPIO_Motor_PIN_B1_PIN); DL_GPIO_clearPins(GPIO_Motor_PORT, GPIO_Motor_PIN_B2_PIN); } else { // 反转 DL_GPIO_setPins(GPIO_Motor_PORT, GPIO_Motor_PIN_B2_PIN); DL_GPIO_clearPins(GPIO_Motor_PORT, GPIO_Motor_PIN_B1_PIN); } } // 按键处理和电机启停控制 void Key_Process(void) { key_val = read_KeyVal(); if(key_val) { // 切换电机状态 motor_state = !motor_state; if(motor_state == 1) { // 启动电机 motor_1(1); // 左电机正转 motor_2(1); // 右电机正转 } else { // 停止电机 Set_Duty(0.0, 0); Set_Duty(0.0, 1); } } } // 超声波距离控制 void Ultrasonic_Control(void) { if(motor_state == 1) { // 仅在电机启动时控制 if(distVal < 50) { // 距离太近:后退 motor_1(0); // 左电机反转 motor_2(0); // 右电机反转 Set_Duty(current_duty, 0); Set_Duty(current_duty, 1); } else if(distVal > 70) { // 距离太远:前进 motor_1(1); // 左电机正转 motor_2(1); // 右电机正转 Set_Duty(current_duty, 0); Set_Duty(current_duty, 1); } else { // 保持理想距离:停止 Set_Duty(0.0, 0); Set_Duty(0.0, 1); } } } int main(void) { SYSCFG_DL_init(); SysTick_Init(); Encoder_Init(); // 初始化PWM DL_TimerG_startCounter(PWM_0_INST); // 初始化超声波和OLED Ultrasonic_Init(); OLED_ShowString(0, 0, (uint8_t *)"Dist:", 16); // 初始状态:停止电机 Set_Duty(0.0, 0); Set_Duty(0.0, 1); motor_state = 0; while(1) { Key_Process(); // 检测按键状态 distVal = Read_Ultrasonic(); // 读取超声波距离 // 显示距离 sprintf((char *)oled_buffer, "%4u", distVal); OLED_ShowString(6*8, 0, oled_buffer, 16); Ultrasonic_Control(); // 根据距离控制电机 mspm0_delay_ms(200); // 200ms延时 } } 这段代码的意思
最新发布
07-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值