ASMESDC2018
/home/swerve/Github/sdc_2018/omni_robot/OffenseRobot.cpp
Go to the documentation of this file.
1 
8 #include <Arduino.h>
9 
10 #include "Logger.h"
11 #include "OffenseRobot.h"
12 
13 /* CONSTRUCTOR FUNCTIONS */
15  shoot_left( MOTOR_TYPE_BLDC, PIN_PWM_SHOOT_LEFT),
18 
19 }
20 
21 /* PUBLIC FUNCTIONS */
23 
24  // Initialized Variables
25  int pusher_input; // input for actuating the linear actuator
26  int shoot_input; // input for actuating the shoot motors
27 
28  // Get pusher and shoot input from controller
29  cli();
30  pusher_input = rc_controller.state.value_ch_3;
31  shoot_input = rc_controller.state.value_ch_5;
32  sei();
33 
34  // Map pusher input into relevant values
35  pusher_input = map(pusher_input, PUSHER_INPUT_MIN, CH_VALUE_MAP_MAX, PUSHER_OUTPUT_MIN, PUSHER_OUTPUT_MAX);
36  pusher_input = constrain(pusher_input, PUSHER_OUTPUT_MIN, PUSHER_OUTPUT_MAX);
37  shooter_state.position = (pusher_input/10)*10; // set the last digit to zero to avoid moving actuator too much
38 
39  // shooter_state.speed = map(shoot_input, -100, 100, 1200, 1800);
40  // Map shoot input into relevant values
41  if (shoot_input > SHOOT_INPUT_CAPTURE_THRESH) {
43  } else if (shoot_input < SHOOT_INPUT_SHOOT_THRESH) {
45  } else {
47  }
48 
49  // Set pusher and shoot motrs to desired location/speed
52  delay(BLDC_DELAY);
54 
55 }
56 
58 
59  logger::displayInfo("Shooter State: " + String(shooter_state.position) + " (position) | " +
60  String(shooter_state.speed) + " (speed)");
61 
62 }
63 
65 
66  if (shoot_left.ready == false) {
67  Serial.println("Shoot left: " + String(shoot_left.ready));
69  return;
70  }
71  if (shoot_right.ready == false) {
72  Serial.println("Shoot right: " + String(shoot_right.ready));
74  return;
75  }
76 
78 
79 }
80 
81 
RCController6CH rc_controller
Definition: OmniRobot.h:106
void displayInfo(String)
int displayError(int)
Definition: Logger.cpp:36
#define SHOOT_INPUT_SHOOT_THRESH
Definition: OffenseRobot.h:25
#define BLDC_DELAY
Definition: OffenseRobot.h:13
#define MOTOR_TYPE_SERVO
Definition: Motor.h:19
OffenseRobot(void)
Default constructor.
void run(int)
Run the motor at the desired speed and direction or position.
Definition: Motor.cpp:65
#define PUSHER_INPUT_MIN
Definition: OffenseRobot.h:19
Motor shoot_left
Definition: OffenseRobot.h:73
#define COLOR_YELLOW
Definition: LED.h:15
Header file for OffenseRobot class derived from the OmniRobot class
#define BLINK_ON
Definition: LED.h:24
#define SIDE_RIGHT
Definition: LED.h:29
#define SHOOT_OUTPUT_CAPTURE
Definition: OffenseRobot.h:27
#define PUSHER_OUTPUT_MAX
Definition: OffenseRobot.h:21
RCController6CHState state
volatile int speed
Definition: OffenseRobot.h:33
#define PIN_PWM_PUSHER
Definition: OffenseRobot.h:17
volatile int value_ch_3
volatile int value_ch_5
void updateLED(void)
Updates LED colors based on robot state.
void displayShooterState(void)
Displays the shooter state.
void updateLED(void)
Updates LED colors based on robot state.
Definition: OmniRobot.cpp:93
#define MOTOR_TYPE_BLDC
Definition: Motor.h:18
#define PUSHER_OUTPUT_MIN
Definition: OffenseRobot.h:20
bool ready
Definition: Motor.h:56
#define SHOOT_OUTPUT_OFF
Definition: OffenseRobot.h:28
ShooterState shooter_state
Definition: OffenseRobot.h:71
#define CH_VALUE_MAP_MAX
Header file for error codes
void setState(int, bool blink=false, int side=SIDE_BOTH)
Definition: LED.cpp:50
#define PIN_PWM_SHOOT_RIGHT
Definition: OffenseRobot.h:16
#define SHOOT_OUTPUT_SHOOT
Definition: OffenseRobot.h:29
#define SIDE_LEFT
Definition: LED.h:28
#define SHOOT_INPUT_CAPTURE_THRESH
Definition: OffenseRobot.h:23
Motor shoot_right
Definition: OffenseRobot.h:74
void runShooter(void)
Actuates the shooter based on input from the RC controller.
#define PIN_PWM_SHOOT_LEFT
Definition: OffenseRobot.h:15
volatile int position
Definition: OffenseRobot.h:32