-
Notifications
You must be signed in to change notification settings - Fork 0
/
KombatWombat_2.c5.c
116 lines (95 loc) · 3.01 KB
/
KombatWombat_2.c5.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
#pragma config(Motor, port1, harvester_1, tmotorVex393_HBridge, openLoop, reversed)
#pragma config(Motor, port2, left_drive, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port3, right_drive, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, launch_motor_1, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port5, launch_motor_2, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port6, claw_roll, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, left_lift, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port8, right_lift, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port9, claw_pitch, tmotorVex393_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#define LaunchForwards Btn5U
#define LaunchBackwards Btn5D
#define DriveSteer Ch1
#define DriveForward Ch3
#define ArmUp Btn6U
#define ArmDown Btn6D
#define HarvesterToggle Btn7U
#define ClawRotateLeft Btn8LXmtr2
#define ClawRotateRight Btn8RXmtr2
#define ClawPitchUp Btn8UXmtr2
#define ClawPitchDown Btn8DXmtr2
///////////Macros///////////
#define sign(value) (value >= 0 ? 1 : -1)
#define max(a,b) (a > b ? a : b)
///////////Variables///////////
bool lastButtonState = false;
bool state = false;
void SetLiftPower(int power){
motor[left_lift] = power;
motor[right_lift] = power;
}
///////////Drive///////////
float get_power(float controller_input)
{
float controller_sign = sign(controller_input);
float new_input = controller_input * controller_sign;
new_input = max(0.0, new_input - 0.15) / (1.0 - 0.15);
return controller_sign * new_input;
}
float get_joystick_axis(int index)
{
float maximum_range = vexRT[index] > 0 ? 127.0 : 128.0;
float joy_pos = (float)vexRT[index];
return joy_pos / maximum_range;
}
void set_motor_speed(int _motor, float speed)
{
if (speed > 1.0) speed = 1.0;
if (speed < -1.0) speed = -1.0;
int maximum_speed = 127;
int motor_speed = maximum_speed * speed;
motor[_motor] = motor_speed;
}
void update_drive () {
float forward_power = get_power(get_joystick_axis(DriveSteer));
float steer_power = get_power(get_joystick_axis(DriveForward));
float left_power = forward_power + steer_power;
float right_power = forward_power - steer_power;
set_motor_speed(left_drive, left_power);
set_motor_speed(right_drive, right_power);
}
task main()
{
while(true)
{
////Assign Button///////
bool BtnArmUp = (bool)vexRT[ArmUp];
bool BtnArmDown = (bool)vexRT[ArmDown];
update_drive();
//////Harvester/////
bool buttonState = (bool)(vexRT[HarvesterToggle]);
if (buttonState && !lastButtonState){
state = !state;
}
if (buttonState != lastButtonState){
lastButtonState = buttonState;
}
if (state){
motor[harvester_1] = 100;
}
else {
motor[harvester_1] = 0;
}
//////ArmLift//////
if (BtnArmUp){
SetLiftPower(127);
}
else if (BtnArmDown){
SetLiftPower(-127);
}
else {
SetLiftPower(0);
}
}
}