-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmindsensors-pfmate-test1.c
130 lines (110 loc) · 3.87 KB
/
mindsensors-pfmate-test1.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
#pragma config(Sensor, S1, MSPFM, sensorI2CCustom)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/*
* $Id: mindsensors-pfmate-test1.c 133 2013-03-10 15:15:38Z xander $
*/
/**
* mindsensors-pfmate.h provides an API for the Mindsensors PFMate. This program
* demonstrates how to use that API.
*
* Changelog:
* - 0.1: Initial release
* - 0.2: More comments
*
* Credits:
* - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
*
* License: You may use this code as you wish, provided you give credit where it's due.
*
* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER.
* Xander Soldaat (xander_at_botbench.com)
* 28 November 2009
* version 0.2
*/
#include "drivers/mindsensors-pfmate.h"
void doTest(int channel) {
nxtDisplayTextLine(5, "Chan: %d", channel);
// -------- testing motor A -----------------------
PlaySound(soundBeepBeep);
while(bSoundActive) EndTimeSlice();
nxtDisplayTextLine(6, "Motor: A");
nxtDisplayTextLine(7, "Dir: fwd");
for (int speed = 1; speed < 8; speed++) {
// Run motor A forward from speed 1 to 7
MSPFMcontrolMotorA(MSPFM, channel, MSPFM_FORWARD, speed);
wait1Msec(500);
}
nxtDisplayTextLine(7, "Dir: brake");
// Brake the motor
MSPFMcontrolMotorA(MSPFM, channel, MSPFM_BRAKE, 0);
wait1Msec(500);
nxtDisplayTextLine(7, "Dir: rev");
for (int speed = 1; speed < 8; speed++) {
// Run motor A in reverse from speed 1 to 7
MSPFMcontrolMotorA(MSPFM, channel, MSPFM_REVERSE, speed);
wait1Msec(500);
}
nxtDisplayTextLine(7, "Dir: float");
// Set motor A to float
MSPFMcontrolMotorA(MSPFM, channel, MSPFM_FLOAT, 0);
wait1Msec(500);
// -------- testing motor B -----------------------
PlaySound(soundBeepBeep);
while(bSoundActive) EndTimeSlice();
nxtDisplayTextLine(6, "Motor: B");
nxtDisplayTextLine(7, "Dir: fwd");
for (int speed = 1; speed < 8; speed++) {
// Run motor B forward from speed 1 to 7
MSPFMcontrolMotorB(MSPFM, channel, MSPFM_FORWARD, speed);
wait1Msec(500);
}
nxtDisplayTextLine(7, "Dir: brake");
MSPFMcontrolMotorB(MSPFM, channel, MSPFM_BRAKE, 0);
wait1Msec(500);
nxtDisplayTextLine(7, "Dir: rev");
for (int speed = 1; speed < 8; speed++) {
// Run motor B in reverse from speed 1 to 7
MSPFMcontrolMotorB(MSPFM, channel, MSPFM_REVERSE, speed);
wait1Msec(500);
}
nxtDisplayTextLine(7, "Dir: float");
MSPFMcontrolMotorB(MSPFM, channel, MSPFM_FLOAT, 0);
wait1Msec(500);
// -------- testing motor A+B -----------------------
PlaySound(soundBeepBeep);
while(bSoundActive) EndTimeSlice();
nxtDisplayTextLine(6, "Motor: A+B");
nxtDisplayTextLine(7, "Dir: fwd+rev");
for (int speed = 1; speed < 8; speed++) {
// Run motor A forward and motor B in reverse from speed 1 to 7
MSPFMcontrolMotorAB(MSPFM, channel, MSPFM_FORWARD, speed, MSPFM_REVERSE, speed);
wait1Msec(500);
}
nxtDisplayTextLine(7, "Dir: brake");
// brake both motors A and B
MSPFMcontrolMotorAB(MSPFM, channel, MSPFM_BRAKE, 0, MSPFM_BRAKE, 0);
wait1Msec(500);
nxtDisplayTextLine(7, "Dir: rev+fwd");
for (int speed = 1; speed < 8; speed++) {
// Run motor A in revese and motor B forward from speed 1 to 7
MSPFMcontrolMotorAB(MSPFM, channel, MSPFM_REVERSE, speed, MSPFM_FORWARD, speed);
wait1Msec(500);
}
nxtDisplayTextLine(7, "Dir: float");
// Put both motors in float
MSPFMcontrolMotorAB(MSPFM, channel, MSPFM_FLOAT, 0, MSPFM_FLOAT, 0);
wait1Msec(500);
}
task main() {
nxtDisplayCenteredTextLine(0, "Mindsensors");
nxtDisplayCenteredBigTextLine(1, "PFMate");
nxtDisplayCenteredTextLine(3, "Test 1");
wait1Msec(2000);
// Run through each channel for testing.
for (int channel = 1; channel < 5; channel++) {
doTest(channel);
}
}
/*
* $Id: mindsensors-pfmate-test1.c 133 2013-03-10 15:15:38Z xander $
*/