-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctdrive.c
74 lines (61 loc) · 2.42 KB
/
ctdrive.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
#pragma config(Hubs, S4, HTMotor, HTMotor, HTServo, none)
#pragma config(Sensor, S1, HTDIR, sensorHiTechnicIRSeeker1200)
#pragma config(Sensor, S2, TOUCH, sensorTouch)
#pragma config(Sensor, S3, HTDIR, sensorHiTechnicIRSeeker1200)
#pragma config(Sensor, S4, , sensorI2CMuxController)
#pragma config(Motor, mtr_S4_C1_1, motorD, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S4_C1_2, motorE, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S4_C2_1, motorF, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S4_C2_2, motorG, tmotorTetrix, openLoop)
#pragma config(Servo, srvo_S4_C3_1, servo1, tServoStandard)
#pragma config(Servo, srvo_S4_C3_2, servo2, tServoNone)
#pragma config(Servo, srvo_S4_C3_3, servo3, tServoNone)
#pragma config(Servo, srvo_S4_C3_4, servo4, tServoNone)
#pragma config(Servo, srvo_S4_C3_5, servo5, tServoNone)
#pragma config(Servo, srvo_S4_C3_6, servo6, tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#include "JoystickDriver.c" //Include file to "handle" the Bluetooth messages.
int cleanup(int x) {
const int threshold = 10;
if (x > threshold)
return (x - threshold) * (x - threshold) / 128;
if (x < -threshold)
return (x + threshold) * (x + threshold) / -128;
return 0;
}
void initializeRobot()
{
return;
}
task main()
{
initializeRobot();
waitForStart();
nxtDisplayString(0, "Zip tie time!...");
float servostate = servo[servo1];
float clawDivisor = 300;
while (true)
{
getJoystickSettings(joystick);
nxtDisplayString(1, "x:%d y:%d", joystick.joy1_x1, joystick.joy1_y1);
nxtDisplayString(2, "x:%d y:%d", joystick.joy1_x2, joystick.joy1_y2);
int left = cleanup(joystick.joy1_y1);
int right = cleanup(joystick.joy1_y2);
int center = cleanup(joystick.joy2_y1)/5;
motor[motorD] = right;
motor[motorE] = -left;
motor[motorF] = center;
motor[motorG] = -center;
int s = cleanup (joystick.joy2_y2);
float new_servostate = servostate - s / clawDivisor;
if (new_servostate < 0){
new_servostate = 0;
}
if (new_servostate > 255){
new_servostate = 255;
}
servostate = new_servostate;
servo[servo1] = (int) servostate;
bFloatDuringInactiveMotorPWM = false;
}
}