Skip to content

Commit

Permalink
ITWERKS
Browse files Browse the repository at this point in the history
- Mapped up the rest of the motors
- The whole thing at least runs now. Time for improvements
  • Loading branch information
JasXSL committed Aug 25, 2018
1 parent 7534cc6 commit e36e01d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
13 changes: 4 additions & 9 deletions ApiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
#include "UserSettings.h"
#include <ArduinoJson.h>

//#include "Pwm.h" Todo


ApiClient::ApiClient(void) :
_socket(),
_connected(false),
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions Motor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<VhProgramStage>().swap(_active_program);
for( auto stage : stages ){
for( auto stage : stages )
_active_program.push_back(VhProgramStage(stage.as<JsonObject>()));
}

playProgram();

}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e36e01d

Please sign in to comment.