Advertisement
apez1

Untitled

Dec 4th, 2019
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.76 KB | None | 0 0
  1. // Lab12_Motorsmain.c
  2. // Runs on MSP432
  3. // Solution to Motors lab
  4. // Daniel and Jonathan Valvano
  5. // December 17, 2018
  6.  
  7. /* This example accompanies the book
  8.    "Embedded Systems: Introduction to Robotics,
  9.    Jonathan W. Valvano, ISBN: 9781074544300, copyright (c) 2019
  10.  For more information about my classes, my research, and my books, see
  11.  http://users.ece.utexas.edu/~valvano/
  12.  
  13. Simplified BSD License (FreeBSD License)
  14. Copyright (c) 2019, Jonathan Valvano, All rights reserved.
  15.  
  16. Redistribution and use in source and binary forms, with or without modification,
  17. are permitted provided that the following conditions are met:
  18.  
  19. 1. Redistributions of source code must retain the above copyright notice,
  20.    this list of conditions and the following disclaimer.
  21. 2. Redistributions in binary form must reproduce the above copyright notice,
  22.    this list of conditions and the following disclaimer in the documentation
  23.    and/or other materials provided with the distribution.
  24.  
  25. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  29. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  31. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  32. AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  33. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  34. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35.  
  36. The views and conclusions contained in the software and documentation are
  37. those of the authors and should not be interpreted as representing official
  38. policies, either expressed or implied, of the FreeBSD Project.
  39.  */
  40.  
  41.  
  42.  
  43. //**************RSLK1.1***************************
  44. // Left motor direction connected to P5.4 (J3.29)
  45. // Left motor PWM connected to P2.7/TA0CCP4 (J4.40)
  46. // Left motor enable connected to P3.7 (J4.31)
  47. // Right motor direction connected to P5.5 (J3.30)
  48. // Right motor PWM connected to P2.6/TA0CCP3 (J4.39)
  49. // Right motor enable connected to P3.6 (J2.11)
  50.  
  51. #include <stdint.h>
  52. #include "msp.h"
  53. #include "..\inc\bump.h"
  54. #include "..\inc\Clock.h"
  55. #include "..\inc\SysTick.h"
  56. #include "..\inc\LaunchPad.h"
  57. #include "..\inc\MotorSimple.h"
  58. #include "..\inc\Reflectance.c"
  59.  
  60. // Driver test
  61. void Pause(void){
  62.     while(LaunchPad_Input()==0);  // wait for touch
  63.     while(LaunchPad_Input());     // wait for release
  64. }
  65.  
  66. uint8_t Data;
  67. int32_t Position;
  68. int main(void){ // Program12_4, RSLK version 1.1
  69.     Clock_Init48MHz();
  70.     LaunchPad_Init();   // built-in switches and LEDs
  71.     Bump_Init();        // bump switches
  72.     Motor_InitSimple(); // initialization
  73.     Reflectance_Init();
  74.     while(1){
  75.  
  76.         Data = Reflectance_Read(1900);
  77.         Position = Reflectance_Position(Data);
  78.  
  79.  
  80.  
  81.         if(Position < 60 && Position > -60){
  82.             LaunchPad_Output(0x02);
  83.             Motor_ForwardSimple(4200,2);
  84.             Clock_Delay1ms(10);
  85.         }
  86.        
  87.         else if (Position > 60) {
  88.             LaunchPad_Output(0x02);
  89.             Motor_LeftSimple(4000, 5);
  90.             Clock_Delay1ms(10);
  91.             Motor_ForwardSimple(3000,2);
  92.  
  93.         }
  94.        
  95.         else if ( Position <- 60) {
  96.             LaunchPad_Output(0x02);
  97.             Motor_RightSimple(4000, 5);
  98.             Clock_Delay1ms(10);
  99.             Motor_ForwardSimple(3000,2);
  100.         }
  101.  
  102.  
  103.         if(Bump_Read()){
  104.             LaunchPad_Output(0x01);
  105.             Motor_BackwardSimple(2000,100);
  106.             Clock_Delay1ms(10);
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement