找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1500|回复: 1
收起左侧

恩智浦摄像头程序速度 2.5m/s

[复制链接]
ID:329533 发表于 2020-1-10 14:26 | 显示全部楼层 |阅读模式
恩智浦摄像头程序 2.5m/s

单片机源程序如下:
  1. /*!
  2. *     COPYRIGHT NOTICE
  3. *     Copyright (c) 2013,山外科技
  4. *     All rights reserved.

  5. *
  6. * @file       main.c
  7. * @brief      山外KL26 平台主程序
  8. * @author     山外科技
  9. * @version    v5.2
  10. * @date       2014-10-26
  11. */

  12. #include "common.h"
  13. #include "include.h"

  14. extern uint16 sensor_value[6];
  15. extern uint16 normalization_threshold[6];
  16. extern float position_accumulative[15];


  17. int32 var[5];                                           //发送到上位机的数据
  18. float position = 0.0f;                                 //位置偏差
  19. float pwm = 0.0f;                                      //舵机占空比增量
  20. uint32 pwm_duty_now = 0;                                //舵机占空比
  21. uint8 loss_line = 0;                                    //丢线标志位
  22. uint8 loss_line_lock =0;                                //丢线锁
  23. uint8 circle_sign = 0;                                  //圆环标志
  24. uint8 ramp_sign = 0;                                    //坡道标志
  25. uint8 stop_car_sign = 0;                                //停车标志

  26. uint16 motor_speed = 0;                            //当前电机速度
  27. int16 speed_set = 250;                            //电机目标速度
  28. uint8 speed_rank = 0;                            //速度等级


  29. void pit2IRQHandler(void);                             //定时器中断函数声明


  30. /*!
  31. *  @brief      main函数
  32. *  @since      v5.2
  33. */
  34. void main()
  35. {
  36.     int16 gx, gy, gz,ax,ay,az;
  37. //    Sensor_init();
  38. //    Gyroscope_init();
  39. //    servo_motor_init();
  40. //    switch_button_init();
  41. //    motor_init();
  42. //    encoder_init();
  43. //    Servo_pid_init();
  44. //    flash_24c02_init();
  45. //    Senser_normalization_threshold_get();
  46. //    Senser_normalization_threshold_read(normalization_threshold);       //读取归一化阀值
  47. //    speed_stall_select();               //速度档位选择
  48. //    NVIC_SetPriority(PORTA_IRQn,0);                     //为了防止漏过停车线,将停车用的外部中断定为最高优先级
  49. //    NVIC_SetPriority(PIT_IRQn,1);
  50. //    pit_init_ms(PIT0,5);                                //初始化定时器中断,10ms
  51. //    set_vector_handler(PIT_VECTORn , pit2IRQHandler);   //初始化定时器中断,10ms
  52. //    enable_irq(PIT_IRQn);
  53.     MPU_Init();
  54.     while(1)
  55.     {
  56.         systick_delay_ms(20);
  57.         MPU_Get_Gyroscope(&gx,&gy,&gz);
  58.         MPU_Get_Accelerometer(&ax,&ay,&az);
  59.         printf("%5d   %5d   %5d    %5d    %5d    %5d    %5d\r\n",gx ,gy ,gz,ax,ay,az,MPU_Get_Temperature());
  60.     }
  61. }

  62. void pit2IRQHandler(void)
  63. {
  64.       encoder_get(&motor_speed);
  65.       reed_detection();         //干簧管停车检测
  66.       Sensor_value_get(sensor_value);
  67.       Senser_normalization(sensor_value);
  68. //      printf("%5d %5d %5d %5d %5d %5d\r\n",sensor_value[0],sensor_value[1],sensor_value[2],sensor_value[3],sensor_value[4],sensor_value[5]);
  69. //      printf("%5d  %d\r\n",sensor_value[0]+sensor_value[2]+sensor_value[3]+sensor_value[5],(int32)(position * 100));      
  70.       position = cal_deviation(sensor_value);
  71.       position = position_filter(position);
  72.       pwm = Servo_pid_cal(position);
  73.       ramp_sign = ramp_deal(sensor_value,position,&motor_speed);                     //坡道处理
  74.       if(ramp_sign == 0)                                                //在坡道上不进行圆环处理
  75.       {
  76.           circle_sign = circle_deal(sensor_value,position,&motor_speed);             //圆环检测
  77.       }
  78.       /***圆环处理***/
  79.      if(circle_sign == 0)    //没有检测到圆环,丢线处理原值
  80.        {
  81.             if(ramp_sign == 0)
  82.             {
  83.                 loss_line_deal(sensor_value , position , LEFT_LOSE_LINE_THRESHOLD , RIGHT_LOSE_LINE_THRESHOLD);
  84.             }            
  85.         }
  86.       else if(circle_sign == 2)    //如果车已经入圆,使用圆内的丢线处理
  87.       {
  88.           loss_line_deal(sensor_value , position , LEFT_LOSE_LINE_THRESHOLD - 10 , RIGHT_LOSE_LINE_THRESHOLD - 10);
  89.        }
  90.       switch(loss_line)
  91.       {
  92.           case 0:
  93.               pwm_duty_now = servo_motor_pwm_set(SERVO_MID - (int)(pwm));
  94.               break;
  95.               
  96.           case 1:
  97.               if(circle_sign == 2)
  98.               {
  99.                   if(((switch_read())&(0x40)) == 0)
  100.                   {
  101.                       position = POSITION_BOUND;
  102.                       pwm_duty_now = servo_motor_pwm_set(SERVO_RIGHT_DEAD_ZONE);
  103.                   }
  104.                   else
  105.                   {
  106.                       position = (-(POSITION_BOUND));
  107.                       pwm_duty_now = servo_motor_pwm_set(SERVO_LEFT_DEAD_ZONE);
  108.                   }
  109.               }
  110.               else
  111.               {
  112.                   loss_line_lock = 1;
  113.                   position = POSITION_BOUND;
  114.                   pwm_duty_now = servo_motor_pwm_set(SERVO_RIGHT_DEAD_ZONE);
  115.               }
  116.               break;
  117.               
  118.           case 2:
  119.               if(circle_sign == 2)
  120.               {
  121.                   if(((switch_read())&(0x40)) == 0)
  122.                   {
  123.                       position = POSITION_BOUND;
  124.                       pwm_duty_now = servo_motor_pwm_set(SERVO_RIGHT_DEAD_ZONE);
  125.                   }
  126.                   else
  127.                   {
  128.                       position = (-(POSITION_BOUND));
  129.                       pwm_duty_now = servo_motor_pwm_set(SERVO_LEFT_DEAD_ZONE);                     
  130.                   }
  131.               }
  132.               else
  133.               {
  134.                   loss_line_lock = 1;
  135.                   position = (-(POSITION_BOUND));
  136.                   pwm_duty_now = servo_motor_pwm_set(SERVO_LEFT_DEAD_ZONE);
  137.               }
  138.               break;
  139.       }
  140.       if((((switch_read()) & (0x80)) == 0) | (stop_car_sign == 1))
  141.       {
  142.           motor_pwm_set(0);
  143.       }
  144.       else
  145.       {
  146.           motor_pwm_set((int32)speed_set);
  147.       }         
  148. //      vcan_scope((uint8_t *)var,sizeof(var));         //虚拟示波器发送数据
  149.       PIT_Flag_Clear(PIT0);
  150. }
复制代码

iar代码下载:
8.29 迷你小霸王程序.7z (2.35 MB, 下载次数: 13)
回复

使用道具 举报

ID:421049 发表于 2021-3-28 13:55 | 显示全部楼层
请问这是第几届的代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表