This repository has been archived by the owner on Dec 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvexuser.c
179 lines (159 loc) · 8.67 KB
/
vexuser.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*-----------------------------------------------------------------------------*/
/* */
/* Copyright (c) James Pearman */
/* 2013 */
/* All Rights Reserved */
/* */
/*-----------------------------------------------------------------------------*/
/* */
/* Module: vexuser.c */
/* Author: James Pearman */
/* Created: 7 May 2013 */
/* */
/* Revisions: */
/* V1.00 XX XXX 2013 - Initial release */
/* */
/*-----------------------------------------------------------------------------*/
/* */
/* The author is supplying this software for use with the VEX cortex */
/* control system. This file can be freely distributed and teams are */
/* authorized to freely use this program , however, it is requested that */
/* improvements or additions be shared with the Vex community via the vex */
/* forum. Please acknowledge the work of the authors when appropriate. */
/* Thanks. */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); */
/* you may not use this file except in compliance with the License. */
/* You may obtain a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* */
/* The author can be contacted on the vex forums as jpearman */
/* or electronic mail using jbpearman_at_mac_dot_com */
/* Mentor for team 8888 RoboLancers, Pasadena CA. */
/* */
/*-----------------------------------------------------------------------------*/
#include <stdlib.h>
#include "ch.h" // needs for all ChibiOS programs
#include "hal.h" // hardware abstraction layer header
#include "vex.h" // vex library header
void setMotors(int speed);
// Digi IO configuration
static vexDigiCfg dConfig[kVexDigital_Num] = {
{ kVexDigital_1, kVexSensorDigitalOutput, kVexConfigOutput, 0 },
{ kVexDigital_2, kVexSensorDigitalOutput, kVexConfigOutput, 0 },
{ kVexDigital_3, kVexSensorDigitalInput, kVexConfigInput, 0 },
{ kVexDigital_4, kVexSensorDigitalInput, kVexConfigInput, 0 },
{ kVexDigital_5, kVexSensorDigitalInput, kVexConfigInput, 0 },
{ kVexDigital_6, kVexSensorDigitalInput, kVexConfigInput, 0 },
{ kVexDigital_7, kVexSensorDigitalInput, kVexConfigInput, 0 },
{ kVexDigital_8, kVexSensorDigitalInput, kVexConfigInput, 0 },
{ kVexDigital_9, kVexSensorDigitalInput, kVexConfigInput, 0 },
{ kVexDigital_10, kVexSensorDigitalInput, kVexConfigInput, 0 },
{ kVexDigital_11, kVexSensorDigitalInput, kVexConfigInput, 0 },
{ kVexDigital_12, kVexSensorDigitalInput, kVexConfigInput, 0 }
};
static vexMotorCfg mConfig[kVexMotorNum] = {
{ kVexMotor_1, kVexMotorUndefined, kVexMotorNormal, kVexSensorNone, 0 },
{ kVexMotor_2, kVexMotorUndefined, kVexMotorReversed, kVexSensorNone, 0 },
{ kVexMotor_3, kVexMotorUndefined, kVexMotorNormal, kVexSensorNone, 0 },
{ kVexMotor_4, kVexMotorUndefined, kVexMotorNormal, kVexSensorNone, 0 },
{ kVexMotor_5, kVexMotorUndefined, kVexMotorNormal, kVexSensorNone, 0 },
{ kVexMotor_6, kVexMotorUndefined, kVexMotorNormal, kVexSensorNone, 0 },
{ kVexMotor_7, kVexMotorUndefined, kVexMotorNormal, kVexSensorNone, 0 },
{ kVexMotor_8, kVexMotorUndefined, kVexMotorNormal, kVexSensorNone, 0 },
{ kVexMotor_9, kVexMotorUndefined, kVexMotorNormal, kVexSensorNone, 0 },
{ kVexMotor_10, kVexMotorUndefined, kVexMotorNormal, kVexSensorNone, 0 }
};
/*-----------------------------------------------------------------------------*/
/** @brief User setup */
/*-----------------------------------------------------------------------------*/
/** @details
* The digital and motor ports can (should) be configured here.
*/
void
vexUserSetup()
{
vexDigitalConfigure( dConfig, DIG_CONFIG_SIZE( dConfig ) );
vexMotorConfigure( mConfig, MOT_CONFIG_SIZE( mConfig ) );
}
/*-----------------------------------------------------------------------------*/
/** @brief User initialize */
/*-----------------------------------------------------------------------------*/
/** @details
* This function is called after all setup is complete and communication has
* been established with the master processor.
* Start other tasks and initialize user variables here
*/
void
vexUserInit()
{
}
/*-----------------------------------------------------------------------------*/
/** @brief Autonomous */
/*-----------------------------------------------------------------------------*/
/** @details
* This thread is started when the autonomous period is started
*/
msg_t
vexAutonomous( void *arg )
{
(void)arg;
// Must call this
vexTaskRegister("auton");
while(1)
{
// Don't hog cpu
vexSleep( 25 );
}
return (msg_t)0;
}
#define UpperLeftMotor kVexMotor_2
#define LowerLeftMotor kVexMotor_3
#define UpperRightMotor kVexMotor_4
#define LowerRightMotor kVexMotor_5
/*-----------------------------------------------------------------------------*/
/** @brief Driver control */
/*-----------------------------------------------------------------------------*/
/** @details
* This thread is started when the driver control period is started
*/
msg_t
vexOperator( void *arg )
{
(void)arg;
// Must call this
vexTaskRegister("operator");
// Run until asked to terminate
while(!chThdShouldTerminate())
{
if(vexControllerGet(Btn6U) == 0 && vexControllerGet(Btn6D) == 0)
setMotors(vexControllerGet(Ch3));// analog control of motors with left joystick y axis
else if(vexControllerGet(Btn6D) == 0)
setMotors(vexControllerGet(Btn6U)*127); // right bumper up
else{
setMotors(-vexControllerGet(Btn6D)*127); // right bumber down
}
// Don't hog cpu
vexSleep( 25 );
}
return (msg_t)0;
}
/*-----------------------------------------------------------------------------*/
/** @brief Motor Speeds */
/*-----------------------------------------------------------------------------*/
/** @details
* Just sets the speed of each motor
*/
void setMotors(int speed){
vexMotorSet(UpperRightMotor, speed);
vexMotorSet(LowerRightMotor, speed);
vexMotorSet(UpperLeftMotor, speed);
vexMotorSet(LowerLeftMotor, speed);
}