Advertisement
iAndr0idOs

PROS/ConVEX Toss Up Code 1

Sep 2nd, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.05 KB | None | 0 0
  1. /*-----------------------------------------------------------------------------*/
  2. /*                                                                             */
  3. /*                        Copyright (c) James Pearman                          */
  4. /*                                   2013                                      */
  5. /*                            All Rights Reserved                              */
  6. /*                                                                             */
  7. /*-----------------------------------------------------------------------------*/
  8. /*                                                                             */
  9. /*    Module:     vexuser.c                                                    */
  10. /*    Author:     James Pearman                                                */
  11. /*    Created:    7 May 2013                                                   */
  12. /*                                                                             */
  13. /*    Revisions:                                                               */
  14. /*                V1.00  04 July 2013 - Initial release                        */
  15. /*                                                                             */
  16. /*-----------------------------------------------------------------------------*/
  17. /*                                                                             */
  18. /*    The author is supplying this software for use with the VEX cortex        */
  19. /*    control system. This file can be freely distributed and teams are        */
  20. /*    authorized to freely use this program , however, it is requested that    */
  21. /*    improvements or additions be shared with the Vex community via the vex   */
  22. /*    forum.  Please acknowledge the work of the authors when appropriate.     */
  23. /*    Thanks.                                                                  */
  24. /*                                                                             */
  25. /*    Licensed under the Apache License, Version 2.0 (the "License");          */
  26. /*    you may not use this file except in compliance with the License.         */
  27. /*    You may obtain a copy of the License at                                  */
  28. /*                                                                             */
  29. /*      http://www.apache.org/licenses/LICENSE-2.0                             */
  30. /*                                                                             */
  31. /*    Unless required by applicable law or agreed to in writing, software      */
  32. /*    distributed under the License is distributed on an "AS IS" BASIS,        */
  33. /*    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
  34. /*    See the License for the specific language governing permissions and      */
  35. /*    limitations under the License.                                           */
  36. /*                                                                             */
  37. /*    The author can be contacted on the vex forums as jpearman                */
  38. /*    or electronic mail using jbpearman_at_mac_dot_com                        */
  39. /*    Mentor for team 8888 RoboLancers, Pasadena CA.                           */
  40. /*                                                                             */
  41. /*-----------------------------------------------------------------------------*/
  42.  
  43. #include <stdlib.h>
  44.  
  45. #include "ch.h"         // needs for all ChibiOS programs
  46. #include "hal.h"        // hardware abstraction layer header
  47. #include "vex.h"        // vex library header
  48.  
  49. // Digi IO configuration
  50. static  vexDigiCfg  dConfig[kVexDigital_Num] = {
  51.         { kVexDigital_1,    kVexSensorDigitalOutput, kVexConfigOutput,      0 },
  52.         { kVexDigital_2,    kVexSensorDigitalOutput, kVexConfigOutput,      0 },
  53.         { kVexDigital_3,    kVexSensorDigitalInput,  kVexConfigInput,       0 },
  54.         { kVexDigital_4,    kVexSensorDigitalInput,  kVexConfigInput,       0 },
  55.         { kVexDigital_5,    kVexSensorDigitalInput,  kVexConfigInput,       0 },
  56.         { kVexDigital_6,    kVexSensorDigitalInput,  kVexConfigInput,       0 },
  57.         { kVexDigital_7,    kVexSensorDigitalInput,  kVexConfigInput,       0 },
  58.         { kVexDigital_8,    kVexSensorDigitalInput,  kVexConfigInput,       0 },
  59.         { kVexDigital_9,    kVexSensorDigitalInput,  kVexConfigInput,       0 },
  60.         { kVexDigital_10,   kVexSensorDigitalInput,  kVexConfigInput,       0 },
  61.         { kVexDigital_11,   kVexSensorDigitalInput,  kVexConfigInput,       0 },
  62.         { kVexDigital_12,   kVexSensorDigitalInput,  kVexConfigInput,       0 }
  63. };
  64.  
  65. static  vexMotorCfg mConfig[kVexMotorNum] = {
  66.         { kVexMotor_1,      kVexMotor393T,           kVexMotorNormal,           kVexSensorNone,        0 },
  67.         { kVexMotor_2,      kVexMotor393S,           kVexMotorNormal,           kVexSensorNone,        0 },
  68.         { kVexMotor_3,      kVexMotor393S,           kVexMotorNormal,           kVexSensorNone,        0 },
  69.         { kVexMotor_4,      kVexMotor393S,           kVexMotorNormal,           kVexSensorNone,        0 },
  70.         { kVexMotor_5,      kVexMotor393S,           kVexMotorReversed,         kVexSensorNone,        0 },
  71.         { kVexMotor_6,      kVexMotor393S,           kVexMotorNormal,           kVexSensorNone,        0 },
  72.         { kVexMotor_7,      kVexMotor393S,           kVexMotorReversed,         kVexSensorNone,        0 },
  73.         { kVexMotor_8,      kVexMotor393T,           kVexMotorReversed,         kVexSensorNone,        0 },
  74.         { kVexMotor_9,      kVexMotor393T,           kVexMotorNormal,           kVexSensorNone,        0 },
  75.         { kVexMotor_10,     kVexMotor393T,           kVexMotorReversed,         kVexSensorNone,        0 }
  76. };
  77.  
  78. const int MOTOR_RIGHT_ARM = 1;
  79. const int MOTOR_LEFT_1 = 2;
  80. const int MOTOR_LEFT_2 = 3;
  81. const int MOTOR_LEFT_3 = 4;
  82. const int MOTOR_RIGHT_3 = 5;
  83. const int MOTOR_RIGHT_2 = 6;
  84. const int MOTOR_RIGHT_1 = 7;
  85. const int MOTOR_INTAKE_RIGHT = 8;
  86. const int MOTOR_INTAKE_LEFT = 9;
  87. const int MOTOR_LEFT_ARM = 10;
  88.  
  89. const int SENSOR_PISTON_1 = 1;
  90. const int SENSOR_PISTON_2 = 2;
  91.  
  92. /*-----------------------------------------------------------------------------*/
  93. /** @brief      User setup                                                     */
  94. /*-----------------------------------------------------------------------------*/
  95. /** @details
  96.  *  The digital and motor ports can (should) be configured here.
  97.  */
  98. void
  99. vexUserSetup()
  100. {
  101.     vexDigitalConfigure( dConfig, DIG_CONFIG_SIZE( dConfig ) );
  102.     vexMotorConfigure( mConfig, MOT_CONFIG_SIZE( mConfig ) );
  103. }
  104.  
  105. /*-----------------------------------------------------------------------------*/
  106. /** @brief      User initialize                                                */
  107. /*-----------------------------------------------------------------------------*/
  108. /** @details
  109.  *  This function is called after all setup is complete and communication has
  110.  *  been established with the master processor.
  111.  *  Start other tasks and initialize user variables here
  112.  */
  113. void
  114. vexUserInit()
  115. {
  116.  
  117. }
  118.  
  119. /*-----------------------------------------------------------------------------*/
  120. /** @brief      Autonomous                                                     */
  121. /*-----------------------------------------------------------------------------*/
  122. /** @details
  123.  *  This thread is started when the autonomous period is started
  124.  */
  125. msg_t
  126. vexAutonomous( void *arg )
  127. {
  128.     (void)arg;
  129.  
  130.     // Must call this
  131.     vexTaskRegister("auton");
  132.  
  133.     while(1)
  134.         {
  135.         // Don't hog cpu
  136.         vexSleep( 25 );
  137.         }
  138.  
  139.     return (msg_t)0;
  140. }
  141.  
  142. #define MotorDriveL     kVexMotor_1
  143. #define MotorDriveR     kVexMotor_10
  144.  
  145. /*-----------------------------------------------------------------------------*/
  146. /** @brief      Driver control                                                 */
  147. /*-----------------------------------------------------------------------------*/
  148. /** @details
  149.  *  This thread is started when the driver control period is started
  150.  */
  151. msg_t
  152. vexOperator( void *arg )
  153. {
  154.     int16_t     blink = 0;
  155.  
  156.     (void)arg;
  157.  
  158.     // Must call this
  159.     vexTaskRegister("operator");
  160.  
  161.  
  162.  
  163.     // Run until asked to terminate
  164.     while(!chThdShouldTerminate())
  165.         {
  166.  
  167.         tankDrive(vexControllerGet(Ch3),vexControllerGet(Ch2));
  168.  
  169.         vexMotorSet(MOTOR_RIGHT_ARM,(vexControllerGet(Btn5U)-vexControllerGet(Btn5D))*127+16);
  170.         vexMotorSet(MOTOR_LEFT_ARM,(vexControllerGet(Btn5U)-vexControllerGet(Btn5D))*127+16);
  171.  
  172.         vexMotorSet(MOTOR_INTAKE_RIGHT,(vexControllerGet(Btn6U)-vexControllerGet(Btn6D))*127+16);
  173.         vexMotorSet(MOTOR_INTAKE_LEFT,(vexControllerGet(Btn6U)-vexControllerGet(Btn6D))*127+16);
  174.  
  175.         if(vexControllerGet(Btn8U)) {
  176.             vexDigitalPinSet(SENSOR_PISTON_1,1);
  177.             vexDigitalPinSet(SENSOR_PISTON_2,1);
  178.         }
  179.         if(vexControllerGet(Btn8D)) {
  180.             vexDigitalPinSet(SENSOR_PISTON_1,0);
  181.             vexDigitalPinSet(SENSOR_PISTON_2,0);
  182.         }
  183.  
  184.         // Don't hog cpu
  185.         vexSleep( 25 );
  186.         }
  187.  
  188.     return (msg_t)0;
  189. }
  190.  
  191. void
  192. tankDrive(int left, int right) {
  193.  
  194.     vexMotorSet(MOTOR_LEFT_1,left);
  195.     vexMotorSet(MOTOR_LEFT_2,left);
  196.     vexMotorSet(MOTOR_LEFT_3,left);
  197.     vexMotorSet(MOTOR_RIGHT_1,right);
  198.     vexMotorSet(MOTOR_RIGHT_2,right);
  199.     vexMotorSet(MOTOR_RIGHT_3,right);
  200.  
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement