Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.69 KB | None | 0 0
  1. #if 1
  2.    
  3. void motor_forward_fixed(uint8 speed, uint32 delay)
  4.     {
  5.         MotorDirLeft_Write(0);
  6.         MotorDirRight_Write(0);
  7.         float ratio = 1.05; // pitää säätää, 1.3 vähän liikaa
  8.        
  9.         uint8 l_speed = speed;
  10.         uint8 r_speed = (float)speed / ratio;
  11.        
  12.         motor_turn(l_speed, r_speed, delay);
  13.     }
  14.    
  15. void motor_tank_turn_90dg(int left_dir, int right_dir)
  16.     {
  17.         MotorDirLeft_Write(left_dir);
  18.         MotorDirRight_Write(right_dir);
  19.         PWM_WriteCompare1(60);
  20.         PWM_WriteCompare2(60);
  21.         vTaskDelay(1500);
  22.        
  23.     }
  24. void motor_random_turn ()
  25. {
  26.     int direction = rand() % 2;
  27.    
  28.     if (direction==0)
  29.     {
  30.         motor_turn(100, 70, 500);
  31.        
  32.     }
  33.     else
  34.     {
  35.         motor_turn(70, 100, 500);
  36.        
  37.     }
  38. }
  39.  
  40. void zmain(void)
  41. {
  42.     struct accData_ data;
  43.     motor_start();
  44.     motor_forward(0,0);
  45.    
  46.    
  47.     while (SW1_Read == 1)
  48.     {
  49.         vTaskDelay(200);
  50.     }
  51.    
  52.     vTaskDelay(1000);
  53.    
  54.     motor_forward_fixed(200,0);
  55.    
  56.     for(;;)
  57.     {
  58.         LSM303D_Read_Acc(&data);
  59.        
  60.         if (data.accX <0)
  61.         {
  62.             motor_backward(100,500);
  63.             int suunta = rand() % 2;
  64.            
  65.             if(suunta==0)
  66.             {
  67.                 motor_tank_turn_90dg(0,1);
  68.             }
  69.             else
  70.             {
  71.                 motor_tank_turn_90dg(1,0);
  72.             }
  73.         }    
  74.        
  75.         int randomTurn = rand() % 10;
  76.            
  77.          if (randomTurn == 0)
  78.          {
  79.             motor_random_turn();
  80.             motor_forward_fixed(200,0);
  81.         }
  82.         vTaskDelay(50);
  83.     }
  84. }
  85.  
  86. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement