adding servo handling
parent
d5e3486661
commit
772fec2b7d
|
@ -102,6 +102,10 @@ CommandCodeEnum Command::getGCodeEnum(char* code) {
|
|||
return F44;
|
||||
}
|
||||
|
||||
if (strcmp(code, "F61") == 0) {
|
||||
return F61;
|
||||
}
|
||||
|
||||
if (strcmp(code, "F81") == 0) {
|
||||
return F81;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ enum CommandCodeEnum
|
|||
F42 = 142,
|
||||
F43 = 143,
|
||||
F44 = 144,
|
||||
F61 = 161,
|
||||
F81 = 181,
|
||||
F82 = 182,
|
||||
F83 = 183
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
|
||||
/*
|
||||
* F61Handler.cpp
|
||||
*
|
||||
* Created on: 4014-11-04
|
||||
* Author: Tim Evers
|
||||
*/
|
||||
|
||||
#include "F61Handler.h"
|
||||
|
||||
|
||||
static F61Handler* instance;
|
||||
|
||||
F61Handler * F61Handler::getInstance() {
|
||||
if (!instance) {
|
||||
instance = new F61Handler();
|
||||
};
|
||||
return instance;
|
||||
}
|
||||
;
|
||||
|
||||
F61Handler::F61Handler() {
|
||||
}
|
||||
|
||||
int F61Handler::execute(Command* command) {
|
||||
|
||||
ServoControl::getInstance()->setAngle(command->getP(),command->getV());
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* F61Handler.h
|
||||
*
|
||||
* Created on: 2014-11-04
|
||||
* Author: TimEvers
|
||||
*/
|
||||
|
||||
#ifndef F4HANDLER_H_
|
||||
#define F4HANDLER_H_
|
||||
#include "GCodeHandler.h"
|
||||
#include "Config.h"
|
||||
#include "CurrentState.h"
|
||||
#include "pins.h"
|
||||
#include "Config.h"
|
||||
#include "ServoControl.h"
|
||||
|
||||
class F61Handler : public GCodeHandler {
|
||||
public:
|
||||
static F61Handler* getInstance();
|
||||
int execute(Command*);
|
||||
private:
|
||||
F61Handler();
|
||||
F61Handler(F61Handler const&);
|
||||
void operator=(F61Handler const&);
|
||||
};
|
||||
|
||||
#endif /* F61HANDLER_H_ */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
*
|
||||
* Created on: 15 maj 2014
|
||||
* Author: MattLech
|
||||
* Author: Tim Evers
|
||||
*/
|
||||
|
||||
#include "GCodeProcessor.h"
|
||||
|
@ -84,6 +85,9 @@ GCodeHandler* GCodeProcessor::getGCodeHandler(CommandCodeEnum codeEnum) {
|
|||
case F44:
|
||||
return F44Handler::getInstance();
|
||||
|
||||
case F61:
|
||||
return F61Handler::getInstance();
|
||||
|
||||
case F81:
|
||||
return F81Handler::getInstance();
|
||||
case F82:
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
#include "F43Handler.h"
|
||||
#include "F44Handler.h"
|
||||
|
||||
#include "F61Handler.h"
|
||||
|
||||
#include "F81Handler.h"
|
||||
#include "F82Handler.h"
|
||||
#include "F83Handler.h"
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
#include "ServoControl.h"
|
||||
|
||||
#include "Servo.h"
|
||||
|
||||
/*
|
||||
Servo pin layout
|
||||
D11 D6 D5 D4
|
||||
*/
|
||||
|
||||
static ServoControl* instance;
|
||||
|
||||
Servo servos[2];
|
||||
|
||||
ServoControl * ServoControl::getInstance() {
|
||||
if (!instance) {
|
||||
instance = new ServoControl();
|
||||
};
|
||||
return instance;
|
||||
}
|
||||
;
|
||||
|
||||
ServoControl::ServoControl() {
|
||||
}
|
||||
|
||||
int ServoControl::attach() {
|
||||
servos[0].attach(SERVO_0_PIN);
|
||||
servos[1].attach(SERVO_1_PIN);
|
||||
}
|
||||
|
||||
int ServoControl::setAngle(int motor, int angle) {
|
||||
|
||||
switch(motor) {
|
||||
case 1:
|
||||
servos[0].write(angle);
|
||||
break;
|
||||
case 2:
|
||||
servos[1].write(angle);
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* ServoControl.h
|
||||
*
|
||||
* Created on: 2014-11-01
|
||||
* Author: Tim Evers
|
||||
*/
|
||||
|
||||
#ifndef SERVOCONTROL_H_
|
||||
#define SERVOCONTROL_H_
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "pins.h"
|
||||
#include "Config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
class ServoControl {
|
||||
public:
|
||||
static ServoControl* getInstance();
|
||||
|
||||
int attach();
|
||||
int setAngle(int motor, int angle);
|
||||
private:
|
||||
ServoControl();
|
||||
ServoControl(ServoControl const&);
|
||||
void operator=(ServoControl const&);
|
||||
};
|
||||
|
||||
#endif /* SERVOCONTROL_H_ */
|
|
@ -3,6 +3,8 @@
|
|||
#include "pins.h"
|
||||
#include "Config.h"
|
||||
|
||||
#include "ServoControl.h"
|
||||
|
||||
static char commandEndChar = 0x0A;
|
||||
static GCodeProcessor* gCodeProcessor = new GCodeProcessor();
|
||||
|
||||
|
@ -31,11 +33,17 @@ void setup() {
|
|||
pinMode(FAN_PIN , OUTPUT);
|
||||
pinMode(LED_PIN , OUTPUT);
|
||||
|
||||
//pinMode(SERVO_0_PIN , OUTPUT);
|
||||
//pinMode(SERVO_1_PIN , OUTPUT);
|
||||
|
||||
digitalWrite(X_ENABLE_PIN, HIGH);
|
||||
digitalWrite(Y_ENABLE_PIN, HIGH);
|
||||
digitalWrite(Z_ENABLE_PIN, HIGH);
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
ServoControl::getInstance()->attach();
|
||||
|
||||
}
|
||||
|
||||
// The loop function is called in an endless loop
|
||||
|
@ -52,4 +60,7 @@ void loop() {
|
|||
}
|
||||
}
|
||||
delay(100);
|
||||
|
||||
//ServoControl::getInstance()->SetAngle(90);
|
||||
|
||||
}
|
||||
|
|
11
src/pins.h
11
src/pins.h
|
@ -26,12 +26,15 @@
|
|||
#define SDSS 53
|
||||
#define LED_PIN 13
|
||||
|
||||
#define FAN_PIN 9
|
||||
#define FAN_PIN 9
|
||||
|
||||
#define PS_ON_PIN 12
|
||||
#define KILL_PIN -1
|
||||
|
||||
#define HEATER_0_PIN 10
|
||||
#define HEATER_1_PIN 8
|
||||
#define TEMP_0_PIN 13 // ANALOG NUMBERING
|
||||
#define TEMP_1_PIN 14 // ANALOG NUMBERING
|
||||
#define HEATER_1_PIN 8
|
||||
#define TEMP_0_PIN 13 // ANALOG NUMBERING
|
||||
#define TEMP_1_PIN 14 // ANALOG NUMBERING
|
||||
|
||||
#define SERVO_0_PIN 4
|
||||
#define SERVO_1_PIN 5
|
||||
|
|
Loading…
Reference in New Issue