-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMotor Test.c
More file actions
105 lines (81 loc) · 5.6 KB
/
Motor Test.c
File metadata and controls
105 lines (81 loc) · 5.6 KB
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
#pragma config(Sensor, dgtl1, feedbackEncoder, sensorQuadEncoder)
#pragma config(Motor, port1, testMotor, tmotorVex393_HBridge, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/*----------------------------------------------------------------------------------------------------*\
|* - Test Motor Functionality - *|
|* Written in ROBOTC 4.56 for the VEX CORTEX *|
|* *|
|* AUTHOR: Mahesh Chugani *|
|* DATE CREATED: Nov 24, 2017 *|
|* STATUS: beginning, IN PROGRESS, working, enhancements *|
|* *|
|* MODIFIED BY: (enter your name here if you modify this file) *|
|* *|
|* DESCRIPTION *|
|* *|
|* This program tests a motor at various power levels, in both forward & reverse directions. *|
|* The user should use the RobotC datalogger (in the debugger) to record & save (1) the motor power *|
|* and (2) the encoder values, to a *.csv file. This file is then uploaded into a LabVIEW program *|
|* (Read RobotC MotorTest Datalog File.vi) for analysis and display. *|
|* *|
|* ROBOT CONFIGURATION *|
|* NOTES: *|
|* 1) The Test Motor is connected to Motor Port 2 of Cortex. *|
|* *|
|* 2) Encoder that is being used for feedback should be cleared __each time__ before it starts *|
|* counting by using "SensorValue[feedbackEncoder] = 0;". *|
|* *|
|* MOTORS & SENSORS: *|
|* [I/O Port] [Name] [Type] [ Description] *|
|* Motor - Port 2 testMotor VEX 3-wire module Test Motor *|
|* Digital - Port 1,2 feedbackEncoder VEX Shaft Encoder Connected to Test Motor *|
|* *|
\*----------------------------------------------------------------------------------------------------*/
//+++++++++++++++++++++++++++++++++++++++++++++| MAIN |++++++++++++++++++++++++++++++++++++++++++++
/* ************ Record Data for 5 rotations ************ */
void recordData( )
{
// clear Encoder
SensorValue[feedbackEncoder] = 0;
// Wait for 5 rotations = 1800 counts on Encoder (1 rotation = 360 counts)
while(abs(SensorValue[feedbackEncoder]) < 1800)
{
// do nothing while datalogger is recording data.
}
}
task main()
{
// Define power levels at which to test motor. Power values range from -127 to +127
int noPower = 0; // 0% power
int quarterPower = 32; // 25% power
int halfPower = 64; // 50% power
int threeFourthsPower = 96; // 75% power
int fullPower = 127; // 100% power
wait1Msec(2000); // 2 second delay before starting
datalogClear(); // clear the datalog for recording
/* ---------- Test motor rotation in one direction (clockwise or anticlockwise) ----------*/
motor[testMotor] = noPower; // start with motor stopped
wait1Msec(1000); // rest period to make sure motor is stopped
motor[testMotor] = quarterPower; // run motor at 25% power
recordData();
motor[testMotor] = halfPower; // run motor at 50% power
recordData();
motor[testMotor] = threeFourthsPower; // run motor 75% power
recordData();
motor[testMotor] = fullPower; // give motor 100% power
recordData();
/* -------- Test motor rotation in opposite direction (antilockwise or clockwise) --------*/
motor[testMotor] = noPower; // stop the motor
wait1Msec(1000); // rest period to make sure motor is stopped
motor[testMotor] = -quarterPower; // run motor at 25% power
recordData();
motor[testMotor] = -halfPower; // run motor at 50% power
recordData();
motor[testMotor] = -threeFourthsPower; // run motor 75% power
recordData();
motor[testMotor] = -fullPower; // give motor 100% power
recordData();
motor[testMotor] = noPower; // stop the motor
wait1Msec(1000); // rest period to make sure motor is stopped
}
//++++++++++++++++++++++++++++++++++++ END OF MOTOR TEST PROGRAM ++++++++++++++++++++++++++++++++++