diff --git a/.github/workflows/compile_sketch.yml b/.github/workflows/compile_sketch.yml index 315e0ae..f836560 100644 --- a/.github/workflows/compile_sketch.yml +++ b/.github/workflows/compile_sketch.yml @@ -21,3 +21,4 @@ jobs: - ./ libraries: | - name: Servo + - name: Adafruit NeoPixel diff --git a/intake.cpp b/intake.cpp deleted file mode 100644 index 0e8044f..0000000 --- a/intake.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include - -#include - -#include "intake.hpp" -#include "robot_defs.hpp" - -Intake::Intake(Servo &motor) - : motor_speed_pulse_(MOTOR_PULSE_STOP_), upper_limit_switch_(PITCHER_UPPER_LIMIT_PIN), - lower_limit_switch_(PITCHER_LOWER_LIMIT_PIN) -{ - motor_ = &motor; - motor_->attach(INTAKE_MOTOR_PIN); - motor_->writeMicroseconds(motor_speed_pulse_); -} - -Intake::~Intake() -{ - motor_->detach(); -} - -void Intake::spin() -{ - motor_speed_pulse_ = MOTOR_PULSE_FORWARD_; -} - -void Intake::stop() -{ - motor_speed_pulse_ = MOTOR_PULSE_STOP_; -} - -void Intake::tick() -{ - motor_->writeMicroseconds(motor_speed_pulse_); -} diff --git a/intake.hpp b/intake.hpp deleted file mode 100644 index 081dc32..0000000 --- a/intake.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef INTAKE_H -#define INTAKE_H - -#include - -class Intake -{ -public: - Intake(Servo &motor); - ~Intake(); - void tick(); - - void spin(); - void stop(); - -private: - unsigned int upper_limit_switch_; - unsigned int lower_limit_switch_; - - Servo *motor_; - - unsigned int motor_speed_pulse_; -}; - -#endif diff --git a/pitcher.cpp b/pitcher.cpp deleted file mode 100644 index ee62e77..0000000 --- a/pitcher.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include - -#include "pitcher.hpp" -#include "robot_defs.hpp" - -Pitcher::Pitcher(Servo &motor) : motor_speed_pulse_(MOTOR_PULSE_STOP_) -{ - motor_ = &motor; - motor_->attach(PITCHER_MOTOR_PIN); -} - -Pitcher::~Pitcher() -{ - motor_->detach(); -} - -void Pitcher::raise() -{ - motor_speed_pulse_ = MOTOR_PULSE_BACKWARD_; -} - -void Pitcher::lower() -{ - motor_speed_pulse_ = MOTOR_PULSE_FORWARD_; -} - -void Pitcher::tick() -{ - - if ((at_lower_limit()) || (at_upper_limit())) - { - motor_speed_pulse_ = MOTOR_PULSE_STOP_; - } - - motor_->writeMicroseconds(motor_speed_pulse_); -} - -bool Pitcher::at_lower_limit() -{ - return digitalRead(lower_limit_switch_); -} - -bool Pitcher::at_upper_limit() -{ - return digitalRead(upper_limit_switch_); -} diff --git a/pitcher.hpp b/pitcher.hpp deleted file mode 100644 index 0998561..0000000 --- a/pitcher.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef PITCHER_H -#define PITCHER_H - -#include - -class Pitcher -{ -public: - Pitcher(Servo &motor); - ~Pitcher(); - void tick(); - - void raise(); - void lower(); - -private: - bool at_lower_limit(); - bool at_upper_limit(); - - unsigned int upper_limit_switch_; - unsigned int lower_limit_switch_; - - Servo *motor_; - - unsigned int motor_speed_pulse_; -}; - -#endif diff --git a/robot_defs.hpp b/robot_defs.hpp deleted file mode 100644 index 31cbda8..0000000 --- a/robot_defs.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef ROBOT_DEFS_H -#define ROBOT_DEFS_H - -const unsigned int INTAKE_MOTOR_PIN = 2U; -const unsigned int PITCHER_MOTOR_PIN = 3U; -const unsigned int SHOOTER_MOTOR_PIN = 4U; - -const unsigned int PITCHER_UPPER_LIMIT_PIN = 5U; -const unsigned int PITCHER_LOWER_LIMIT_PIN = 6U; - -const unsigned int MOTOR_PULSE_STOP_ = 1500U; -const unsigned int MOTOR_PULSE_FORWARD_ = 2000U; -const unsigned int MOTOR_PULSE_BACKWARD_ = 1000U; - -#endif diff --git a/shooter.cpp b/shooter.cpp deleted file mode 100644 index 0c55236..0000000 --- a/shooter.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include - -#include "shooter.hpp" -#include "robot_defs.hpp" - -Shooter::Shooter(Servo &flywheel_motor) : flywheel_motor_speed_(MOTOR_PULSE_STOP_) -{ - flywheel_motor_ = &flywheel_motor; - flywheel_motor_->attach(SHOOTER_MOTOR_PIN); -} - -Shooter::~Shooter() -{ - flywheel_motor_->detach(); -} - -void Shooter::load() -{ - flywheel_motor_speed_ = MOTOR_PULSE_BACKWARD_; -} - -void Shooter::shoot() -{ - flywheel_motor_speed_ = MOTOR_PULSE_FORWARD_; -} - -void Shooter::stop() -{ - flywheel_motor_speed_ = MOTOR_PULSE_STOP_; -} - -void Shooter::tick() -{ - flywheel_motor_->writeMicroseconds(flywheel_motor_speed_); -} diff --git a/shooter.hpp b/shooter.hpp deleted file mode 100644 index 36e0f80..0000000 --- a/shooter.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef SHOOTER_H -#define SHOOTER_H - -#include - -class Shooter -{ -public: - Shooter(Servo &flywheel_motor); - ~Shooter(); - void tick(); - - void load(); - void shoot(); - void stop(); - -private: - Servo *flywheel_motor_; - unsigned int flywheel_motor_speed_; -}; - -#endif diff --git a/wsce_display_bot.ino b/wsce_display_bot.ino index ce17da2..fd0eb98 100644 --- a/wsce_display_bot.ino +++ b/wsce_display_bot.ino @@ -1,115 +1,104 @@ +#include -#include "intake.hpp" -#include "pitcher.hpp" -#include "shooter.hpp" -#include "robot_defs.hpp" +Servo intake_motor; +Servo tilt_motor; +Servo shooter_motor; -typedef enum -{ - ACTUATE_INTAKE = 0, - ACTUATE_SHOOTER, - ACTUATE_PITCHER -} ActuationState; +Adafruit_NeoPixel *chassis_leds; +Adafruit_NeoPixel *intake_leds; +Adafruit_NeoPixel *shooter_leds; -Servo shooter_flywheel; -Servo intake_motor; -Servo pitcher_motor; +unsigned long cycle_start_millis; -Intake *intake; //{intake_motor}; -Shooter *shooter; //{shooter_flywheel}; -Pitcher *pitcher; //{pitcher_motor}; +constexpr auto LIGHTS_ONLY_CYCLE_TIME = 30000ul; +constexpr auto MOTORS_CYCLE_TIME = 15000ul; -unsigned long last_state_transition_time; -unsigned long last_tick_time; +constexpr auto INTAKE_MOTOR_PIN = 2U; +constexpr auto TILT_MOTOR_PIN = 3U; +constexpr auto SHOOTER_MOTOR_PIN = 4U; -ActuationState state; +constexpr auto CHASSIS_LEDS_PIN = 13U; +constexpr auto INTAKE_LEDS_PIN = 12U; +constexpr auto SHOOTER_LEDS_PIN = 11U; -void intake_callback() -{ - shooter->stop(); - pitcher->lower(); +constexpr auto CHASSIS_LEDS_LENGTH = 3U * 144U; +constexpr auto INTAKE_LEDS_LENGTH = 144U; +constexpr auto SHOOTER_LEDS_LENGTH = 247U; - intake->spin(); -} +constexpr auto TILT_UPPER_LIMIT_PIN = 5U; +constexpr auto TILT_LOWER_LIMIT_PIN = 6U; -void shooter_callback() -{ - pitcher->lower(); - intake->stop(); +// All routines below take "phase" as an argument +// This is a value in the range (0,1] - shooter->shoot(); -} +/* LED routines */ +void rainbow(const double phase, Adafruit_NeoPixel *leds) {} -void pitcher_callback() +/* Motor routines */ +void tick_motion(const double phase) { - intake->stop(); - shooter->stop(); + if (phase < 0.05) + { + // Pulse all lights as warning + stop_all_motors(); + } + else if (phase < 0.1) + { + // Intake on + tick_intake(phase); + } + else if (phase < 0.25) + { + // More stuff... + } +} - pitcher->raise(); +void stop_all_motors() +{ + intake_motor.writeMicroseconds(1500); + tilt_motor.writeMicroseconds(1500); + shooter_motor.writeMicroseconds(1500); } void setup() { // put your setup code here, to run once - last_state_transition_time = 0U; - state = ACTUATE_INTAKE; - last_tick_time = 0U; + // NeoPixel takes (pin_id, string_length) as arguments + chassis_leds = new Adafruit_NeoPixel(CHASSIS_LEDS_LENGTH, CHASSIS_LEDS_PIN); + intake_leds = new Adafruit_NeoPixel(INTAKE_LEDS_LENGTH, INTAKE_LEDS_PIN); + shooter_leds = new Adafruit_NeoPixel(SHOOTER_LEDS_LENGTH, SHOOTER_LEDS_PIN); + + intake_motor.attach(INTAKE_MOTOR_PIN); + shooter_motor.attach(SHOOTER_MOTOR_PIN); + tilt_motor.attach(TILT_MOTOR_PIN); - intake = new Intake(intake_motor); - shooter = new Shooter(shooter_flywheel); - pitcher = new Pitcher(pitcher_motor); + cycle_start_millis = millis(); } void loop() { - // put your main code here, to run repeatedly: - if ((millis() - last_tick_time) > 200) + const auto dt = millis() - cycle_start_millis; + + const auto motors_enabled = false; // TODO - read the switch + + if (dt < LIGHTS_ONLY_CYCLE_TIME) + { + // Just run the light show for the first x seconds + const auto phase = 1.0 * dt / LIGHTS_ONLY_CYCLE_TIME; + rainbow(phase, chassis_leds); + rainbow(phase, intake_leds); + rainbow(phase, shooter_leds); + stop_all_motors(); + } + else if (motors_enabled && dt < (LIGHTS_ONLY_CYCLE_TIME + MOTORS_CYCLE_TIME)) + { + // Run the motor routine + const auto phase = 1.0 * (dt - LIGHTS_ONLY_CYCLE_TIME) / MOTORS_CYCLE_TIME; + tick_motion(phase); + } + else { - if ((millis() - last_state_transition_time) > 5000U) - { - switch (state) - { - case ACTUATE_INTAKE: - state = ACTUATE_PITCHER; - break; - - case ACTUATE_PITCHER: - state = ACTUATE_SHOOTER; - break; - - case ACTUATE_SHOOTER: - state = ACTUATE_INTAKE; - break; - - default: - break; - } - last_state_transition_time = millis(); - } - - switch (state) - { - case ACTUATE_INTAKE: - intake_callback(); - break; - - case ACTUATE_PITCHER: - pitcher_callback(); - break; - - case ACTUATE_SHOOTER: - shooter_callback(); - break; - - default: - break; - } - - // Tick all the things - intake->tick(); - shooter->tick(); - pitcher->tick(); - - last_tick_time = millis(); + // Reset the counter + cycle_start_millis = millis(); } }