国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

小車跟隨行駛系統(tǒng)(基于MSP-EXP430F5529LP系統(tǒng)板)

這篇具有很好參考價(jià)值的文章主要介紹了小車跟隨行駛系統(tǒng)(基于MSP-EXP430F5529LP系統(tǒng)板)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

選用材料:主控板MSP-EXP430F5529LP、陀螺儀、直流減速電機(jī)(可以選用光電編碼器,霍爾電機(jī)不好調(diào)節(jié)PID)、TB6612電機(jī)驅(qū)動(dòng)、超聲波測(cè)距模塊、灰度傳感器、無線透?jìng)?藍(lán)牙模塊(便于兩輛小車相互發(fā)送信息)、OLED屏等。

總體思路:使用灰度傳感器巡線,超聲波檢測(cè)前后車距,通過調(diào)節(jié)PID的位置環(huán),控制兩輛小車前后的距離,運(yùn)用JY901進(jìn)行陀螺儀矯正。

2022TI_C1_JY901.c

#include "2022TI_C1_JY901.h"

struct SAngle Mpu_angle;

//串口0初始化
void Usart0Init(void)
{
    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P3, GPIO_PIN4);
    GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P3, GPIO_PIN3);

    //Baudrate = 115200, clock freq = 25MHz
    //在線計(jì)算器
    //https://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430BaudRateConverter/index.html
    USCI_A_UART_initParam param = {0};
    param.selectClockSource = USCI_A_UART_CLOCKSOURCE_SMCLK;
    param.clockPrescalar = 13;
    param.firstModReg = 9;
    param.secondModReg = 0;
    param.parity = USCI_A_UART_NO_PARITY;
    param.msborLsbFirst = USCI_A_UART_LSB_FIRST;
    param.numberofStopBits = USCI_A_UART_ONE_STOP_BIT;
    param.uartMode = USCI_A_UART_MODE;
    param.overSampling = USCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION;


    if (STATUS_FAIL == USCI_A_UART_init(USCI_A0_BASE, &param))
    {
        return;
    }

    //Enable UART module for operation
    USCI_A_UART_enable(USCI_A0_BASE);

    //Enable Receive Interrupt
    USCI_A_UART_clearInterrupt(USCI_A0_BASE,USCI_A_UART_RECEIVE_INTERRUPT);
    USCI_A_UART_enableInterrupt(USCI_A0_BASE,USCI_A_UART_RECEIVE_INTERRUPT);
}

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A0_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(USCI_A0_VECTOR)))
#endif
void USCI_A0_ISR (void)
{
//    uint8_t receivedData = 0;

    switch (__even_in_range(UCA0IV,4))
    {
        //Vector 2 - RXIFG
        case 2:
            CopeSerial2Data(USCI_A0_BASE);
//            receivedData = USCI_A_UART_receiveData(USCI_A0_BASE);
            break;
        default: break;
    }
}

//發(fā)送N個(gè)字節(jié)長(zhǎng)度的數(shù)據(jù)
void USART0_Send(uint8_t *pui8Buffer, uint32_t ui32Count)
{
  while(ui32Count--)
  {
      USCI_A_UART_transmitData(USCI_A0_BASE, *pui8Buffer++);
  }
}

void CopeSerial2Data(uint16_t baseAddress)
{
    static unsigned char ucRxBuffer[250];
    static unsigned char ucRxCnt = 0;
    unsigned char i,sum;

    ucRxBuffer[ucRxCnt++]=USCI_A_UART_receiveData(baseAddress);;   //將收到的數(shù)據(jù)存入緩沖區(qū)中

    if (ucRxBuffer[0]!=0x55) //數(shù)據(jù)頭不對(duì),則重新開始尋找0x55數(shù)據(jù)頭
    {
        ucRxCnt=0;
        return;
    }
    if (ucRxCnt<11) {return;}//數(shù)據(jù)不滿11個(gè),則返回
    else
    {
        switch(ucRxBuffer[1])//三軸角度
        {
            case 0x53:
                memcpy(&Mpu_angle,&ucRxBuffer[2],8);
                for(i=0; i<10; i++)
                    sum += ucRxBuffer[i];

                if(sum == ucRxBuffer[10])
                {
                    Mpu_angle.angle_z=  (float)Mpu_angle.Angle[2]/32768*180;//Z
                    Mpu_angle.angle_y = (float)Mpu_angle.Angle[0]/32768*180;//Y
                    Mpu_angle.angle_x = (float)Mpu_angle.Angle[1]/32768*180;//X

                }
//                memcpy(&Mpu_angle,&ucRxBuffer[2],8);
//                Mpu_angle.angle_z=  (float)Mpu_angle.Angle[2]/32768*180;//Z
//                Mpu_angle.angle_y = (float)Mpu_angle.Angle[0]/32768*180;//Y
//                Mpu_angle.angle_x = (float)Mpu_angle.Angle[1]/32768*180;//X
            break;
            default:break;
        }
        ucRxCnt=0;//清空緩存區(qū)
    }
}

2022TI_C1_JY901.h

#ifndef __2022TI_C1_JY901_H_
#define __2022TI_C1_JY901_H_

#include <includes.h>


struct SAngle
{
    short Angle[3];
    short T;
    float angle_x;
    float angle_y;
    float angle_z;
};

extern struct SAngle Mpu_angle;

//串口0初始化
void Usart0Init(void);
void USART0_Send(uint8_t *pui8Buffer, uint32_t ui32Count);

void CopeSerial2Data(uint16_t baseAddress);

#endif /* JY901_H_ */

2022TI_C1_SR04.c

#include "2022TI_C1_SR04.h"

float sr04_dist = 0.0;
uint32_t Sign_Counts = 0;//脈沖寬度(高) us

//啟動(dòng)測(cè)量
void SR04_Start(void)
{
    GPIO_setOutputHighOnPin(GPIO_PORT_P7, GPIO_PIN4);
    delay_us(50);
    GPIO_setOutputLowOnPin(GPIO_PORT_P7, GPIO_PIN4);
}

//SR04 trig p7.4
//SR04 echo p2.5
void Timer_A2_Capture_Init(void)
{
    Timer_A_initContinuousModeParam htim = {0};
    htim.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;
    htim.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;
    htim.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_ENABLE;
    htim.timerClear = TIMER_A_DO_CLEAR;
    htim.startTimer = true;
    Timer_A_initContinuousMode(TIMER_A2_BASE, &htim);

    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P2, GPIO_PIN5);
    Timer_A_initCaptureModeParam capture_htim = {0};
    capture_htim.captureRegister = TIMER_A_CAPTURECOMPARE_REGISTER_2;
    capture_htim.captureMode = TIMER_A_CAPTUREMODE_RISING_AND_FALLING_EDGE;
    capture_htim.captureInputSelect = TIMER_A_CAPTURE_INPUTSELECT_CCIxA;
    capture_htim.synchronizeCaptureSource = TIMER_A_CAPTURE_SYNCHRONOUS;
    capture_htim.captureInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE;
    capture_htim.captureOutputMode = TIMER_A_OUTPUTMODE_OUTBITVALUE;
    Timer_A_initCaptureMode(TIMER_A2_BASE,&capture_htim);

    GPIO_setAsOutputPin(GPIO_PORT_P7, GPIO_PIN4);
    GPIO_setOutputLowOnPin(GPIO_PORT_P7, GPIO_PIN4);
    GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN5);
}

#pragma vector=TIMER2_A1_VECTOR
__interrupt
void TIMER2_A1_ISR (void)
{
    static uint16_t Overflow_Times = 0;
    static uint16_t Sign_Begin = 0, Sign_End = 0;

    switch(TA2IV)
    {
        case TA2IV_TACCR2:
            if(GPIO_getInputPinValue(GPIO_PORT_P2,GPIO_PIN5))
            {
                Sign_Begin = Timer_A_getCaptureCompareCount(TIMER_A2_BASE,TIMER_A_CAPTURECOMPARE_REGISTER_2);
            }
            else
            {
                Sign_End = Timer_A_getCaptureCompareCount(TIMER_A2_BASE,TIMER_A_CAPTURECOMPARE_REGISTER_2);
                if(!Overflow_Times)
                    Sign_Counts = Sign_End - Sign_Begin;
                else
                {
                    Sign_Counts = (uint32_t)65536 * Overflow_Times + Sign_End - Sign_Begin;
                    Overflow_Times = 0;
                }

                //25MHZ
                //計(jì)數(shù)周期 1/25 us 340M/S
                sr04_dist = 0.04 *0.34 * Sign_Counts / 2.0;//mm
            }
            Timer_A_clearCaptureCompareInterrupt(TIMER_A2_BASE,TIMER_A_CAPTURECOMPARE_REGISTER_2);
            break;
        case TA2IV_TAIFG:
            if(GPIO_getInputPinValue(GPIO_PORT_P2,GPIO_PIN5))
            {
                ++Overflow_Times;
            }
            else
                Overflow_Times = 0;
            Timer_A_clearTimerInterrupt(TIMER_A2_BASE);
            break;
        default:
            break;
    }
}

2022TI_C1_SR04.h

#ifndef __2022TI_C1_SR04__H
#define __2022TI_C1_SR04__H

#include <includes.h>

extern float sr04_dist;
extern uint32_t Sign_Counts;

void SR04_Start(void);

void Timer_A2_Capture_Init(void);

#endif 

2022TI_C1_PID.c

#include "2022TI_C1_PID.h"

PID M3508_spid[2];
PID ANGLE;
PID distance;
float abs_limit(float a, float ABS_MAX)
{
	if(a > ABS_MAX)
		a = ABS_MAX;

	if(a < -ABS_MAX)
		a = -ABS_MAX;
	return a;
}

void PID_Position_Calc( PID *pp,  float  CurrentPoint,  float NextPoint )  
{   
	pp->Error =  NextPoint -  CurrentPoint;          
	pp->SumError += pp->Error;                      
	pp->DError = pp->Error - pp->LastError;

	pp->output =  pp->Proportion * pp->Error +   \
								abs_limit(pp->Integral * pp->SumError, pp->Integralmax ) +   \
								pp->Derivative * pp->DError ;  

	if(pp->output > pp->outputmax )  pp->output = pp->outputmax;
	if(pp->output < - pp->outputmax )  pp->output = -pp->outputmax;
//	pp->PrevError = pp->LastError;  
	pp->LastError = pp->Error;
}

void PID_Incremental_Calc( PID *pp,  float  CurrentPoint,  float NextPoint )  
{  
	pp->Error =  NextPoint -  CurrentPoint;          
	pp->SumError += pp->Error;                      
	pp->DError = pp->Error - pp->LastError;

	pp->output +=  pp->Proportion * ( pp->Error - pp->LastError )+   \
								 abs_limit(pp->Integral * pp->Error, pp->Integralmax ) +   \
								 pp->Derivative * ( pp->Error +  pp->PrevError - 2*pp->LastError);  

	if(pp->output > pp->outputmax )  pp->output = pp->outputmax;
	if(pp->output < - pp->outputmax )  pp->output = -pp->outputmax;
	pp->PrevError = pp->LastError;  
	pp->LastError = pp->Error;
}

void PIDInit(PID *pp, float Kp , float Ki , float Kd ,  float outputmax, float Integralmax)  
{  
	pp->Integralmax = Integralmax;
	pp->outputmax  = outputmax;
	pp->Proportion = Kp;
	pp->Integral   = Ki;
	pp->Derivative = Kd;
	pp->DError = pp->Error = pp->output = pp->LastError = pp->PrevError = 0; 
}  

2022TI_C1_PID.h文章來源地址http://www.zghlxwxcb.cn/news/detail-522684.html

#ifndef __2022TI_C1_PID_H
#define __2022TI_C1_PID_H

typedef struct PID {
  float  Proportion;         //  Proportional Const  
  float  Integral;           //  Integral Const  
  float  Derivative;         //  Derivative Const  
	float  PrevError;          //  Error[-2]
  float  LastError;          //  Error[-1]  
	float  Error;
	float  DError;
  float  SumError;           //  Sums of Errors  
	float  Integralmax;
	float  output;
	float  outputmax;
} PID;

extern PID M3508_spid[2];
extern PID ANGLE;
extern PID distance;

float abs_limit(float a, float ABS_MAX);
void PID_Position_Calc( PID *pp,  float  CurrentPoint,  float NextPoint);
void PID_Incremental_Calc( PID *pp,  float  CurrentPoint,  float NextPoint);
void PIDInit(PID *pp, float Kp , float Ki , float Kd ,  float outputmax, float Integralmax);

#endif

到了這里,關(guān)于小車跟隨行駛系統(tǒng)(基于MSP-EXP430F5529LP系統(tǒng)板)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 快速上手MSP430F5529開發(fā)板教程(基于CCS8環(huán)境下的自制庫(kù))

    快速上手MSP430F5529開發(fā)板教程(基于CCS8環(huán)境下的自制庫(kù))

    MSP430單片機(jī)的學(xué)習(xí)難度介于51與STM32之間,推薦使用寄存器開發(fā),因?yàn)镸SP430的寄存器操作真的比庫(kù)函數(shù)操作要簡(jiǎn)易許多。在學(xué)習(xí)MSP430的時(shí)候,建議直接看中文手冊(cè)(重點(diǎn))和原理圖學(xué)習(xí)。 CCS8環(huán)境搭建 MSP430F5529開發(fā)板 中文手冊(cè)與原理圖 關(guān)于下載及安裝CCS大家可以參考這篇文章

    2024年02月16日
    瀏覽(37)
  • MSP430F5529學(xué)習(xí)筆記(6)——導(dǎo)入MSP430Ware,查看例程

    MSP430F5529學(xué)習(xí)筆記(6)——導(dǎo)入MSP430Ware,查看例程

    MSP430WARE下載; 目錄 在線版本 下載MSP430Ware 查看例程 導(dǎo)入例程? 離線版本 下載MSP430Ware ?查看例程 導(dǎo)入例程 MSP430Ware里面有很多例程和庫(kù)函數(shù)使用手冊(cè),我們可以查看學(xué)習(xí)。非常重要 (1) 打開CCS——view——Resource Explorer ?之后我們會(huì)進(jìn)入如下界面 (2) ?點(diǎn)擊MSP430——Embe

    2024年02月13日
    瀏覽(26)
  • MSP430F5529——中斷理解

    MSP430F5529——中斷理解

    認(rèn)識(shí)低功耗模式; MSP430的中斷,需要兩個(gè)部分,一部分是打開中斷,另外一部分是編寫中斷服務(wù)函數(shù) 首先我們得知道__bis_SR_register和_BIS_SR是一個(gè)玩意。查看宏定義可知 ?_BIS_SR()可傳入的參數(shù) 然后我們查看x的值,發(fā)現(xiàn)里面有八個(gè)可以傳入的值 我們這里只需要關(guān)系GIE就可以

    2024年02月16日
    瀏覽(32)
  • MSP430F5529學(xué)習(xí)筆記

    該MCU是由德州儀器TI生產(chǎn)的16位低功耗單片機(jī) 主要分以下型號(hào): 專注低功耗的 1xx 通用型,配備1KB-60KB FLASH、512B-10KB RAM,工作時(shí)耗電僅達(dá)200uA/MIPS,RAM保持模式耗電0.1uA,RTC模式耗電0.7uA;可在6us之內(nèi)快速喚醒。搭載10/12位斜率SAR ADC,集成模擬比較器、DMA、硬件乘法器、BOR、SV

    2024年02月15日
    瀏覽(29)
  • 基于MSP430 紅外避障-遙控小車(電賽必備 附項(xiàng)目代碼)

    基于MSP430 紅外避障-遙控小車(電賽必備 附項(xiàng)目代碼)

    項(xiàng)目環(huán)境: 1. MSP430F5529 2. Code Composer Studio 3. 藍(lán)牙調(diào)試助手 項(xiàng)目簡(jiǎn)介: 小車可分為3種工作模式,每種工作模式都會(huì)打印在OLED顯示屏上,通過按鍵轉(zhuǎn)換工作模式。 模式1: 小車紅外循跡,通過超聲波實(shí)時(shí)監(jiān)測(cè)障礙物距離,若超出規(guī)定路線,距離障礙物相對(duì)較近時(shí),原地停止,

    2023年04月08日
    瀏覽(26)
  • MSP430F5529庫(kù)函數(shù)學(xué)習(xí)——串口

    MSP430F5529庫(kù)函數(shù)學(xué)習(xí)——串口

    波特率計(jì)算網(wǎng)站;導(dǎo)入MSP430Ware,查看例程;原理圖和中文開發(fā)手冊(cè)獲取 目錄 GPIO_setAsPeripheralModuleFunctionInputPin()和GPIO_setAsPeripheralModuleFunctionOutputPin 函數(shù)聲明 ?作用 參數(shù) selectedPort selectedPins 使用 USCI_A_UART_init() 函數(shù)聲明 ?作用 參數(shù) baseAddress param ?USCI_A_UART_enable() 函數(shù)

    2024年02月16日
    瀏覽(31)
  • 05:OLED模塊【MSP430F5529】

    05:OLED模塊【MSP430F5529】

    目錄 實(shí)物圖 字模取字 ????????字模軟件 ? ? ? ? 取模步驟 ????????1.設(shè)置軟件 ????????2.取模 ????????3.輸出數(shù)據(jù) ?代碼 type.h oledfont.h oled.h oled.c main.c 下面圖片中,可以看到OLED模塊的四個(gè)接口:GND,VCC,SCL,SDA GND VCC SCL SDA 接地 接電源3.3V/5V 接P3.5 接P3.6 ??????

    2024年02月16日
    瀏覽(29)
  • MSP430F5529庫(kù)函數(shù)GPIO學(xué)習(xí)

    MSP430F5529庫(kù)函數(shù)GPIO學(xué)習(xí)

    導(dǎo)入MSP430Ware,查看例程;數(shù)據(jù)手冊(cè)以及原理圖獲取 建議不是很了解寄存器的看完我的MSP430F5529學(xué)習(xí)筆記? 目錄 GPIO_setAsOutputPin() 函數(shù)聲明 作用 參數(shù) selectedPort selectedPins 修改的寄存器 使用 與GPIO_setAsOutputPin()參數(shù)一致的函數(shù) ?GPIO_setOutputHighOnPin() GPIO_setOutputLowOnPin()

    2024年02月15日
    瀏覽(31)
  • MSP430F5529_PWM波全調(diào)制

    /* ?* main.c ?*/ #include\\\"PWM.c\\\" #include\\\"msp430f5529.h\\\" void main(void) { ? ? ? ? WDTCTL=WDTPW+WDTHOLD; ?//關(guān)閉看門狗 ? ? ? ? set_PWM(20000); ? ? ? ? while(1) ? ? ? ? { ? ? ? ? ? ? ? ? //舵機(jī),可自行修改 ? ? ? ? setPWM_duty_cycle(12,2000); ? ? ? ? delay_ms(1000); ? ? ? ? setPWM_duty_cycle(13,500); ? ? ? ?

    2024年02月14日
    瀏覽(12)
  • MSP430學(xué)習(xí)筆記(四)丨I2C通信(MSP430F5529驅(qū)動(dòng)OLED顯示屏)

    ???筆者學(xué)習(xí)采用單片機(jī)型號(hào)為MSP430F5529,使用MSP-EXP430F5529LP開發(fā)板。 ???筆者擁有一定的STM32基礎(chǔ),在學(xué)習(xí)MSP430的過程中,最開始苦于沒有合適的OLED顯示驅(qū)動(dòng)代碼,所以花了很多時(shí)間鉆研。綜合網(wǎng)上的各種代碼,筆者認(rèn)為江協(xié)科技的STM32課程中提供的OLED代碼使用方便,

    2024年02月16日
    瀏覽(25)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包