Guest User

Untitled

a guest
Mar 29th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.96 KB | None | 0 0
  1. /*******************************************************************************
  2.  * @mainpage
  3.  * This is a template for the vexuser.c file.
  4.  *
  5.  * This program is based on a template by James Pearman in his "C on Vex"
  6.  * library, V 1.00.
  7.  *
  8.  * @author James Pearman
  9.  * @author Liam Bohl <liambohl@gmail.com>
  10.  * @author Faith Bosher <FABosher@gmail.com>
  11.  *
  12.  * @since 2014-12-22
  13.  ******************************************************************************/
  14. #include <stdlib.h>
  15. #include <math.h>
  16. #include <string.h>
  17.  
  18. #include "ch.h"             //ChibiOS programs
  19. #include "hal.h"            //hardware abstraction layer header
  20. #include "vex.h"            //vex library header
  21. #include "apollo.h"         //includes the apollo debug window in screen
  22. #include "smartmotor.h"     //smart motors
  23. #include "vexime.h"
  24.  
  25. #include "clicks.c"         //register and check when a button is clicked
  26.  
  27. #include "vexuser.h"        //function declarations
  28.  
  29. //Motor Names
  30. #define FRONT_LEFT          kVexMotor_2     //for example only
  31. #define FRONT_RIGHT         kVexMotor_4
  32. #define BACK_RIGHT          kVexMotor_5
  33. #define BACK_LEFT           kVexMotor_3
  34.  
  35.  
  36.  
  37. // Digi IO configuration
  38. static  vexDigiCfg  dConfig[kVexDigital_Num] = {
  39.         { kVexDigital_1,    kVexSensorDigitalInput,     kVexConfigInput,        0 },
  40.         { kVexDigital_2,    kVexSensorDigitalInput,     kVexConfigInput,        0 },
  41.         { kVexDigital_3,    kVexSensorDigitalInput,     kVexConfigInput,        0 },
  42.         { kVexDigital_4,    kVexSensorDigitalInput,     kVexConfigInput,        0 },
  43.         { kVexDigital_5,    kVexSensorDigitalInput,     kVexConfigInput,        0 },
  44.         { kVexDigital_6,    kVexSensorDigitalInput,     kVexConfigInput,        0 },
  45.         { kVexDigital_7,    kVexSensorDigitalInput,     kVexConfigInput,        0 },
  46.         { kVexDigital_8,    kVexSensorDigitalInput,     kVexConfigInput,        0 },
  47.         { kVexDigital_9,    kVexSensorDigitalInput,     kVexConfigInput,        0 },
  48.         { kVexDigital_10,   kVexSensorDigitalInput,     kVexConfigInput,        0 },
  49. };
  50.  
  51. //Motor configuration
  52. static  vexMotorCfg mConfig[kVexMotorNum] = {
  53.  
  54.         { kVexMotor_1,      kVexMotor393T,      kVexMotorNormal,        kVexSensorNone,         0 },
  55.         { kVexMotor_2,      kVexMotor393S,      kVexMotorNormal,        kVexSensorNone,         0 },
  56.         { kVexMotor_3,      kVexMotor393T,      kVexMotorNormal,        kVexSensorNone,         0 },
  57.         { kVexMotor_4,      kVexMotor393T,      kVexMotorNormal,        kVexSensorIME,          kImeChannel_1 },
  58.         { kVexMotor_5,      kVexMotor393T,      kVexMotorNormal,        kVexSensorIME,          kImeChannel_2 },
  59.         { kVexMotor_6,      kVexMotor393T,      kVexMotorNormal,        kVexSensorNone,         0 },
  60.         { kVexMotor_7,      kVexMotor393T,      kVexMotorNormal,        kVexSensorNone,         0 },
  61.         { kVexMotor_8,      kVexMotor393T,      kVexMotorNormal,        kVexSensorNone,         0 },
  62.         { kVexMotor_9,      kVexMotor393T,      kVexMotorNormal,        kVexSensorNone,         0 },
  63.         { kVexMotor_10,     kVexMotor393T,      kVexMotorNormal,        kVexSensorNone,         0 }
  64. };
  65.  
  66. //Global variables
  67.  
  68. //Global constants
  69.  
  70. /**
  71.  * @brief
  72.  * User setup
  73.  * @details
  74.  * The digital and motor ports can (should) be configured here.
  75.  */
  76. void vexUserSetup()
  77. {
  78.     vexDigitalConfigure(dConfig, DIG_CONFIG_SIZE( dConfig));
  79.     vexMotorConfigure(mConfig, MOT_CONFIG_SIZE( mConfig));
  80. }
  81.  
  82. /**
  83.  * @brief
  84.  * User initialize
  85.  * @details
  86.  * This function is called after all setup is complete and communication has
  87.  * been established with the master processor.
  88.  * Start other tasks and initialize user variables here.
  89.  */
  90. void vexUserInit()
  91. {
  92.  
  93. }
  94.  
  95.  
  96. /**
  97.  * @brief
  98.  * Autonomous
  99.  * @details
  100.  * This thread is started when the autonomous period is started.
  101.  */
  102. msg_t vexAutonomous(void *arg)
  103. {
  104.     (void)arg;
  105.  
  106.     // Must call this
  107.     vexTaskRegister("auton");
  108.  
  109.     //Auton code goes here. It is advisable to have the routine written in a separate function.
  110.  
  111.     return (msg_t)0;
  112. }
  113.  
  114. /**
  115.  * @brief
  116.  * Driver Control
  117.  * @details
  118.  * This thread is started when the driver control period is started.
  119.  */
  120. msg_t vexOperator(void *arg)
  121. {
  122.     (void)arg;
  123.  
  124.     // Must call this
  125.     vexTaskRegister("operator");
  126.  
  127.     while(!chThdShouldTerminate())
  128.     {
  129.        
  130.  
  131.         //Driver control code goes here.
  132.    
  133.  
  134.  
  135.         //Don't hog CPU from other tasks
  136.         vexSleep(20);
  137.     }
  138.    
  139.     return (msg_t)0;
  140. }
Add Comment
Please, Sign In to add comment