-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjoystick.c
More file actions
51 lines (47 loc) · 1.57 KB
/
joystick.c
File metadata and controls
51 lines (47 loc) · 1.57 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
#pragma config(Hubs, S1, HTMotor, HTServo, none, none)
#pragma config(Motor, mtr_S1_C1_1, rightMotor, tmotorTetrix, openLoop, reversed, encoder)
#pragma config(Motor, mtr_S1_C1_2, leftMotor, tmotorTetrix, openLoop, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#include "JoystickDriver.c"
/*
Converts the joystick value into a tetrix motor usable value
Parameters:
joystickVal the value that the joystick provides (-128 to +127)
Return value:
tetrix motor value (-100 to +100 (Technically only +99))
*/
int joystickToMotor(int joystickVal)
{
/*
int motorValue = 0;
// Check if joystick is in the deadzone.
if (abs(joystickVal) <= 10){
//Do nothing since motorValue is 0 by default.
return motorValue;
}
// Gradual increase in the values of the motor.
else if (abs(joystickVal) <= 64){
//Fixed to account for positive or negative joystick inputs
motorValue = ((abs(joystickVal)-10)*sgn(joystickVal))*20/54; //I would probably write a function to make this algorithm more flexible.
}
// Faster increase in the values of the motor.
else if (abs(joystickVal) <= 128){
motorValue = joystickVal*100/128;
}
return motorValue;
*/
return joystickVal*100/128;
}
task main()
{
while (true)
{
getJoystickSettings(joystick);
// Make the motors move.
motor[leftMotor] = joystickToMotor(joystick.joy1_y1);
motor[rightMotor] = joystickToMotor(joystick.joy1_y2);
string example;
StringFormat(example, "Joy: %d %d", joystick.joy1_y1, joystick.joy1_y2);
nxtDisplayTextLine(4, example);
}
}