欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: 為什么加了和尋跡相關的單片機代碼之后,小車的速度變慢了 [打印本頁]

作者: 新人小白    時間: 2022-6-5 10:20
標題: 為什么加了和尋跡相關的單片機代碼之后,小車的速度變慢了
為什么加了和尋跡相關的代碼之后,小車的速度變慢了?有什么解決的方法嗎?
  1. int GraysensorRPin = 18;
  2. int GraysensorLPin = 14;
  3. int motor_01 = 10;
  4. int motor_02 = 6;
  5. int motor_03 = 5;
  6. int motor_04 = 9;
  7. int start_stop_flag = 0;
  8. int stop_num = 0;
  9. int stop_clear_num = 0;
  10. void right();
  11. void left();
  12. void forwards();
  13. void stop();

  14. void setup() {
  15.   pinMode(GraysensorRPin,INPUT);
  16.   pinMode(GraysensorLPin,INPUT);
  17.   pinMode(motor_01,OUTPUT);
  18.   pinMode(motor_02,OUTPUT);
  19.   pinMode(motor_03,OUTPUT);
  20.   pinMode(motor_04,OUTPUT);
  21. }

  22. void loop() {
  23.   if(!(digitalRead(GraysensorRPin)) &&digitalRead(GraysensorLPin))
  24.   {
  25.     right();
  26.   }
  27.     if(digitalRead(GraysensorRPin) && !(digitalRead(GraysensorLPin)))
  28.   {
  29.     left();
  30.   }
  31.     if( (!digitalRead(GraysensorRPin))&& (!digitalRead(GraysensorLPin)))
  32.   {
  33.     forwards();
  34.   }
  35.     if(digitalRead(GraysensorRPin) &&digitalRead(GraysensorLPin))
  36.   {
  37.     stop();
  38.   }
  39.   if(stop_clear_num == 2)
  40.   {
  41.     start_stop_flag = 1;
  42.   }
  43.   
  44. }
  45. void stop()
  46. {
  47.    if(start_stop_flag)
  48.   {
  49.     analogWrite(motor_03, 0);
  50.     analogWrite(motor_02, 0);
  51.     analogWrite(motor_04, 0);
  52.     analogWrite(motor_01, 0);
  53.     start_stop_flag = 0;
  54.     forwards();
  55.   }else
  56.   {
  57.     stop_num++;
  58.   }
  59. }

  60. void right()
  61. {
  62.   analogWrite(motor_03, 175);
  63.   analogWrite(motor_02, 0);
  64.   analogWrite(motor_04, 0);
  65.   analogWrite(motor_01, 175);
  66. }

  67. void forwards()
  68. {
  69.   analogWrite(motor_03, 175);
  70.   analogWrite(motor_02, 0);
  71.   analogWrite(motor_04, 175);
  72.   analogWrite(motor_01, 0);
  73.    if(stop_num > 10)
  74.   {
  75.     stop_num = 0;
  76.     stop_clear_num++;
  77.   }
  78. }

  79. void left()
  80. {
  81.   analogWrite(motor_03, 0);
  82.   analogWrite(motor_02, 175);
  83.   analogWrite(motor_04, 175);
  84.   analogWrite(motor_01, 0);
  85. }
復制代碼





作者: glinfei    時間: 2022-6-6 08:51
我覺得你程序判斷上有問題,因該沒法循跡。至于循跡時車速慢很正常,你可以加強動力,就是analogwrite那的值大一點唄,它的范圍是255以內。
作者: 新人小白    時間: 2022-6-6 14:44
尋跡是能正常尋跡的,只是加了尋跡的代碼之后,小車變得比之前的慢

作者: 香菜不是香菜    時間: 2022-6-6 20:17
看樣子你這是四個電機,在沒加尋跡之前你是四個電機都動,加了尋跡后只有兩個電機工作,其實轉彎時可以讓四個電機都工作的,兩個正轉,兩個反轉。
作者: 香菜不是香菜    時間: 2022-6-6 20:20
可以兩個電機正轉,兩個電機反轉,這樣甚至能實現原地轉圈,速度和轉向能力也會提高不少。還有就是可如樓上說的調高電壓,選用5V電壓可能也能解決一部分問題。
作者: LXJG    時間: 2022-6-6 20:27
調pwm

作者: glinfei    時間: 2022-6-7 09:09
新人小白 發表于 2022-6-6 14:44
尋跡是能正常尋跡的,只是加了尋跡的代碼之后,小車變得比之前的慢

僅僅想速度快點,就把analogWrite(motor_02, 175);中的175調大,距離255還有好大的調節空間。由于循跡時用的是差動法,導致動能損失大,必然會降低速度的。如果轉向時,用一邊轉一邊不轉方式,這樣轉向不那么靈敏,但動能損失小點。




歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1