From e36e01d82e9cd0bce68a32e119979ccc8053b488 Mon Sep 17 00:00:00 2001 From: JasXSL Date: Sat, 25 Aug 2018 15:33:52 +0200 Subject: [PATCH] ITWERKS - Mapped up the rest of the motors - The whole thing at least runs now. Time for improvements --- ApiClient.cpp | 13 ++++--------- Configuration.h | 6 ++++++ Motor.cpp | 13 +++++++------ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/ApiClient.cpp b/ApiClient.cpp index 3823366..873a835 100644 --- a/ApiClient.cpp +++ b/ApiClient.cpp @@ -10,9 +10,6 @@ #include "UserSettings.h" #include -//#include "Pwm.h" Todo - - ApiClient::ApiClient(void) : _socket(), _connected(false), @@ -25,12 +22,10 @@ ApiClient::ApiClient(void) : void ApiClient::setup(){ motors.push_back(Motor(Configuration::PIN_MOTOR_A_FWD, Configuration::PIN_MOTOR_A_BACK)); - /* - Todo: Map the rest of the motors - motors.push_back(Motor(CHANNEL_MOTOR_1)); - motors.push_back(Motor(CHANNEL_MOTOR_2)); - motors.push_back(Motor(CHANNEL_MOTOR_3)); - */ + motors.push_back(Motor(Configuration::PIN_MOTOR_B_FWD, Configuration::PIN_MOTOR_B_BACK)); + motors.push_back(Motor(Configuration::PIN_MOTOR_C_FWD, Configuration::PIN_MOTOR_C_BACK)); + motors.push_back(Motor(Configuration::PIN_MOTOR_D_FWD, Configuration::PIN_MOTOR_D_BACK)); + // Attach event handlers // For simplicity, events are always attached regardless diff --git a/Configuration.h b/Configuration.h index 3eb72e4..d7b1204 100644 --- a/Configuration.h +++ b/Configuration.h @@ -29,6 +29,12 @@ namespace Configuration{ const uint8_t PIN_CONFIG_BUTTON = 18; // Configuration pin. Use a pull-up resistor const uint8_t PIN_MOTOR_A_FWD = 15; const uint8_t PIN_MOTOR_A_BACK = 2; + const uint8_t PIN_MOTOR_B_FWD = 0; + const uint8_t PIN_MOTOR_B_BACK = 4; + const uint8_t PIN_MOTOR_C_FWD = 16; + const uint8_t PIN_MOTOR_C_BACK = 17; + const uint8_t PIN_MOTOR_D_FWD = 5; + const uint8_t PIN_MOTOR_D_BACK = 21; // PWM const int PWM_FREQ = 16000; // PWM Frequency diff --git a/Motor.cpp b/Motor.cpp index 1e9f3b0..68f33a6 100644 --- a/Motor.cpp +++ b/Motor.cpp @@ -5,12 +5,13 @@ #include "Pwm.h" #include "RandObject.h" - +//#define DEBUG Motor::Motor( uint8_t pin_fwd, uint8_t pin_back ) : _duty(0), pwm_fwd(pin_fwd), - pwm_back(pin_back) + pwm_back(pin_back), + _repeats(0) { // Force initial state //pwm_fwd = Pwm(pin_fwd); @@ -82,15 +83,15 @@ void Motor::loadProgram( JsonArray &stages, int repeats = 0 ){ #ifdef DEBUG Serial.println(); - Serial.printf("Loading new program on channel %i with %i stages.\n", _channel, stages.size()); + Serial.printf("Loading new program with #%i stages.\n", stages.size()); #endif _repeats = repeats; // Todo: This crashes the ESP. What de fook bork bork std::vector().swap(_active_program); - for( auto stage : stages ){ + for( auto stage : stages ) _active_program.push_back(VhProgramStage(stage.as())); - } + playProgram(); } @@ -131,7 +132,7 @@ void Motor::update(){ // fast_decay and forward are false by default void Motor::setPWM( uint8_t duty, bool fast_decay, bool forward ){ - Serial.printf("Setting duty: %i \n", duty); + //Serial.printf("Setting duty: %i on channel %i and 0 on channel %i \n", duty, pwm_fwd._channel, pwm_back._channel); _duty = duty; pwm_fwd.setPWM(duty);