-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmindsensors-ps2ctrl-v4-test3.c
115 lines (99 loc) · 3.52 KB
/
mindsensors-ps2ctrl-v4-test3.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
#pragma config(Sensor, S1, PSPNXV4, sensorI2CCustomFastSkipStates)
#pragma config(Sensor, S2, LASER1, sensorAnalogActive)
#pragma config(Sensor, S3, LASER2, sensorAnalogActive)
#pragma config(Motor, motorA, ARMS, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorB, RIGHT, tmotorNormal, PIDControl, reversed, encoder)
#pragma config(Motor, motorC, LEFT, tmotorNormal, PIDControl, reversed, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/*
* $Id: mindsensors-ps2ctrl-v4-test3.c 133 2013-03-10 15:15:38Z xander $
*/
/**
* mindsensors-ps2ctrl-v4.h provides an API for the Mindsensors PS2 controller sensor
* with referee signal receiver. This program demonstrates how to use that API
*
* Changelog:
* - 0.1: Initial release
*
* 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)
* 02 August 2012
* version 0.1
*/
#include "drivers/mindsensors-ps2ctrl-v4.h"
#define RAW_RIGHT 0x45B
#define RAW_LEFT 0x45A
#define RAW_FWD 0x458
#define RAW_REV 0x459
#define RAW_STOP 0x45C
#define goBotRight() moveBot(-20, 20)
#define goBotLeft() moveBot(20, -20)
#define goBotFwd() moveBot(50, 50)
#define goBotRev() moveBot(-50, -50)
#define goBotStop() moveBot(0, 0)
void moveBot(int speedRight, int speedLeft)
{
motor[RIGHT] = speedRight;
motor[LEFT] = speedLeft;
}
task main ()
{
ubyte counter = 0;
ubyte oldCounter = 0;
long rawValue = 0;
long oldRawValue = 0;
nxtDisplayCenteredTextLine(0, "Mindsensors");
nxtDisplayCenteredBigTextLine(1, "PSP-Nx");
nxtDisplayCenteredTextLine(3, "Test 3");
wait1Msec(2000);
PlaySound(soundBeepBeep);
while(bSoundActive) EndTimeSlice();
eraseDisplay();
while (true)
{
// Get the current counter value, wraps at 255
counter = PSPV4readRefSignalCount(PSPNXV4);
if (oldCounter != counter)
{
// Raw value will also "see" commands from the remote
// that are not recognised as "play", "stop", "forward" or "rewind".
// You could use this to control additional aspects of your robot!
rawValue = PSPV4readRawRefTXValue(PSPNXV4);
if (oldRawValue != rawValue)
{
PlaySound(soundShortBlip);
switch(rawValue)
{
case RAW_RIGHT: nxtDisplayCenteredBigTextLine(3, "RIGHT");
goBotRight();
break;
case RAW_LEFT: nxtDisplayCenteredBigTextLine(3, "LEFT");
goBotLeft();
break;
case RAW_FWD: nxtDisplayCenteredBigTextLine(3, "FWD");
goBotFwd();
break;
case RAW_REV: nxtDisplayCenteredBigTextLine(3, "REV");
goBotRev();
break;
case RAW_STOP: nxtDisplayCenteredBigTextLine(3, "STOP");
goBotStop();
break;
}
}
nxtDisplayTextLine(7, "Raw: 0x%03X", rawValue);
// Update the counters and signals
oldCounter = counter;
oldRawValue = rawValue;
}
wait1Msec(50);
}
}
/*
* $Id: mindsensors-ps2ctrl-v4-test3.c 133 2013-03-10 15:15:38Z xander $
*/