You can subscribe to this list here.
2009 |
Jan
(9) |
Feb
(137) |
Mar
(123) |
Apr
(60) |
May
(305) |
Jun
(49) |
Jul
(39) |
Aug
(44) |
Sep
(23) |
Oct
(42) |
Nov
(39) |
Dec
(30) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2010 |
Jan
(61) |
Feb
(50) |
Mar
(33) |
Apr
(10) |
May
(17) |
Jun
(19) |
Jul
(48) |
Aug
(71) |
Sep
(69) |
Oct
(59) |
Nov
(21) |
Dec
(74) |
2011 |
Jan
(38) |
Feb
(29) |
Mar
(19) |
Apr
(43) |
May
(16) |
Jun
(8) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <hoe...@us...> - 2009-02-01 00:20:40
|
Revision: 2473 http://reprap.svn.sourceforge.net/reprap/?rev=2473&view=rev Author: hoekstar Date: 2009-02-01 00:20:36 +0000 (Sun, 01 Feb 2009) Log Message: ----------- moved things to their proper places. Modified Paths: -------------- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/ArduinoSlaveExtruder.pde trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Configuration.h trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Packet.h trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/PacketProcessor.pde trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/_misc.h trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/extruder2.pde Added Paths: ----------- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Datatypes.h trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Variables.h Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/ArduinoSlaveExtruder.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/ArduinoSlaveExtruder.pde 2009-02-01 00:14:48 UTC (rev 2472) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/ArduinoSlaveExtruder.pde 2009-02-01 00:20:36 UTC (rev 2473) @@ -17,54 +17,16 @@ //include some basic libraries. #include <WProgram.h> -#include "_misc.h" +#include <Servo.h> + +#include "Configuration.h" +#include "Datatypes.h" #include "Packet.h" +#include "Variables.h" //this is our firmware version #define FIRMWARE_VERSION 0001 -//this is the version of our host software -unsigned int master_version = 0; - -//these are our packet classes -Packet masterPacket(0); - -//are we paused? -boolean is_tool_paused = false; - -#include <Servo.h> - -int current_temperature; -int target_temperature; - -// motor control states. -typedef enum { - MC_PWM = 0, - MC_ENCODER -} -MotorControlStyle; - -typedef enum { - MC_FORWARD = 0, - MC_REVERSE = 1 -} -MotorControlDirection; - -MotorControlStyle motor1_control = MC_PWM; -MotorControlDirection motor1_dir = MC_FORWARD; -byte motor1_pwm = 0; -long motor1_target_rpm = 0; -long motor1_current_rpm = 0; - -MotorControlStyle motor2_control = MC_PWM; -MotorControlDirection motor2_dir = MC_FORWARD; -byte motor2_pwm = 0; -long motor2_target_rpm = 0; -long motor2_current_rpm = 0; - -Servo servo1; -Servo servo2; - //set up our firmware for actual usage. void setup() { @@ -109,3 +71,25 @@ //initalize everything to the beginning initialize(); } + +void delayMicrosecondsInterruptible(unsigned int us) +{ + // for a one-microsecond delay, simply return. the overhead + // of the function call yields a delay of approximately 1 1/8 us. + if (--us == 0) + return; + + // the following loop takes a quarter of a microsecond (4 cycles) + // per iteration, so execute it four times for each microsecond of + // delay requested. + us <<= 2; + + // account for the time taken in the preceeding commands. + us -= 2; + + // busy wait + __asm__ __volatile__ ( + "1: sbiw %0,1" "\n\t" // 2 cycles + "brne 1b" : "=w" (us) : "0" (us) // 2 cycles + ); +} \ No newline at end of file Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Configuration.h =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Configuration.h 2009-02-01 00:14:48 UTC (rev 2472) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Configuration.h 2009-02-01 00:20:36 UTC (rev 2473) @@ -3,135 +3,16 @@ ****************************************************************************************/ // -// CHOOSE WHICH MOTHERBOARD YOU'RE USING: +// CHOOSE WHICH EXTRUDER YOU'RE USING: // -#define REPRAP_MOTHERBOARD_VERSION_1_0 -//#define REPRAP_MOTHERBOARD_VERSION_1_1 +#define EXTRUDER_CONTROLLER_VERSION_2_0 -// -// CHOOSE WHICH FAMILY OF STEPPER DRIVER YOU'RE USING: -// -//#define STEPPER_DRIVER_VERSION_1_X -#define STEPPER_DRIVER_VERSION_2_X - -// -// CHOOSE WHICH FAMILY OF OPTO ENDSTOP YOU'RE USING: -// -//#define OPTO_ENDSTOP_1_X -#define OPTO_ENDSTOP_2_X - /**************************************************************************************** * Sanguino Pin Assignment ****************************************************************************************/ //these are the pins for the v1.0 Motherboard. -#ifdef REPRAP_MOTHERBOARD_VERSION_1_0 +#ifdef EXTRUDER_CONTROLLER_VERSION_2_0 -//x axis pins -#define X_STEP_PIN 15 -#define X_DIR_PIN 18 -#define X_ENABLE_PIN 19 -#define X_MIN_PIN 20 -#define X_MAX_PIN 21 -//y axis pins -#define Y_STEP_PIN 23 -#define Y_DIR_PIN 22 -#define Y_ENABLE_PIN 19 -#define Y_MIN_PIN 25 -#define Y_MAX_PIN 26 - -//z axis pins -#define Z_STEP_PIN 29 -#define Z_DIR_PIN 30 -#define Z_ENABLE_PIN 31 -#define Z_MIN_PIN 2 -#define Z_MAX_PIN 1 - -//our pin for debugging. -#define DEBUG_PIN 0 - -//various SPI select pins -#define SPI_SELECT_1 ? -#define SPI_SELECT_2 ? -#define SPI_SELECT_3 ? - -//our SD card pins -#define SD_CARD_SELECT ? -#define SD_CARD_WRITE ? -#define SD_CARD_DETECT ? - -//our RS485 pins -#define RS485_TX_ENABLE ? -#define RS485_RX_ENABLE ? - #endif - -//these are the pins for the v1.1 Motherboard. -#ifdef REPRAP_MOTHERBOARD_VERSION_1_1 - -//x axis pins -#define X_STEP_PIN 15 -#define X_DIR_PIN 18 -#define X_ENABLE_PIN 19 -#define X_MIN_PIN 20 -#define X_MAX_PIN 21 - -//y axis pins -#define Y_STEP_PIN 23 -#define Y_DIR_PIN 22 -#define Y_ENABLE_PIN 24 -#define Y_MIN_PIN 25 -#define Y_MAX_PIN 26 - -//z axis pins -#define Z_STEP_PIN 27 -#define Z_DIR_PIN 28 -#define Z_ENABLE_PIN 29 -#define Z_MIN_PIN 30 -#define Z_MAX_PIN 31 - -//our pin for debugging. -#define DEBUG_PIN 0 - -//various SPI select pins -#define SPI_SELECT_1 1 -#define SPI_SELECT_2 3 -#define SPI_SELECT_3 14 - -//our SD card pins -#define SD_CARD_SELECT 4 -#define SD_CARD_WRITE 2 -#define SD_CARD_DETECT 3 - -//our RS485 pins -#define RS485_TX_ENABLE 12 -#define RS485_RX_ENABLE 13 - -#endif - -/**************************************************************************************** -* Stepper Driver Behaviour Definition -****************************************************************************************/ - -#ifdef STEPPER_DRIVER_VERSION_1_X -#define STEPPER_ENABLE 1 -#define STEPPER_DISABLE 0 -#endif - -#ifdef STEPPER_DRIVER_VERSION_2_X -#define STEPPER_ENABLE 0 -#define STEPPER_DISABLE 1 -#endif - -/**************************************************************************************** -* Opto Endstop Behaviour Definition -****************************************************************************************/ - -#ifdef OPTO_ENDSTOP_1_X -#define SENSORS_INVERTING 0 -#endif - -#ifdef OPTO_ENDSTOP_2_X -#define SENSORS_INVERTING 1 -#endif Added: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Datatypes.h =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Datatypes.h (rev 0) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Datatypes.h 2009-02-01 00:20:36 UTC (rev 2473) @@ -0,0 +1,33 @@ +// motor control states. +typedef enum { + MC_PWM = 0, + MC_ENCODER +} +MotorControlStyle; + +typedef enum { + MC_FORWARD = 0, + MC_REVERSE = 1 +} +MotorControlDirection; + +// packet states +typedef enum { + PS_START = 0, + PS_LEN, + PS_PAYLOAD, + PS_CRC, + PS_LAST +} +PacketState; + +// various error codes +typedef enum { + RC_GENERIC_ERROR = 0, + RC_OK = 1, + RC_BUFFER_OVERFLOW = 2, + RC_CRC_MISMATCH = 3, + RC_PACKET_TOO_BIG = 4, + RC_CMD_UNSUPPORTED = 5 +} +ResponseCode; \ No newline at end of file Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Packet.h =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Packet.h 2009-02-01 00:14:48 UTC (rev 2472) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Packet.h 2009-02-01 00:20:36 UTC (rev 2473) @@ -6,27 +6,6 @@ #include <stdint.h> #include "HardwareSerial.h" -// packet states -typedef enum { - PS_START = 0, - PS_LEN, - PS_PAYLOAD, - PS_CRC, - PS_LAST -} -PacketState; - -// various error codes -typedef enum { - RC_GENERIC_ERROR = 0, - RC_OK = 1, - RC_BUFFER_OVERFLOW = 2, - RC_CRC_MISMATCH = 3, - RC_PACKET_TOO_BIG = 4, - RC_CMD_UNSUPPORTED = 5 -} -ResponseCode; - #define START_BYTE 0xD5 #define MAX_PACKET_LENGTH 32 Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/PacketProcessor.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/PacketProcessor.pde 2009-02-01 00:14:48 UTC (rev 2472) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/PacketProcessor.pde 2009-02-01 00:20:36 UTC (rev 2473) @@ -23,10 +23,6 @@ #define SLAVE_CMD_SELECT_TOOL 21 #define SLAVE_CMD_IS_TOOL_READY 22 -//how many queued commands have we processed? -//this will be used to keep track of our current progress. -unsigned long finishedCommands = 0; - //initialize the firmware to default state. void init_commands() { Added: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Variables.h =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Variables.h (rev 0) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Variables.h 2009-02-01 00:20:36 UTC (rev 2473) @@ -0,0 +1,30 @@ +//this is the version of our host software +unsigned int master_version = 0; + +//how many queued commands have we processed? +//this will be used to keep track of our current progress. +unsigned long finishedCommands = 0; + +//these are our packet classes +Packet masterPacket(0); + +//are we paused? +boolean is_tool_paused = false; + +int current_temperature; +int target_temperature; + +MotorControlStyle motor1_control = MC_PWM; +MotorControlDirection motor1_dir = MC_FORWARD; +byte motor1_pwm = 0; +long motor1_target_rpm = 0; +long motor1_current_rpm = 0; + +MotorControlStyle motor2_control = MC_PWM; +MotorControlDirection motor2_dir = MC_FORWARD; +byte motor2_pwm = 0; +long motor2_target_rpm = 0; +long motor2_current_rpm = 0; + +Servo servo1; +Servo servo2; \ No newline at end of file Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/_misc.h =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/_misc.h 2009-02-01 00:14:48 UTC (rev 2472) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/_misc.h 2009-02-01 00:20:36 UTC (rev 2473) @@ -1,48 +1,4 @@ //#include <stddef.h> #include <stdint.h> -void delayMicrosecondsInterruptible(unsigned int us) -{ -#if F_CPU >= 16000000L - // for the 16 MHz clock on most Arduino boards - - // for a one-microsecond delay, simply return. the overhead - // of the function call yields a delay of approximately 1 1/8 us. - if (--us == 0) - return; - - // the following loop takes a quarter of a microsecond (4 cycles) - // per iteration, so execute it four times for each microsecond of - // delay requested. - us <<= 2; - - // account for the time taken in the preceeding commands. - us -= 2; -#else - // for the 8 MHz internal clock on the ATmega168 - - // for a one- or two-microsecond delay, simply return. the overhead of - // the function calls takes more than two microseconds. can't just - // subtract two, since us is unsigned; we'd overflow. - if (--us == 0) - return; - if (--us == 0) - return; - - // the following loop takes half of a microsecond (4 cycles) - // per iteration, so execute it twice for each microsecond of - // delay requested. - us <<= 1; - - // partially compensate for the time taken by the preceeding commands. - // we can't subtract any more than this or we'd overflow w/ small delays. - us--; -#endif - - // busy wait - __asm__ __volatile__ ( - "1: sbiw %0,1" "\n\t" // 2 cycles - "brne 1b" : "=w" (us) : "0" (us) // 2 cycles - ); -} Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/extruder2.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/extruder2.pde 2009-02-01 00:14:48 UTC (rev 2472) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/extruder2.pde 2009-02-01 00:20:36 UTC (rev 2473) @@ -1,5 +1,3 @@ - - void init_extruder() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hoe...@us...> - 2009-02-01 00:14:52
|
Revision: 2472 http://reprap.svn.sourceforge.net/reprap/?rev=2472&view=rev Author: hoekstar Date: 2009-02-01 00:14:48 +0000 (Sun, 01 Feb 2009) Log Message: ----------- more shuffling Added Paths: ----------- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Configuration.h trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Timer1 trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/extruder2.pde Removed Paths: ------------- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/_init.pde trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/extruder.pde trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/timer1_interrupt_routines.pde Copied: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Configuration.h (from rev 2471, trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/_init.pde) =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Configuration.h (rev 0) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Configuration.h 2009-02-01 00:14:48 UTC (rev 2472) @@ -0,0 +1,137 @@ +/**************************************************************************************** +* Here's where you define the overall electronics setup for your machine. +****************************************************************************************/ + +// +// CHOOSE WHICH MOTHERBOARD YOU'RE USING: +// +#define REPRAP_MOTHERBOARD_VERSION_1_0 +//#define REPRAP_MOTHERBOARD_VERSION_1_1 + +// +// CHOOSE WHICH FAMILY OF STEPPER DRIVER YOU'RE USING: +// +//#define STEPPER_DRIVER_VERSION_1_X +#define STEPPER_DRIVER_VERSION_2_X + +// +// CHOOSE WHICH FAMILY OF OPTO ENDSTOP YOU'RE USING: +// +//#define OPTO_ENDSTOP_1_X +#define OPTO_ENDSTOP_2_X + +/**************************************************************************************** +* Sanguino Pin Assignment +****************************************************************************************/ + +//these are the pins for the v1.0 Motherboard. +#ifdef REPRAP_MOTHERBOARD_VERSION_1_0 + +//x axis pins +#define X_STEP_PIN 15 +#define X_DIR_PIN 18 +#define X_ENABLE_PIN 19 +#define X_MIN_PIN 20 +#define X_MAX_PIN 21 + +//y axis pins +#define Y_STEP_PIN 23 +#define Y_DIR_PIN 22 +#define Y_ENABLE_PIN 19 +#define Y_MIN_PIN 25 +#define Y_MAX_PIN 26 + +//z axis pins +#define Z_STEP_PIN 29 +#define Z_DIR_PIN 30 +#define Z_ENABLE_PIN 31 +#define Z_MIN_PIN 2 +#define Z_MAX_PIN 1 + +//our pin for debugging. +#define DEBUG_PIN 0 + +//various SPI select pins +#define SPI_SELECT_1 ? +#define SPI_SELECT_2 ? +#define SPI_SELECT_3 ? + +//our SD card pins +#define SD_CARD_SELECT ? +#define SD_CARD_WRITE ? +#define SD_CARD_DETECT ? + +//our RS485 pins +#define RS485_TX_ENABLE ? +#define RS485_RX_ENABLE ? + +#endif + +//these are the pins for the v1.1 Motherboard. +#ifdef REPRAP_MOTHERBOARD_VERSION_1_1 + +//x axis pins +#define X_STEP_PIN 15 +#define X_DIR_PIN 18 +#define X_ENABLE_PIN 19 +#define X_MIN_PIN 20 +#define X_MAX_PIN 21 + +//y axis pins +#define Y_STEP_PIN 23 +#define Y_DIR_PIN 22 +#define Y_ENABLE_PIN 24 +#define Y_MIN_PIN 25 +#define Y_MAX_PIN 26 + +//z axis pins +#define Z_STEP_PIN 27 +#define Z_DIR_PIN 28 +#define Z_ENABLE_PIN 29 +#define Z_MIN_PIN 30 +#define Z_MAX_PIN 31 + +//our pin for debugging. +#define DEBUG_PIN 0 + +//various SPI select pins +#define SPI_SELECT_1 1 +#define SPI_SELECT_2 3 +#define SPI_SELECT_3 14 + +//our SD card pins +#define SD_CARD_SELECT 4 +#define SD_CARD_WRITE 2 +#define SD_CARD_DETECT 3 + +//our RS485 pins +#define RS485_TX_ENABLE 12 +#define RS485_RX_ENABLE 13 + +#endif + +/**************************************************************************************** +* Stepper Driver Behaviour Definition +****************************************************************************************/ + +#ifdef STEPPER_DRIVER_VERSION_1_X +#define STEPPER_ENABLE 1 +#define STEPPER_DISABLE 0 +#endif + +#ifdef STEPPER_DRIVER_VERSION_2_X +#define STEPPER_ENABLE 0 +#define STEPPER_DISABLE 1 +#endif + +/**************************************************************************************** +* Opto Endstop Behaviour Definition +****************************************************************************************/ + +#ifdef OPTO_ENDSTOP_1_X +#define SENSORS_INVERTING 0 +#endif + +#ifdef OPTO_ENDSTOP_2_X +#define SENSORS_INVERTING 1 +#endif Copied: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Timer1 (from rev 2471, trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/timer1_interrupt_routines.pde) =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Timer1 (rev 0) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Timer1 2009-02-01 00:14:48 UTC (rev 2472) @@ -0,0 +1,132 @@ +//these routines provide an easy interface for controlling timer1 interrupts + +//this handles the timer interrupt event +SIGNAL(SIG_OUTPUT_COMPARE1A) +{ +} + +void enableTimer1Interrupt() +{ + //enable our interrupt! + TIMSK1 |= (1<<OCIE1A); +} + +void disableTimer1Interrupt() +{ + TIMSK1 &= ~(1<<ICIE1); + TIMSK1 &= ~(1<<OCIE1A); +} + +void setTimer1Resolution(byte r) +{ + //from table 15-5 in that atmega168 datasheet: + // we're setting CS12 - CS10 which correspond to the binary numbers 0-5 + // 0 = no timer + // 1 = no prescaler + // 2 = clock/8 + // 3 = clock/64 + // 4 = clock/256 + // 5 = clock/1024 + + if (r > 5) + r = 5; + + TCCR1B &= B11111000; + TCCR1B |= r; +} + +void setTimer1Ceiling(unsigned int c) +{ + OCR1A = c; +} + + +unsigned int getTimer1Ceiling(unsigned long ticks) +{ + // our slowest speed at our highest resolution ( (2^16-1) * 0.0625 usecs = 4095 usecs) + if (ticks <= 65535L) + return (ticks & 0xffff); + // our slowest speed at our next highest resolution ( (2^16-1) * 0.5 usecs = 32767 usecs) + else if (ticks <= 524280L) + return ((ticks / 8) & 0xffff); + // our slowest speed at our medium resolution ( (2^16-1) * 4 usecs = 262140 usecs) + else if (ticks <= 4194240L) + return ((ticks / 64) & 0xffff); + // our slowest speed at our medium-low resolution ( (2^16-1) * 16 usecs = 1048560 usecs) + else if (ticks <= 16776960L) + return (ticks / 256); + // our slowest speed at our lowest resolution ((2^16-1) * 64 usecs = 4194240 usecs) + else if (ticks <= 67107840L) + return (ticks / 1024); + //its really slow... hopefully we can just get by with super slow. + else + return 65535; +} + +byte getTimer1Resolution(unsigned long ticks) +{ + // these also represent frequency: 1000000 / ticks / 2 = frequency in hz. + + // our slowest speed at our highest resolution ( (2^16-1) * 0.0625 usecs = 4095 usecs (4 millisecond max)) + // range: 8Mhz max - 122hz min + if (ticks <= 65535L) + return 1; + // our slowest speed at our next highest resolution ( (2^16-1) * 0.5 usecs = 32767 usecs (32 millisecond max)) + // range:1Mhz max - 15.26hz min + else if (ticks <= 524280L) + return 2; + // our slowest speed at our medium resolution ( (2^16-1) * 4 usecs = 262140 usecs (0.26 seconds max)) + // range: 125Khz max - 1.9hz min + else if (ticks <= 4194240L) + return 3; + // our slowest speed at our medium-low resolution ( (2^16-1) * 16 usecs = 1048560 usecs (1.04 seconds max)) + // range: 31.25Khz max - 0.475hz min + else if (ticks <= 16776960L) + return 4; + // our slowest speed at our lowest resolution ((2^16-1) * 64 usecs = 4194240 usecs (4.19 seconds max)) + // range: 7.812Khz max - 0.119hz min + else if (ticks <= 67107840L) + return 5; + //its really slow... hopefully we can just get by with super slow. + else + return 5; +} + +void setTimer1Ticks(unsigned long ticks) +{ + // ticks is the delay between interrupts in 62.5 nanosecond ticks. + // + // we break it into 5 different resolutions based on the delay. + // then we set the resolution based on the size of the delay. + // we also then calculate the timer ceiling required. (ie what the counter counts to) + // the result is the timer counts up to the appropriate time and then fires an interrupt. + + setTimer1Ceiling(getTimer1Ceiling(ticks)); + setTimer1Resolution(getTimer1Resolution(ticks)); +} + +void setupTimer1Interrupt() +{ + //clear the registers + TCCR1A = 0; + TCCR1B = 0; + TCCR1C = 0; + TIMSK1 = 0; + + //waveform generation = 0100 = CTC + TCCR1B &= ~(1<<WGM13); + TCCR1B |= (1<<WGM12); + TCCR1A &= ~(1<<WGM11); + TCCR1A &= ~(1<<WGM10); + + //output mode = 00 (disconnected) + TCCR1A &= ~(1<<COM1A1); + TCCR1A &= ~(1<<COM1A0); + TCCR1A &= ~(1<<COM1B1); + TCCR1A &= ~(1<<COM1B0); + + //start off with a slow frequency. + setTimer1Resolution(5); + setTimer1Ceiling(65535); + disableTimer1Interrupt(); +} Deleted: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/_init.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/_init.pde 2009-01-31 20:59:15 UTC (rev 2471) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/_init.pde 2009-02-01 00:14:48 UTC (rev 2472) @@ -1,137 +0,0 @@ -/**************************************************************************************** -* Here's where you define the overall electronics setup for your machine. -****************************************************************************************/ - -// -// CHOOSE WHICH MOTHERBOARD YOU'RE USING: -// -#define REPRAP_MOTHERBOARD_VERSION_1_0 -//#define REPRAP_MOTHERBOARD_VERSION_1_1 - -// -// CHOOSE WHICH FAMILY OF STEPPER DRIVER YOU'RE USING: -// -//#define STEPPER_DRIVER_VERSION_1_X -#define STEPPER_DRIVER_VERSION_2_X - -// -// CHOOSE WHICH FAMILY OF OPTO ENDSTOP YOU'RE USING: -// -//#define OPTO_ENDSTOP_1_X -#define OPTO_ENDSTOP_2_X - -/**************************************************************************************** -* Sanguino Pin Assignment -****************************************************************************************/ - -//these are the pins for the v1.0 Motherboard. -#ifdef REPRAP_MOTHERBOARD_VERSION_1_0 - -//x axis pins -#define X_STEP_PIN 15 -#define X_DIR_PIN 18 -#define X_ENABLE_PIN 19 -#define X_MIN_PIN 20 -#define X_MAX_PIN 21 - -//y axis pins -#define Y_STEP_PIN 23 -#define Y_DIR_PIN 22 -#define Y_ENABLE_PIN 19 -#define Y_MIN_PIN 25 -#define Y_MAX_PIN 26 - -//z axis pins -#define Z_STEP_PIN 29 -#define Z_DIR_PIN 30 -#define Z_ENABLE_PIN 31 -#define Z_MIN_PIN 2 -#define Z_MAX_PIN 1 - -//our pin for debugging. -#define DEBUG_PIN 0 - -//various SPI select pins -#define SPI_SELECT_1 ? -#define SPI_SELECT_2 ? -#define SPI_SELECT_3 ? - -//our SD card pins -#define SD_CARD_SELECT ? -#define SD_CARD_WRITE ? -#define SD_CARD_DETECT ? - -//our RS485 pins -#define RS485_TX_ENABLE ? -#define RS485_RX_ENABLE ? - -#endif - -//these are the pins for the v1.1 Motherboard. -#ifdef REPRAP_MOTHERBOARD_VERSION_1_1 - -//x axis pins -#define X_STEP_PIN 15 -#define X_DIR_PIN 18 -#define X_ENABLE_PIN 19 -#define X_MIN_PIN 20 -#define X_MAX_PIN 21 - -//y axis pins -#define Y_STEP_PIN 23 -#define Y_DIR_PIN 22 -#define Y_ENABLE_PIN 24 -#define Y_MIN_PIN 25 -#define Y_MAX_PIN 26 - -//z axis pins -#define Z_STEP_PIN 27 -#define Z_DIR_PIN 28 -#define Z_ENABLE_PIN 29 -#define Z_MIN_PIN 30 -#define Z_MAX_PIN 31 - -//our pin for debugging. -#define DEBUG_PIN 0 - -//various SPI select pins -#define SPI_SELECT_1 1 -#define SPI_SELECT_2 3 -#define SPI_SELECT_3 14 - -//our SD card pins -#define SD_CARD_SELECT 4 -#define SD_CARD_WRITE 2 -#define SD_CARD_DETECT 3 - -//our RS485 pins -#define RS485_TX_ENABLE 12 -#define RS485_RX_ENABLE 13 - -#endif - -/**************************************************************************************** -* Stepper Driver Behaviour Definition -****************************************************************************************/ - -#ifdef STEPPER_DRIVER_VERSION_1_X -#define STEPPER_ENABLE 1 -#define STEPPER_DISABLE 0 -#endif - -#ifdef STEPPER_DRIVER_VERSION_2_X -#define STEPPER_ENABLE 0 -#define STEPPER_DISABLE 1 -#endif - -/**************************************************************************************** -* Opto Endstop Behaviour Definition -****************************************************************************************/ - -#ifdef OPTO_ENDSTOP_1_X -#define SENSORS_INVERTING 0 -#endif - -#ifdef OPTO_ENDSTOP_2_X -#define SENSORS_INVERTING 1 -#endif Deleted: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/extruder.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/extruder.pde 2009-01-31 20:59:15 UTC (rev 2471) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/extruder.pde 2009-02-01 00:14:48 UTC (rev 2472) @@ -1,59 +0,0 @@ - - -void init_extruder() -{ - -} - -void manage_temperature() -{ - -} - -void enable_motor_1() -{ - -} - -void disable_motor_1() -{ - -} - -void enable_motor_2() -{ - -} - -void disable_motor_2() -{ - -} -void enable_fan() -{ - -} - -void disable_fan() -{ - -} - -void open_valve() -{ - -} - -void close_valve() -{ - -} - -byte is_tool_ready() -{ - //are we within 5% of the temperature? - if (current_temperature > (int)(target_temperature * 0.95)) - return 1; - else - return 0; -} Copied: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/extruder2.pde (from rev 2471, trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/extruder.pde) =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/extruder2.pde (rev 0) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/extruder2.pde 2009-02-01 00:14:48 UTC (rev 2472) @@ -0,0 +1,59 @@ + + +void init_extruder() +{ + +} + +void manage_temperature() +{ + +} + +void enable_motor_1() +{ + +} + +void disable_motor_1() +{ + +} + +void enable_motor_2() +{ + +} + +void disable_motor_2() +{ + +} +void enable_fan() +{ + +} + +void disable_fan() +{ + +} + +void open_valve() +{ + +} + +void close_valve() +{ + +} + +byte is_tool_ready() +{ + //are we within 5% of the temperature? + if (current_temperature > (int)(target_temperature * 0.95)) + return 1; + else + return 0; +} Deleted: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/timer1_interrupt_routines.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/timer1_interrupt_routines.pde 2009-01-31 20:59:15 UTC (rev 2471) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/timer1_interrupt_routines.pde 2009-02-01 00:14:48 UTC (rev 2472) @@ -1,132 +0,0 @@ -//these routines provide an easy interface for controlling timer1 interrupts - -//this handles the timer interrupt event -SIGNAL(SIG_OUTPUT_COMPARE1A) -{ -} - -void enableTimer1Interrupt() -{ - //enable our interrupt! - TIMSK1 |= (1<<OCIE1A); -} - -void disableTimer1Interrupt() -{ - TIMSK1 &= ~(1<<ICIE1); - TIMSK1 &= ~(1<<OCIE1A); -} - -void setTimer1Resolution(byte r) -{ - //from table 15-5 in that atmega168 datasheet: - // we're setting CS12 - CS10 which correspond to the binary numbers 0-5 - // 0 = no timer - // 1 = no prescaler - // 2 = clock/8 - // 3 = clock/64 - // 4 = clock/256 - // 5 = clock/1024 - - if (r > 5) - r = 5; - - TCCR1B &= B11111000; - TCCR1B |= r; -} - -void setTimer1Ceiling(unsigned int c) -{ - OCR1A = c; -} - - -unsigned int getTimer1Ceiling(unsigned long ticks) -{ - // our slowest speed at our highest resolution ( (2^16-1) * 0.0625 usecs = 4095 usecs) - if (ticks <= 65535L) - return (ticks & 0xffff); - // our slowest speed at our next highest resolution ( (2^16-1) * 0.5 usecs = 32767 usecs) - else if (ticks <= 524280L) - return ((ticks / 8) & 0xffff); - // our slowest speed at our medium resolution ( (2^16-1) * 4 usecs = 262140 usecs) - else if (ticks <= 4194240L) - return ((ticks / 64) & 0xffff); - // our slowest speed at our medium-low resolution ( (2^16-1) * 16 usecs = 1048560 usecs) - else if (ticks <= 16776960L) - return (ticks / 256); - // our slowest speed at our lowest resolution ((2^16-1) * 64 usecs = 4194240 usecs) - else if (ticks <= 67107840L) - return (ticks / 1024); - //its really slow... hopefully we can just get by with super slow. - else - return 65535; -} - -byte getTimer1Resolution(unsigned long ticks) -{ - // these also represent frequency: 1000000 / ticks / 2 = frequency in hz. - - // our slowest speed at our highest resolution ( (2^16-1) * 0.0625 usecs = 4095 usecs (4 millisecond max)) - // range: 8Mhz max - 122hz min - if (ticks <= 65535L) - return 1; - // our slowest speed at our next highest resolution ( (2^16-1) * 0.5 usecs = 32767 usecs (32 millisecond max)) - // range:1Mhz max - 15.26hz min - else if (ticks <= 524280L) - return 2; - // our slowest speed at our medium resolution ( (2^16-1) * 4 usecs = 262140 usecs (0.26 seconds max)) - // range: 125Khz max - 1.9hz min - else if (ticks <= 4194240L) - return 3; - // our slowest speed at our medium-low resolution ( (2^16-1) * 16 usecs = 1048560 usecs (1.04 seconds max)) - // range: 31.25Khz max - 0.475hz min - else if (ticks <= 16776960L) - return 4; - // our slowest speed at our lowest resolution ((2^16-1) * 64 usecs = 4194240 usecs (4.19 seconds max)) - // range: 7.812Khz max - 0.119hz min - else if (ticks <= 67107840L) - return 5; - //its really slow... hopefully we can just get by with super slow. - else - return 5; -} - -void setTimer1Ticks(unsigned long ticks) -{ - // ticks is the delay between interrupts in 62.5 nanosecond ticks. - // - // we break it into 5 different resolutions based on the delay. - // then we set the resolution based on the size of the delay. - // we also then calculate the timer ceiling required. (ie what the counter counts to) - // the result is the timer counts up to the appropriate time and then fires an interrupt. - - setTimer1Ceiling(getTimer1Ceiling(ticks)); - setTimer1Resolution(getTimer1Resolution(ticks)); -} - -void setupTimer1Interrupt() -{ - //clear the registers - TCCR1A = 0; - TCCR1B = 0; - TCCR1C = 0; - TIMSK1 = 0; - - //waveform generation = 0100 = CTC - TCCR1B &= ~(1<<WGM13); - TCCR1B |= (1<<WGM12); - TCCR1A &= ~(1<<WGM11); - TCCR1A &= ~(1<<WGM10); - - //output mode = 00 (disconnected) - TCCR1A &= ~(1<<COM1A1); - TCCR1A &= ~(1<<COM1A0); - TCCR1A &= ~(1<<COM1B1); - TCCR1A &= ~(1<<COM1B0); - - //start off with a slow frequency. - setTimer1Resolution(5); - setTimer1Ceiling(65535); - disableTimer1Interrupt(); -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hoe...@us...> - 2009-01-31 20:59:20
|
Revision: 2471 http://reprap.svn.sourceforge.net/reprap/?rev=2471&view=rev Author: hoekstar Date: 2009-01-31 20:59:15 +0000 (Sat, 31 Jan 2009) Log Message: ----------- okay, it works properly now. Modified Paths: -------------- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/SanguinoMaster.pde trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Steppers.pde Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/SanguinoMaster.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/SanguinoMaster.pde 2009-01-31 20:54:12 UTC (rev 2470) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/SanguinoMaster.pde 2009-01-31 20:59:15 UTC (rev 2471) @@ -14,10 +14,10 @@ //include some basic libraries. #include <WProgram.h> +#include <RepRapSDCard.h> #include "Configuration.h" #include "Datatypes.h" -#include "RepRapSDCard.h" #include "CircularBuffer.h" #include "Packet.h" #include "Variables.h" Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Steppers.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Steppers.pde 2009-01-31 20:54:12 UTC (rev 2470) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Steppers.pde 2009-01-31 20:59:15 UTC (rev 2471) @@ -1,4 +1,4 @@ -t//initialize our stepper drivers +//initialize our stepper drivers void init_steppers() { //clear our point buffer This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hoe...@us...> - 2009-01-31 20:54:21
|
Revision: 2470 http://reprap.svn.sourceforge.net/reprap/?rev=2470&view=rev Author: hoekstar Date: 2009-01-31 20:54:12 +0000 (Sat, 31 Jan 2009) Log Message: ----------- added SD card support to the library. Modified Paths: -------------- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/SanguinoMaster.pde trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Steppers.pde trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Variables.h Added Paths: ----------- trunk/reprap/firmware/Sanguino/Sanguino3G/RepRapSDCard/ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/SDCard.pde Added: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/SDCard.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/SDCard.pde (rev 0) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/SDCard.pde 2009-01-31 20:54:12 UTC (rev 2470) @@ -0,0 +1,125 @@ +void init_sd_card() +{ + if (!card.init_card()) + { + if (!card.isAvailable()) + { + Serial.println("No card present"); + error = 1; + } + else + { + Serial.println("Card init failed"); + error = 2; + } + } + else if (!card.open_partition()) + { + Serial.println("No partition"); + error = 3; + } + else if (!card.open_filesys()) + { + Serial.println("Can't open filesys"); + error = 4; + } + else if (!card.open_dir("/")) + { + Serial.println("Can't open /"); + error = 5; + } + else if (card.isLocked()) + { + Serial.println("Card is locked"); + error = 6; + } +} + +void open_file() +{ + open_new_file(); + + if (error == 0) + { + bufferIndex = 0; + for (char c = 'a'; c<= 'z'; c++) + { + buffer[bufferIndex] = c; + bufferIndex++; + } + + card.write_file(f, (uint8_t *) buffer, bufferIndex); + card.close_file(f); + } + + read_first_file(); +} + +void open_new_file() +{ + strcpy(buffer, "RRJOB00.TXT"); + for (buffer[5] = '0'; buffer[5] <= '9'; buffer[5]++) + { + for (buffer[6] = '0'; buffer[6] <= '9'; buffer[6]++) + { + f = card.open_file(buffer); + if (!f) + break; // found a file! + card.close_file(f); + } + if (!f) + break; + } + + if(!card.create_file(buffer)) + { + Serial.print("couldnt create: "); + Serial.println(buffer); + error = 7; + } + else + { + f = card.open_file(buffer); + if (!f) + { + Serial.print("error opening: "); + Serial.println(buffer); + error = 8; + } + else + { + Serial.print("writing to: "); + Serial.println(buffer); + } + } +} + +void read_first_file() +{ + strcpy(buffer, "RRJOB00.TXT"); + f = card.open_file(buffer); + + if (!f) + { + Serial.print("error opening: "); + Serial.println(buffer); + error = 8; + } + else + { + Serial.print("reading from: "); + Serial.println(buffer); + + uint8_t result = card.read_file(f, (uint8_t *)buffer, 8); + + if (result >0) + Serial.print(buffer); + else if (result == 0) + Serial.println("end of file."); + else + { + Serial.print("read error: "); + Serial.println(result, DEC); + } + } +} Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/SanguinoMaster.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/SanguinoMaster.pde 2009-01-31 20:20:09 UTC (rev 2469) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/SanguinoMaster.pde 2009-01-31 20:54:12 UTC (rev 2470) @@ -17,6 +17,7 @@ #include "Configuration.h" #include "Datatypes.h" +#include "RepRapSDCard.h" #include "CircularBuffer.h" #include "Packet.h" #include "Variables.h" Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Steppers.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Steppers.pde 2009-01-31 20:20:09 UTC (rev 2469) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Steppers.pde 2009-01-31 20:54:12 UTC (rev 2470) @@ -1,4 +1,4 @@ -//initialize our stepper drivers +t//initialize our stepper drivers void init_steppers() { //clear our point buffer Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Variables.h =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Variables.h 2009-01-31 20:20:09 UTC (rev 2469) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Variables.h 2009-01-31 20:54:12 UTC (rev 2470) @@ -42,4 +42,14 @@ //this will be used to keep track of our current progress. unsigned long finishedCommands = 0; -byte currentToolIndex = 0; \ No newline at end of file +byte currentToolIndex = 0; + +//SD CARD STUFF. +RepRapSDCard card; +File f; + +//our buffer of bytes. +#define BUFFSIZE 64 +char buffer[BUFFSIZE]; +byte bufferIndex = 0; +byte error = 0; \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hoe...@us...> - 2009-01-31 20:20:13
|
Revision: 2469 http://reprap.svn.sourceforge.net/reprap/?rev=2469&view=rev Author: hoekstar Date: 2009-01-31 20:20:09 +0000 (Sat, 31 Jan 2009) Log Message: ----------- a bit more reshuffling Added Paths: ----------- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Timer1.pde Removed Paths: ------------- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/_misc.h trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/timer1_interrupt_routines.pde Copied: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Timer1.pde (from rev 2468, trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/timer1_interrupt_routines.pde) =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Timer1.pde (rev 0) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Timer1.pde 2009-01-31 20:20:09 UTC (rev 2469) @@ -0,0 +1,133 @@ +//these routines provide an easy interface for controlling timer1 interrupts + +//this handles the timer interrupt event +SIGNAL(SIG_OUTPUT_COMPARE1A) +{ + dda_step(); +} + +void enableTimer1Interrupt() +{ + //enable our interrupt! + TIMSK1 |= (1<<OCIE1A); +} + +void disableTimer1Interrupt() +{ + TIMSK1 &= ~(1<<ICIE1); + TIMSK1 &= ~(1<<OCIE1A); +} + +void setTimer1Resolution(byte r) +{ + //from table 15-5 in that atmega168 datasheet: + // we're setting CS12 - CS10 which correspond to the binary numbers 0-5 + // 0 = no timer + // 1 = no prescaler + // 2 = clock/8 + // 3 = clock/64 + // 4 = clock/256 + // 5 = clock/1024 + + if (r > 5) + r = 5; + + TCCR1B &= B11111000; + TCCR1B |= r; +} + +void setTimer1Ceiling(unsigned int c) +{ + OCR1A = c; +} + + +unsigned int getTimer1Ceiling(unsigned long ticks) +{ + // our slowest speed at our highest resolution ( (2^16-1) * 0.0625 usecs = 4095 usecs) + if (ticks <= 65535L) + return (ticks & 0xffff); + // our slowest speed at our next highest resolution ( (2^16-1) * 0.5 usecs = 32767 usecs) + else if (ticks <= 524280L) + return ((ticks / 8) & 0xffff); + // our slowest speed at our medium resolution ( (2^16-1) * 4 usecs = 262140 usecs) + else if (ticks <= 4194240L) + return ((ticks / 64) & 0xffff); + // our slowest speed at our medium-low resolution ( (2^16-1) * 16 usecs = 1048560 usecs) + else if (ticks <= 16776960L) + return (ticks / 256); + // our slowest speed at our lowest resolution ((2^16-1) * 64 usecs = 4194240 usecs) + else if (ticks <= 67107840L) + return (ticks / 1024); + //its really slow... hopefully we can just get by with super slow. + else + return 65535; +} + +byte getTimer1Resolution(unsigned long ticks) +{ + // these also represent frequency: 1000000 / ticks / 2 = frequency in hz. + + // our slowest speed at our highest resolution ( (2^16-1) * 0.0625 usecs = 4095 usecs (4 millisecond max)) + // range: 8Mhz max - 122hz min + if (ticks <= 65535L) + return 1; + // our slowest speed at our next highest resolution ( (2^16-1) * 0.5 usecs = 32767 usecs (32 millisecond max)) + // range:1Mhz max - 15.26hz min + else if (ticks <= 524280L) + return 2; + // our slowest speed at our medium resolution ( (2^16-1) * 4 usecs = 262140 usecs (0.26 seconds max)) + // range: 125Khz max - 1.9hz min + else if (ticks <= 4194240L) + return 3; + // our slowest speed at our medium-low resolution ( (2^16-1) * 16 usecs = 1048560 usecs (1.04 seconds max)) + // range: 31.25Khz max - 0.475hz min + else if (ticks <= 16776960L) + return 4; + // our slowest speed at our lowest resolution ((2^16-1) * 64 usecs = 4194240 usecs (4.19 seconds max)) + // range: 7.812Khz max - 0.119hz min + else if (ticks <= 67107840L) + return 5; + //its really slow... hopefully we can just get by with super slow. + else + return 5; +} + +void setTimer1Ticks(unsigned long ticks) +{ + // ticks is the delay between interrupts in 62.5 nanosecond ticks. + // + // we break it into 5 different resolutions based on the delay. + // then we set the resolution based on the size of the delay. + // we also then calculate the timer ceiling required. (ie what the counter counts to) + // the result is the timer counts up to the appropriate time and then fires an interrupt. + + setTimer1Ceiling(getTimer1Ceiling(ticks)); + setTimer1Resolution(getTimer1Resolution(ticks)); +} + +void setupTimer1Interrupt() +{ + //clear the registers + TCCR1A = 0; + TCCR1B = 0; + TCCR1C = 0; + TIMSK1 = 0; + + //waveform generation = 0100 = CTC + TCCR1B &= ~(1<<WGM13); + TCCR1B |= (1<<WGM12); + TCCR1A &= ~(1<<WGM11); + TCCR1A &= ~(1<<WGM10); + + //output mode = 00 (disconnected) + TCCR1A &= ~(1<<COM1A1); + TCCR1A &= ~(1<<COM1A0); + TCCR1A &= ~(1<<COM1B1); + TCCR1A &= ~(1<<COM1B0); + + //start off with a slow frequency. + setTimer1Resolution(5); + setTimer1Ceiling(65535); + disableTimer1Interrupt(); +} Deleted: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/_misc.h =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/_misc.h 2009-01-31 20:16:52 UTC (rev 2468) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/_misc.h 2009-01-31 20:20:09 UTC (rev 2469) @@ -1 +0,0 @@ - Deleted: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/timer1_interrupt_routines.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/timer1_interrupt_routines.pde 2009-01-31 20:16:52 UTC (rev 2468) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/timer1_interrupt_routines.pde 2009-01-31 20:20:09 UTC (rev 2469) @@ -1,133 +0,0 @@ -//these routines provide an easy interface for controlling timer1 interrupts - -//this handles the timer interrupt event -SIGNAL(SIG_OUTPUT_COMPARE1A) -{ - dda_step(); -} - -void enableTimer1Interrupt() -{ - //enable our interrupt! - TIMSK1 |= (1<<OCIE1A); -} - -void disableTimer1Interrupt() -{ - TIMSK1 &= ~(1<<ICIE1); - TIMSK1 &= ~(1<<OCIE1A); -} - -void setTimer1Resolution(byte r) -{ - //from table 15-5 in that atmega168 datasheet: - // we're setting CS12 - CS10 which correspond to the binary numbers 0-5 - // 0 = no timer - // 1 = no prescaler - // 2 = clock/8 - // 3 = clock/64 - // 4 = clock/256 - // 5 = clock/1024 - - if (r > 5) - r = 5; - - TCCR1B &= B11111000; - TCCR1B |= r; -} - -void setTimer1Ceiling(unsigned int c) -{ - OCR1A = c; -} - - -unsigned int getTimer1Ceiling(unsigned long ticks) -{ - // our slowest speed at our highest resolution ( (2^16-1) * 0.0625 usecs = 4095 usecs) - if (ticks <= 65535L) - return (ticks & 0xffff); - // our slowest speed at our next highest resolution ( (2^16-1) * 0.5 usecs = 32767 usecs) - else if (ticks <= 524280L) - return ((ticks / 8) & 0xffff); - // our slowest speed at our medium resolution ( (2^16-1) * 4 usecs = 262140 usecs) - else if (ticks <= 4194240L) - return ((ticks / 64) & 0xffff); - // our slowest speed at our medium-low resolution ( (2^16-1) * 16 usecs = 1048560 usecs) - else if (ticks <= 16776960L) - return (ticks / 256); - // our slowest speed at our lowest resolution ((2^16-1) * 64 usecs = 4194240 usecs) - else if (ticks <= 67107840L) - return (ticks / 1024); - //its really slow... hopefully we can just get by with super slow. - else - return 65535; -} - -byte getTimer1Resolution(unsigned long ticks) -{ - // these also represent frequency: 1000000 / ticks / 2 = frequency in hz. - - // our slowest speed at our highest resolution ( (2^16-1) * 0.0625 usecs = 4095 usecs (4 millisecond max)) - // range: 8Mhz max - 122hz min - if (ticks <= 65535L) - return 1; - // our slowest speed at our next highest resolution ( (2^16-1) * 0.5 usecs = 32767 usecs (32 millisecond max)) - // range:1Mhz max - 15.26hz min - else if (ticks <= 524280L) - return 2; - // our slowest speed at our medium resolution ( (2^16-1) * 4 usecs = 262140 usecs (0.26 seconds max)) - // range: 125Khz max - 1.9hz min - else if (ticks <= 4194240L) - return 3; - // our slowest speed at our medium-low resolution ( (2^16-1) * 16 usecs = 1048560 usecs (1.04 seconds max)) - // range: 31.25Khz max - 0.475hz min - else if (ticks <= 16776960L) - return 4; - // our slowest speed at our lowest resolution ((2^16-1) * 64 usecs = 4194240 usecs (4.19 seconds max)) - // range: 7.812Khz max - 0.119hz min - else if (ticks <= 67107840L) - return 5; - //its really slow... hopefully we can just get by with super slow. - else - return 5; -} - -void setTimer1Ticks(unsigned long ticks) -{ - // ticks is the delay between interrupts in 62.5 nanosecond ticks. - // - // we break it into 5 different resolutions based on the delay. - // then we set the resolution based on the size of the delay. - // we also then calculate the timer ceiling required. (ie what the counter counts to) - // the result is the timer counts up to the appropriate time and then fires an interrupt. - - setTimer1Ceiling(getTimer1Ceiling(ticks)); - setTimer1Resolution(getTimer1Resolution(ticks)); -} - -void setupTimer1Interrupt() -{ - //clear the registers - TCCR1A = 0; - TCCR1B = 0; - TCCR1C = 0; - TIMSK1 = 0; - - //waveform generation = 0100 = CTC - TCCR1B &= ~(1<<WGM13); - TCCR1B |= (1<<WGM12); - TCCR1A &= ~(1<<WGM11); - TCCR1A &= ~(1<<WGM10); - - //output mode = 00 (disconnected) - TCCR1A &= ~(1<<COM1A1); - TCCR1A &= ~(1<<COM1A0); - TCCR1A &= ~(1<<COM1B1); - TCCR1A &= ~(1<<COM1B0); - - //start off with a slow frequency. - setTimer1Resolution(5); - setTimer1Ceiling(65535); - disableTimer1Interrupt(); -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hoe...@us...> - 2009-01-31 20:16:56
|
Revision: 2468 http://reprap.svn.sourceforge.net/reprap/?rev=2468&view=rev Author: hoekstar Date: 2009-01-31 20:16:52 +0000 (Sat, 31 Jan 2009) Log Message: ----------- moved a bunch of things around to make things nice Modified Paths: -------------- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/CircularBuffer.h trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Configuration.h trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Packet.h trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/PacketProcessor.pde trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/SanguinoMaster.pde trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/_misc.h trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/timer1_interrupt_routines.pde Added Paths: ----------- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Datatypes.h trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Steppers.pde trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Tools.pde trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Variables.h Removed Paths: ------------- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/stepper.pde trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/tools2.pde Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/CircularBuffer.h =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/CircularBuffer.h 2009-01-31 19:54:09 UTC (rev 2467) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/CircularBuffer.h 2009-01-31 20:16:52 UTC (rev 2468) @@ -29,7 +29,7 @@ ~CircularBuffer() { } - + /// Reset buffer. (Note: does not zero data.) void clear() { start = count = 0; @@ -55,7 +55,7 @@ buffer[(start+count)%capacity] = datum; count++; } - + /// Remove and return a character from the start of the /// circular buffer. const uint8_t remove_8() { @@ -66,18 +66,12 @@ } const uint16_t remove_16() { - return (remove_8() << 8) & remove_8(); + return (remove_8() << 8) & remove_8(); } const uint32_t remove_32() { - return (remove_16() << 16) & remove_16(); + return (remove_16() << 16) & remove_16(); } }; -//we store all queueable commands in one big giant buffer. -// Explicitly allocate memory at compile time for buffer. -#define COMMAND_BUFFER_SIZE 2048 -uint8_t underlyingBuffer[COMMAND_BUFFER_SIZE]; -CircularBuffer commandBuffer(COMMAND_BUFFER_SIZE, underlyingBuffer); - #endif // _CIRCULAR_BUFFER_H_ Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Configuration.h =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Configuration.h 2009-01-31 19:54:09 UTC (rev 2467) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Configuration.h 2009-01-31 20:16:52 UTC (rev 2468) @@ -1,6 +1,6 @@ /**************************************************************************************** -* Here's where you define the overall electronics setup for your machine. -****************************************************************************************/ + * Here's where you define the overall electronics setup for your machine. + ****************************************************************************************/ // // CHOOSE WHICH MOTHERBOARD YOU'RE USING: @@ -21,8 +21,8 @@ #define OPTO_ENDSTOP_2_X /**************************************************************************************** -* Sanguino Pin Assignment -****************************************************************************************/ + * Sanguino Pin Assignment + ****************************************************************************************/ //these are the pins for the v1.0 Motherboard. #ifdef REPRAP_MOTHERBOARD_VERSION_1_0 @@ -51,11 +51,6 @@ //our pin for debugging. #define DEBUG_PIN 0 -//various SPI select pins -#define SPI_SELECT_1 ? -#define SPI_SELECT_2 ? -#define SPI_SELECT_3 ? - //our SD card pins #define SD_CARD_SELECT ? #define SD_CARD_WRITE ? @@ -111,8 +106,8 @@ #endif /**************************************************************************************** -* Stepper Driver Behaviour Definition -****************************************************************************************/ + * Stepper Driver Behaviour Definition + ****************************************************************************************/ #ifdef STEPPER_DRIVER_VERSION_1_X #define STEPPER_ENABLE 1 @@ -125,8 +120,8 @@ #endif /**************************************************************************************** -* Opto Endstop Behaviour Definition -****************************************************************************************/ + * Opto Endstop Behaviour Definition + ****************************************************************************************/ #ifdef OPTO_ENDSTOP_1_X #define SENSORS_INVERTING 0 @@ -135,3 +130,14 @@ #ifdef OPTO_ENDSTOP_2_X #define SENSORS_INVERTING 1 #endif + + +/**************************************************************************************** + * Various Buffer Size Declarations + ****************************************************************************************/ +//we store all queueable commands in one big giant buffer. +// Explicitly allocate memory at compile time for buffer. +#define COMMAND_BUFFER_SIZE 2048 +#define POINT_QUEUE_SIZE 32 +#define POINT_SIZE 9 +#define MAX_PACKET_LENGTH 32 Added: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Datatypes.h =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Datatypes.h (rev 0) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Datatypes.h 2009-01-31 20:16:52 UTC (rev 2468) @@ -0,0 +1,30 @@ +//#include <stddef.h> +#include <stdint.h> + +// our point structure to make things nice. +struct LongPoint { + long x; + long y; + long z; +}; + +// packet states +typedef enum { + PS_START = 0, + PS_LEN, + PS_PAYLOAD, + PS_CRC, + PS_LAST +} +PacketState; + +// various error codes +typedef enum { + RC_GENERIC_ERROR = 0, + RC_OK = 1, + RC_BUFFER_OVERFLOW = 2, + RC_CRC_MISMATCH = 3, + RC_PACKET_TOO_BIG = 4, + RC_CMD_UNSUPPORTED = 5 +} +ResponseCode; Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Packet.h =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Packet.h 2009-01-31 19:54:09 UTC (rev 2467) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Packet.h 2009-01-31 20:16:52 UTC (rev 2468) @@ -3,34 +3,10 @@ //include our various libraries. #include <util/crc16.h> -//#include <stddef.h> #include <stdint.h> -#include "CircularBuffer.h" #include "HardwareSerial.h" -// packet states -typedef enum { - PS_START = 0, - PS_LEN, - PS_PAYLOAD, - PS_CRC, - PS_LAST -} -PacketState; - -// various error codes -typedef enum { - RC_GENERIC_ERROR = 0, - RC_OK = 1, - RC_BUFFER_OVERFLOW = 2, - RC_CRC_MISMATCH = 3, - RC_PACKET_TOO_BIG = 4, - RC_CMD_UNSUPPORTED = 5 -} -ResponseCode; - #define START_BYTE 0xD5 -#define MAX_PACKET_LENGTH 32 class Packet { private: @@ -43,16 +19,14 @@ uint8_t tx_length; uint8_t tx_data[MAX_PACKET_LENGTH]; uint8_t tx_crc; - uint8_t is_command_packet; ResponseCode response_code; - uint8_t uart; public: Packet(uint8_t uart) { - this->uart = uart; + this->uart = uart; init(); } @@ -60,12 +34,11 @@ { state = PS_START; response_code = RC_OK; - target_length = 0; + target_length = 0; rx_length = 0; - rx_crc = 0; + rx_crc = 0; tx_length = 0; - tx_crc = 0; - is_command_packet = false; + tx_crc = 0; } //process a byte from our packet @@ -87,49 +60,26 @@ } else if (state == PS_LEN) // process length byte { - //figure out how much data is coming. - //please note: data may go into command buffer - //instead of query packet buffer, so don't check the size target_length = b; rx_length = 0; state = PS_PAYLOAD; + + if (target_length > MAX_PACKET_LENGTH) + response_code = RC_PACKET_TOO_BIG; } else if (state == PS_PAYLOAD) // process payload byte { - //the first byte determines command vs query - if (rx_length == 0) - { - // top bit high == bufferable command packet (eg. #128-255) - if (b & 1 << 7) - is_command_packet = true; - // top bit low == reply needed query packet (eg. #0-127) - else - is_command_packet = false; - } //just keep reading bytes while we got them. if (rx_length < target_length) { //keep track of CRC. rx_crc = _crc_ibutton_update(rx_crc, b); - //we put different things in different buffers. (query vs command) - if (is_command_packet) - { - //will it fit? - if (commandBuffer.remainingCapacity() == 0) - response_code = RC_BUFFER_OVERFLOW; - else - commandBuffer.append(b); - } - else - { - //will it fit? - if (rx_length < MAX_PACKET_LENGTH) - rx_data[rx_length] = b; - else - response_code = RC_PACKET_TOO_BIG; - } + //will it fit? + if (rx_length < MAX_PACKET_LENGTH) + rx_data[rx_length] = b; + //keep track. rx_length++; } @@ -153,24 +103,19 @@ return (state == PS_LAST); } - bool isQuery() - { - return (response_code == RC_OK && !is_command_packet); - } - uint8_t getLength() { - return rx_length; + return rx_length; } uint8_t getData(uint8_t i) { - return rx_data[i]; + return rx_data[i]; } void unsupported() { - response_code = RC_CMD_UNSUPPORTED; + response_code = RC_CMD_UNSUPPORTED; } void sendReply() @@ -181,7 +126,7 @@ //actually send our response. transmit(START_BYTE); - transmit(tx_length+1); + transmit(tx_length+1); transmit(response_code); //loop through our reply packet payload and send it. @@ -200,9 +145,9 @@ void sendPacket() { - tx_crc = 0; + tx_crc = 0; transmit(START_BYTE); - transmit(tx_length); + transmit(tx_length); //loop through our reply packet payload and send it. for (uint8_t i=0; i<tx_length; i++) @@ -215,13 +160,23 @@ transmit(tx_crc); } +#ifdef __ATMEGA644P__ void transmit(uint8_t d) { - if (uart == 0) - Serial.print(d, BYTE); - else - Serial1.print(d, BYTE); + if (uart == 0) + Serial.print(d, BYTE); + else + Serial1.print(d, BYTE); } +#else + void transmit(uint8_t d) + { + if (uart == 0) + Serial.print(d, BYTE); + else + Serial1.print(d, BYTE); + } +#endif //add a four byte chunk of data to our reply void add_32(uint32_t d) @@ -250,17 +205,17 @@ uint8_t get_8(uint8_t idx) { - return rx_data[idx]; + return rx_data[idx]; } uint16_t get_16(uint8_t idx) { - return (get_8(idx+1) << 8) & get_8(idx); + return (get_8(idx+1) << 8) & get_8(idx); } uint32_t get_32(uint8_t idx) { - return (get_16(idx+2) << 16) & get_16(idx); + return (get_16(idx+2) << 16) & get_16(idx); } }; Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/PacketProcessor.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/PacketProcessor.pde 2009-01-31 19:54:09 UTC (rev 2467) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/PacketProcessor.pde 2009-01-31 20:16:52 UTC (rev 2468) @@ -22,10 +22,6 @@ #define HOST_CMD_WAIT_FOR_TOOL 135 #define HOST_CMD_TOOL_COMMAND 136 -//how many queued commands have we processed? -//this will be used to keep track of our current progress. -unsigned long finishedCommands = 0; - //initialize the firmware to default state. void init_commands() { @@ -45,26 +41,25 @@ //do we have a finished packet? if (hostPacket.isFinished()) { - byte b = hostPacket.get_8(0); - // top bit high == bufferable command packet (eg. #128-255) - if (b & 1 << 7) - { - //okay, throw it in the buffer. - for (int i=1; i<hostPacket.getLength(); i++) - commandBuffer.append(hostPacket.get_8(i)); - } - // top bit low == reply needed query packet (eg. #0-127) - else - { - handle_query(b); - } + byte b = hostPacket.get_8(0); + // top bit high == bufferable command packet (eg. #128-255) + if (b & 1 << 7) + { + //okay, throw it in the buffer. + for (int i=1; i<hostPacket.getLength(); i++) + commandBuffer.append(hostPacket.get_8(i)); } - + // top bit low == reply needed query packet (eg. #0-127) + else + { + handle_query(b); + } + //okay, send our response hostPacket.sendReply(); //only process one packet at a time. - break; + return; } } } @@ -75,199 +70,199 @@ //which one did we get? switch (cmd) { - case HOST_CMD_VERSION: - //get our host version - host_version = hostPacket.get_16(1); - - //send our version back. - hostPacket.add_16(FIRMWARE_VERSION); - break; + case HOST_CMD_VERSION: + //get our host version + host_version = hostPacket.get_16(1); - case HOST_CMD_INIT: - //just initialize - initialize(); - break; - - case HOST_CMD_GET_BUFFER_SIZE: - //send our remaining buffer size. - hostPacket.add_16(commandBuffer.remainingCapacity()); - break; + //send our version back. + hostPacket.add_16(FIRMWARE_VERSION); + break; - case HOST_CMD_CLEAR_BUFFER: - //just clear it. - commandBuffer.clear(); - break; + case HOST_CMD_INIT: + //just initialize + initialize(); + break; - case HOST_CMD_GET_POSITION: - //send our position - hostPacket.add_32(current_steps.x); - hostPacket.add_32(current_steps.y); - hostPacket.add_32(current_steps.z); - hostPacket.add_8(get_endstop_states()); - break; + case HOST_CMD_GET_BUFFER_SIZE: + //send our remaining buffer size. + hostPacket.add_16(commandBuffer.remainingCapacity()); + break; - case HOST_CMD_GET_RANGE: - //send our range - hostPacket.add_32(range_steps.x); - hostPacket.add_32(range_steps.y); - hostPacket.add_32(range_steps.z); - break; + case HOST_CMD_CLEAR_BUFFER: + //just clear it. + commandBuffer.clear(); + break; - case HOST_CMD_SET_RANGE: - //set our range to what the host tells us - range_steps.x = hostPacket.get_32(1); - range_steps.y = hostPacket.get_32(5); - range_steps.z = hostPacket.get_32(9); - - //write it back to eeprom - write_range_to_eeprom(); - break; + case HOST_CMD_GET_POSITION: + //send our position + hostPacket.add_32(current_steps.x); + hostPacket.add_32(current_steps.y); + hostPacket.add_32(current_steps.z); + hostPacket.add_8(get_endstop_states()); + break; - case HOST_CMD_ABORT: - //support a microcontrollers right to choice. - abort_print(); - break; + case HOST_CMD_GET_RANGE: + //send our range + hostPacket.add_32(range_steps.x); + hostPacket.add_32(range_steps.y); + hostPacket.add_32(range_steps.z); + break; - case HOST_CMD_PAUSE: - if (is_machine_paused) - { - //unpause our machine. - is_machine_paused = false; - - //unpause our tools - set_tool_pause_state(false); - - //resume stepping. - enableTimer1Interrupt(); - enable_steppers(); - } - else - { - //pause our activity. - is_machine_paused = true; + case HOST_CMD_SET_RANGE: + //set our range to what the host tells us + range_steps.x = hostPacket.get_32(1); + range_steps.y = hostPacket.get_32(5); + range_steps.z = hostPacket.get_32(9); - //pause our tools - set_tool_pause_state(true); + //write it back to eeprom + write_range_to_eeprom(); + break; - //pause stepping - disableTimer1Interrupt(); - disable_steppers(); - } - break; + case HOST_CMD_ABORT: + //support a microcontrollers right to choice. + abort_print(); + break; - case HOST_CMD_PROBE: - //we dont support this yet. - hostPacket.unsupported(); - break; - - case HOST_CMD_TOOL_QUERY: - send_tool_query(); - break; + case HOST_CMD_PAUSE: + if (is_machine_paused) + { + //unpause our machine. + is_machine_paused = false; + + //unpause our tools + set_tool_pause_state(false); + + //resume stepping. + enableTimer1Interrupt(); + enable_steppers(); + } + else + { + //pause our activity. + is_machine_paused = true; + + //pause our tools + set_tool_pause_state(true); + + //pause stepping + disableTimer1Interrupt(); + disable_steppers(); + } + break; + + case HOST_CMD_PROBE: + //we dont support this yet. + hostPacket.unsupported(); + break; + + case HOST_CMD_TOOL_QUERY: + send_tool_query(); + break; } } //this is for handling buffered commands with no response void handle_commands() { - byte flags = 0; - + byte flags = 0; + //do we have any commands? if (commandBuffer.size()) { //okay, which command are we handling? - byte cmd = commandBuffer.remove_8(); + byte cmd = commandBuffer.remove_8(); switch(cmd) { - //add it to our poitn queue. - case HOST_CMD_QUEUE_POINT_INC: - queue_incremental_point( - commandBuffer.remove_16(), - commandBuffer.remove_16(), - commandBuffer.remove_16(), - commandBuffer.remove_8(), - commandBuffer.remove_16() - ); - break; + //add it to our poitn queue. + case HOST_CMD_QUEUE_POINT_INC: + queue_incremental_point( + commandBuffer.remove_16(), + commandBuffer.remove_16(), + commandBuffer.remove_16(), + commandBuffer.remove_8(), + commandBuffer.remove_16() + ); + break; - //add it to our point queue. - case HOST_CMD_QUEUE_POINT_ABS: - queue_absolute_point( - commandBuffer.remove_32(), - commandBuffer.remove_32(), - commandBuffer.remove_32(), - commandBuffer.remove_8(), - commandBuffer.remove_16() - ); - break; - - //update our current point to where we're told. - case HOST_CMD_SET_POSITION: - wait_until_target_reached(); //dont want to get hasty. - - current_steps.x = commandBuffer.remove_32(); - current_steps.y = commandBuffer.remove_32(); - current_steps.z = commandBuffer.remove_32(); - break; + //add it to our point queue. + case HOST_CMD_QUEUE_POINT_ABS: + queue_absolute_point( + commandBuffer.remove_32(), + commandBuffer.remove_32(), + commandBuffer.remove_32(), + commandBuffer.remove_8(), + commandBuffer.remove_16() + ); + break; + //update our current point to where we're told. + case HOST_CMD_SET_POSITION: + wait_until_target_reached(); //dont want to get hasty. + + current_steps.x = commandBuffer.remove_32(); + current_steps.y = commandBuffer.remove_32(); + current_steps.z = commandBuffer.remove_32(); + break; + //figure out our minimums. - case HOST_CMD_FIND_AXES_MINIMUM: - wait_until_target_reached(); //dont want to get hasty. + case HOST_CMD_FIND_AXES_MINIMUM: + wait_until_target_reached(); //dont want to get hasty. - //no dda interrupts. - disableTimer1Interrupt(); - - //which ones are we going to? - flags = commandBuffer.remove_8(); - - //find them! - seek_minimums( - flags & 1, - flags & (1 << 1), - flags & (1 << 2), - commandBuffer.remove_32(), - commandBuffer.remove_16() - ); - - //turn on point seekign agian. - enableTimer1Interrupt(); - - break; + //no dda interrupts. + disableTimer1Interrupt(); + //which ones are we going to? + flags = commandBuffer.remove_8(); + + //find them! + seek_minimums( + flags & 1, + flags & (1 << 1), + flags & (1 << 2), + commandBuffer.remove_32(), + commandBuffer.remove_16() + ); + + //turn on point seekign agian. + enableTimer1Interrupt(); + + break; + //gotta know your limits. - case HOST_CMD_FIND_AXES_MAXIMUM: - wait_until_target_reached(); //dont want to get hasty. + case HOST_CMD_FIND_AXES_MAXIMUM: + wait_until_target_reached(); //dont want to get hasty. - //TODO: implement this. - break; + //TODO: implement this. + break; - case HOST_CMD_DELAY: - wait_until_target_reached(); //dont want to get hasty. + case HOST_CMD_DELAY: + wait_until_target_reached(); //dont want to get hasty. - //take it easy. - delay(commandBuffer.remove_32()); - break; + //take it easy. + delay(commandBuffer.remove_32()); + break; - case HOST_CMD_CHANGE_TOOL: - wait_until_target_reached(); //dont want to get hasty. + case HOST_CMD_CHANGE_TOOL: + wait_until_target_reached(); //dont want to get hasty. - //extruder, i choose you! - select_tool(commandBuffer.remove_8()); - break; + //extruder, i choose you! + select_tool(commandBuffer.remove_8()); + break; - case HOST_CMD_WAIT_FOR_TOOL: - wait_until_target_reached(); //dont want to get hasty. + case HOST_CMD_WAIT_FOR_TOOL: + wait_until_target_reached(); //dont want to get hasty. - //get your temp in gear, you lazy bum. - wait_for_tool_ready_state( - commandBuffer.remove_8(), - commandBuffer.remove_16(), - commandBuffer.remove_16() + //get your temp in gear, you lazy bum. + wait_for_tool_ready_state( + commandBuffer.remove_8(), + commandBuffer.remove_16(), + commandBuffer.remove_16() ); - break; + break; - case HOST_CMD_TOOL_QUERY: - send_tool_command(); - break; + case HOST_CMD_TOOL_QUERY: + send_tool_command(); + break; } } } Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/SanguinoMaster.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/SanguinoMaster.pde 2009-01-31 19:54:09 UTC (rev 2467) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/SanguinoMaster.pde 2009-01-31 20:16:52 UTC (rev 2468) @@ -14,50 +14,16 @@ //include some basic libraries. #include <WProgram.h> -#include "_misc.h" + +#include "Configuration.h" +#include "Datatypes.h" +#include "CircularBuffer.h" #include "Packet.h" +#include "Variables.h" //this is our firmware version #define FIRMWARE_VERSION 0001 -//this is the version of our host software -unsigned int host_version = 0; - -//these are our packet classes -Packet hostPacket(0); -Packet slavePacket(1); - -//are we paused? -boolean is_machine_paused = false; -boolean is_machine_aborted = false; - -//init our variables -volatile long max_delta; - -volatile long x_counter; -volatile bool x_can_step; -volatile bool x_direction; - -volatile long y_counter; -volatile bool y_can_step; -volatile bool y_direction; - -volatile long z_counter; -volatile bool z_can_step; -volatile bool z_direction; - -//our position tracking variables -volatile LongPoint current_steps; -volatile LongPoint target_steps; -volatile LongPoint delta_steps; -volatile LongPoint range_steps; - -//our point queue variables -#define POINT_QUEUE_SIZE 32 -#define POINT_SIZE 9 -byte rawPointBuffer[POINT_QUEUE_SIZE * POINT_SIZE]; -CircularBuffer pointBuffer(POINT_QUEUE_SIZE * POINT_SIZE, rawPointBuffer); - //set up our firmware for actual usage. void setup() { @@ -66,14 +32,14 @@ //this is a simple text string that identifies us. Serial.print("R3G Master v"); - Serial.print(FIRMWARE_VERSION); + Serial.println(FIRMWARE_VERSION, DEC); } //this function takes us back to our default state. void initialize() { is_machine_paused = false; - + init_serial(); init_commands(); init_steppers(); @@ -83,8 +49,8 @@ //start our hardware serial drivers void init_serial() { - Serial.begin(38400); - Serial1.begin(115200); + Serial.begin(38400); + Serial1.begin(115200); } //handle various things we're required to do. @@ -95,10 +61,10 @@ { //check for and handle any packets that come in. process_host_packets(); - + //only handle our buffer if we're unpaused. if (!is_machine_paused && !is_machine_aborted) - handle_commands(); + handle_commands(); } } @@ -107,7 +73,7 @@ { //yes, we're done here. is_machine_aborted = true; - + //TODO: turn off all of our tools. //turn off steppers too. @@ -117,3 +83,51 @@ //initalize everything to the beginning initialize(); } + +void delayMicrosecondsInterruptible(unsigned int us) +{ + +#if F_CPU >= 16000000L + // for the 16 MHz clock on most Arduino boards + + // for a one-microsecond delay, simply return. the overhead + // of the function call yields a delay of approximately 1 1/8 us. + if (--us == 0) + return; + + // the following loop takes a quarter of a microsecond (4 cycles) + // per iteration, so execute it four times for each microsecond of + // delay requested. + us <<= 2; + + // account for the time taken in the preceeding commands. + us -= 2; +#else + // for the 8 MHz internal clock on the ATmega168 + + // for a one- or two-microsecond delay, simply return. the overhead of + // the function calls takes more than two microseconds. can't just + // subtract two, since us is unsigned; we'd overflow. + if (--us == 0) + return; + if (--us == 0) + return; + + // the following loop takes half of a microsecond (4 cycles) + // per iteration, so execute it twice for each microsecond of + // delay requested. + us <<= 1; + + // partially compensate for the time taken by the preceeding commands. + // we can't subtract any more than this or we'd overflow w/ small delays. + us--; +#endif + + // busy wait + __asm__ __volatile__ ( + "1: sbiw %0,1" "\n\t" // 2 cycles +"brne 1b" : + "=w" (us) : + "0" (us) // 2 cycles + ); +} Copied: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Steppers.pde (from rev 2467, trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/stepper.pde) =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Steppers.pde (rev 0) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Steppers.pde 2009-01-31 20:16:52 UTC (rev 2468) @@ -0,0 +1,508 @@ +//initialize our stepper drivers +void init_steppers() +{ + //clear our point buffer + pointBuffer.clear(); + + //pull in our saved values. + read_range_from_eeprom(); + + //prep timer 1 for handling DDA stuff. + setupTimer1Interrupt(); + + //initialize all our pins. + pinMode(X_STEP_PIN, OUTPUT); + pinMode(X_DIR_PIN, OUTPUT); + pinMode(X_ENABLE_PIN, OUTPUT); + pinMode(X_MIN_PIN, INPUT); + pinMode(X_MAX_PIN, INPUT); + + pinMode(Y_STEP_PIN, OUTPUT); + pinMode(Y_DIR_PIN, OUTPUT); + pinMode(Y_ENABLE_PIN, OUTPUT); + pinMode(Y_MIN_PIN, INPUT); + pinMode(Y_MAX_PIN, INPUT); + + pinMode(Z_STEP_PIN, OUTPUT); + pinMode(Z_DIR_PIN, OUTPUT); + pinMode(Z_ENABLE_PIN, OUTPUT); + pinMode(Z_MIN_PIN, INPUT); + pinMode(Z_MAX_PIN, INPUT); + + //turn them off to start. + disable_steppers(); + + //figure our stuff. + calculate_deltas(); +} + +void seek_minimums(boolean find_x, boolean find_y, boolean find_z, unsigned long step_delay, unsigned int timeout_seconds) +{ + unsigned long start = millis(); + unsigned long end = millis() + (timeout_seconds*1000); + + enable_steppers(); + + boolean found_x = false; + boolean found_y = false; + boolean found_z = false; + + //do it until we time out. + while (millis() < end) + { + //do our steps and check for mins. + if (find_x && !found_x) + { + found_x = find_axis_min(X_STEP_PIN, X_DIR_PIN, X_MIN_PIN); + current_steps.x = 0; + } + if (find_y && !found_y) + { + found_y = find_axis_min(Y_STEP_PIN, Y_DIR_PIN, Y_MIN_PIN); + current_steps.y = 0; + } + if (find_z && !found_z) + { + found_z = find_axis_min(Z_STEP_PIN, Z_DIR_PIN, Z_MIN_PIN); + current_steps.z = 0; + } + + //check to see if we've found all required switches. + if (find_x && !found_x) + true; + else if (find_y && !found_y) + true; + else if (find_z && !found_z) + true; + //found them all. + else + break; + + //do our delay for our axes. + if (step_delay <= 65535) + delayMicrosecondsInterruptible(step_delay); + else + delay(step_delay/1000); + } +} + +boolean find_axis_min(byte step_pin, byte dir_pin, byte min_pin) +{ + //are we at the minimum? + if (read_switch(min_pin)) + { + //move forward until the switch goes open. (slowly) + digitalWrite(dir_pin, HIGH); + while (read_switch(min_pin)) + { + do_step(step_pin); + delay(500); + } + + //okay, now move us back one step. + digitalWrite(dir_pin, LOW); + do_step(step_pin); + + return true; + } + else + { + digitalWrite(dir_pin, LOW); + do_step(step_pin); + } + + return false; +} + +void seek_maximums(boolean find_x, boolean find_y, boolean find_z, unsigned long step_delay, unsigned int timeout_seconds) +{ + unsigned long start = millis(); + unsigned long end = millis() + (timeout_seconds*1000); + + enable_steppers(); + + boolean found_x = false; + boolean found_y = false; + boolean found_z = false; + + //do it until we time out. + while (millis() < end) + { + //do our steps and check for mins. + if (find_x && !found_x) + { + found_x = find_axis_max(X_STEP_PIN, X_DIR_PIN, X_MAX_PIN); + range_steps.x = current_steps.x; + } + if (find_y && !found_y) + { + found_y = find_axis_max(Y_STEP_PIN, Y_DIR_PIN, Y_MAX_PIN); + range_steps.x = current_steps.x; + } + if (find_z && !found_z) + { + found_z = find_axis_max(Z_STEP_PIN, Z_DIR_PIN, Z_MAX_PIN); + range_steps.x = current_steps.x; + } + + //check to see if we've found all required switches. + if (find_x && !found_x) + true; + else if (find_y && !found_y) + true; + else if (find_z && !found_z) + true; + //found them all. + else + { + write_range_to_eeprom(); + break; + } + + //do our delay for our axes. + if (step_delay <= 65535) + delayMicrosecondsInterruptible(step_delay); + else + delay(step_delay/1000); + } +} + +boolean find_axis_max(byte step_pin, byte dir_pin, byte max_pin) +{ + //are we at the minimum? + if (read_switch(max_pin)) + { + //move forward until the switch goes open. (slowly) + digitalWrite(dir_pin, LOW); + while (read_switch(max_pin)) + { + do_step(step_pin); + delay(500); + } + + //okay, now move us back one step. + digitalWrite(dir_pin, HIGH); + do_step(step_pin); + + return true; + } + else + { + digitalWrite(dir_pin, HIGH); + do_step(step_pin); + } + + return false; +} + + +//prepare our variables for a bresenham DDA run. +void prepare_dda() +{ + //enable our steppers if needed. + enable_steppers(); + + //figure out our deltas + max_delta = 0; + max_delta = max(delta_steps.x, delta_steps.y); + max_delta = max(delta_steps.z, max_delta); + + //init stuff. + x_counter = -max_delta/2; + y_counter = -max_delta/2; + z_counter = -max_delta/2; +} + +//do a single step on our DDA line! +inline void dda_step() +{ + //check endstops, position, etc. + x_can_step = can_step(X_MIN_PIN, X_MAX_PIN, current_steps.x, target_steps.x, x_direction); + y_can_step = can_step(Y_MIN_PIN, Y_MAX_PIN, current_steps.y, target_steps.y, y_direction); + z_can_step = can_step(Z_MIN_PIN, Z_MAX_PIN, current_steps.z, target_steps.z, z_direction); + + //increment our x counter, and take steps if required. + if (x_can_step) + { + x_counter += delta_steps.x; + + if (x_counter > 0) + { + do_step(X_STEP_PIN); + x_counter -= max_delta; + + if (x_direction) + current_steps.x++; + else + current_steps.x--; + } + } + + //increment our y counter, and take steps if required. + if (y_can_step) + { + y_counter += delta_steps.y; + + if (y_counter > 0) + { + do_step(Y_STEP_PIN); + y_counter -= max_delta; + + if (y_direction) + current_steps.y++; + else + current_steps.y--; + } + } + + //increment our z counter, and take steps if required. + if (z_can_step) + { + z_counter += delta_steps.z; + + if (z_counter > 0) + { + do_step(Z_STEP_PIN); + z_counter -= max_delta; + + if (z_direction) + current_steps.z++; + else + current_steps.z--; + } + } + + //we're either at our target, or we're stuck. + if (!x_can_step && !y_can_step && !z_can_step) + { + //set us to be at our target. + current_steps.x = target_steps.x; + current_steps.y = target_steps.y; + current_steps.z = target_steps.z; + + //where to next, boss? + grab_next_point(); + } +} + +void grab_next_point() +{ + //can we even step to this? + if (pointBuffer.size() >= POINT_SIZE) + { + //make it so we dont interrupt ourself. + disableTimer1Interrupt(); + + //grab our new target + target_steps.x += pointBuffer.remove_16(); + target_steps.y += pointBuffer.remove_16(); + target_steps.z += pointBuffer.remove_16(); + + //figure out stuff for the move. + calculate_deltas(); + prepare_dda(); + + //start the move! + setTimer1Resolution(pointBuffer.remove_8()); + setTimer1Ceiling(pointBuffer.remove_16()); + enableTimer1Interrupt(); + } +} + +bool can_step(byte min_pin, byte max_pin, long current, long target, byte direction) +{ + //stop us if we're on target + if (target == current) + return false; + //stop us if we're at home and still going + else if (read_switch(min_pin) && !direction) + return false; + //stop us if we're at max and still going + else if (read_switch(max_pin) && direction) + return false; + + //default to being able to step + return true; +} + +//actually send a step signal. +void do_step(byte step_pin) +{ + digitalWrite(step_pin, HIGH); + delayMicrosecondsInterruptible(5); + digitalWrite(step_pin, LOW); +} + +//figure out if we're at a switch or not +bool read_switch(byte pin) +{ + //dual read as crude debounce + if (SENSORS_INVERTING) + return !digitalRead(pin) && !digitalRead(pin); + else + return digitalRead(pin) && digitalRead(pin); +} + +//prepare our deltas and such for our DDA action +void calculate_deltas() +{ + //figure our deltas. + delta_steps.x = abs(target_steps.x - current_steps.x); + delta_steps.y = abs(target_steps.y - current_steps.y); + delta_steps.z = abs(target_steps.z - current_steps.z); + + //what is our direction + x_direction = (target_steps.x >= current_steps.x); + y_direction = (target_steps.y >= current_steps.y); + z_direction = (target_steps.z >= current_steps.z); + + //set our direction pins as well + digitalWrite(X_DIR_PIN, x_direction); + digitalWrite(Y_DIR_PIN, y_direction); + digitalWrite(Z_DIR_PIN, z_direction); +} + +//enable our steppers so we can move them. +void enable_steppers() +{ + if (delta_steps.x > 0) + digitalWrite(X_ENABLE_PIN, STEPPER_ENABLE); + if (delta_steps.y > 0) + digitalWrite(Y_ENABLE_PIN, STEPPER_ENABLE); + if (delta_steps.z > 0) + digitalWrite(Z_ENABLE_PIN, STEPPER_ENABLE); +} + +//turn off steppers to save juice / keep things cool. +void disable_steppers() +{ + //disable our steppers + digitalWrite(X_ENABLE_PIN, STEPPER_DISABLE); + digitalWrite(Y_ENABLE_PIN, STEPPER_DISABLE); + digitalWrite(Z_ENABLE_PIN, STEPPER_DISABLE); +} + +//read all of our states into a single byte. +byte get_endstop_states() +{ + byte state = 0; + + //each one is its own bit in the byte. + state |= read_switch(Z_MAX_PIN) << 5; + state |= read_switch(Z_MIN_PIN) << 4; + state |= read_switch(Y_MAX_PIN) << 3; + state |= read_switch(Y_MIN_PIN) << 2; + state |= read_switch(X_MAX_PIN) << 1; + state |= read_switch(X_MIN_PIN); + + return state; +} + +//TODO: make me work! +void write_range_to_eeprom() +{ + +} + +//TODO: make me work! +void read_range_from_eeprom() +{ + +} + +//queue a point for us to move to +void queue_incremental_point(int x, int y, int z, byte prescaler, unsigned int count) +{ + //wait until we have free space + while (pointBuffer.remainingCapacity() > POINT_SIZE) + delayMicrosecondsInterruptible(500); + + //okay, add in our points. + // x + pointBuffer.append(x & 0xff); + pointBuffer.append(x >> 8); + // y + pointBuffer.append(y & 0xff); + pointBuffer.append(y >> 8); + // z + pointBuffer.append(z & 0xff); + pointBuffer.append(z >> 8); + // prescaler + pointBuffer.append(prescaler); + // counter + pointBuffer.append(count & 0xff); + pointBuffer.append(count >> 8); + + //turn our interrupt on. + enableTimer1Interrupt(); +} + +//TODO: make this proportional based on the delta proportions. +//queue a point for us to move to +void queue_absolute_point(long x, long y, long z, byte prescaler, unsigned int count) +{ + //calculate our total travel in steps + unsigned long delta_x = abs(x - current_steps.x); + unsigned long delta_y = abs(y - current_steps.y); + unsigned long delta_z = abs(z - current_steps.z); + + //setup some variables. + int x_inc = 0; + int y_inc = 0; + int z_inc = 0; + + //keep queueing points while we can. + while (delta_x >= 0 || delta_y >= 0 || delta_z >= 0) + { + //figure out our incremental points. + x_inc = get_increment_from_absolute(delta_x, current_steps.x, x); + y_inc = get_increment_from_absolute(delta_y, current_steps.y, y); + z_inc = get_increment_from_absolute(delta_z, current_steps.z, z); + + //queue our point. + queue_incremental_point(x_inc, y_inc, z_inc, prescaler, count); + + //remove them from our deltas. + delta_x -= x_inc; + delta_x -= y_inc; + delta_x -= z_inc; + } +} + +int get_increment_from_absolute(unsigned long delta, long current, long target) +{ + if (delta > 32767) + { + if (target < current) + return -32767; + else + return 32767; + } + else + { + if (target < current) + return -((int)delta); + else + return (int)delta; + } +} + +boolean is_point_buffer_empty() +{ + //okay, we got points in the buffer. + if (pointBuffer.size() > 0) + return false; + + //still working on a point. + if (current_steps.x != target_steps.x && current_steps.y != target_steps.y && current_steps.z != target_steps.z) + return false; + + //nope, we're done. + return true; +} + +void wait_until_target_reached() +{ + while(!is_point_buffer_empty()) + delayMicrosecondsInterruptible(500); +} Copied: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Tools.pde (from rev 2467, trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/tools2.pde) =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Tools.pde (rev 0) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Tools.pde 2009-01-31 20:16:52 UTC (rev 2468) @@ -0,0 +1,195 @@ +// These are our query commands from the host +#define SLAVE_CMD_VERSION 0 +#define SLAVE_CMD_INIT 1 +#define SLAVE_CMD_GET_TEMP 2 +#define SLAVE_CMD_SET_TEMP 3 +#define SLAVE_CMD_SET_MOTOR_1_PWM 4 +#define SLAVE_CMD_SET_MOTOR_2_PWM 5 +#define SLAVE_CMD_SET_MOTOR_1_RPM 6 +#define SLAVE_CMD_SET_MOTOR_2_RPM 7 +#define SLAVE_CMD_SET_MOTOR_1_DIR 8 +#define SLAVE_CMD_SET_MOTOR_2_DIR 9 +#define SLAVE_CMD_TOGGLE_MOTOR_1 10 +#define SLAVE_CMD_TOGGLE_MOTOR_2 11 +#define SLAVE_CMD_TOGGLE_FAN 12 +#define SLAVE_CMD_TOGGLE_VALVE 13 +#define SLAVE_CMD_SET_SERVO_1_POS 14 +#define SLAVE_CMD_SET_SERVO_2_POS 15 +#define SLAVE_CMD_FILAMENT_STATUS 16 +#define SLAVE_CMD_GET_MOTOR_1_PWM 17 +#define SLAVE_CMD_GET_MOTOR_2_PWM 18 +#define SLAVE_CMD_GET_MOTOR_1_RPM 19 +#define SLAVE_CMD_GET_MOTOR_2_RPM 20 +#define SLAVE_CMD_SELECT_TOOL 21 +#define SLAVE_CMD_IS_TOOL_READY 22 + +//initialize our tools +void init_tools() +{ + //do a scan of tools from address 0-255? + //with a 1 millisecond timeout, this takes ~0.256 seconds. + //we may also want to store which tools are available in eeprom? + for (int i=0; i<256; i++) + { + //are you out there? + if (ping_tool(i)) + { + init_tool(i); + } + } +} + +//ask a tool if its there. +bool ping_tool(byte i) +{ + slavePacket.init(); + + slavePacket.add_8(i); + slavePacket.add_8(SLAVE_CMD_VERSION); + slavePacket.add_16(FIRMWARE_VERSION); + slavePacket.sendPacket(); + + return read_tool_response(1); +} + +//initialize a tool to its default state. +void init_tool(byte i) +{ + slavePacket.init(); + + slavePacket.add_8(i); + slavePacket.add_8(SLAVE_CMD_INIT); + slavePacket.sendPacket(); + + read_tool_response(1); +} + +//select a tool as our current tool, and let it know. +void select_tool(byte tool) +{ + currentToolIndex = tool; + + slavePacket.init(); + + slavePacket.add_8(tool); + slavePacket.add_8(SLAVE_CMD_SELECT_TOOL); + slavePacket.sendPacket(); + + read_tool_response(1); +} + +//ping the tool until it tells us its ready +void wait_for_tool_ready_state(byte tool, int delay_millis, int timeout_seconds) +{ + //setup some defaults + if (delay_millis == 0) + delay_millis = 100; + if (timeout_seconds == 0) + timeout_seconds = 60; + + //check for our end time. + unsigned long now = millis(); + unsigned long end = now + (timeout_seconds * 1000); + + //do it until we hear something, or time out. + while (1) + { + //did we time out yet? + if (millis() >= end) + return; + + //did we hear back from the tool? + if (is_tool_ready(tool)) + return; + + //try again... + delay(delay_millis); + } +} + +//is our tool ready for action? +bool is_tool_ready(byte tool) +{ + slavePacket.init(); + + slavePacket.add_8(tool); + slavePacket.add_8(SLAVE_CMD_IS_TOOL_READY); + slavePacket.sendPacket(); + + //did we get a response? + if (read_tool_response(1)) + { + //is it true? + if (slavePacket.get_8(1) == 1) + return true; + } + + //bail. + return false; +} + +void send_tool_query() +{ + //zero out our packet + slavePacket.init(); + + //load up our packet. + for (byte i=1; i<hostPacket.getLength(); i++) + slavePacket.add_8(hostPacket.get_8(i)); + + //send it and then get our response + slavePacket.sendPacket(); + read_tool_response(60000); + + //now load it up into the host. + for (byte i=0; i<slavePacket.getLength(); i++) + hostPacket.add_8(slavePacket.get_8(i)); +} + +void send_tool_command() +{ + //zero out our packet + slavePacket.init(); + + //add in our tool id and command. + slavePacket.add_16(commandBuffer.remove_16()); + + //load up our packet. + byte len = commandBuffer.remove_8(); + for (byte i=0; i<len; i++) + slavePacket.add_8(commandBuffer.remove_8()); + + //send it and then get our response + slavePacket.sendPacket(); + read_tool_response(60000); +} + +bool read_tool_response(int timeout) +{ + //figure out our timeout stuff. + long start = millis(); + long end = start + timeout; + + //keep reading until we got it. + while (!slavePacket.isFinished()) + { + //read through our available data + if (Serial.available() > 0) + { + //grab a byte and process it. + byte d = Serial1.read(); + slavePacket.process_byte(d); + + //our timeout guy. + if (millis() > end) + return false; + } + } + + return true; +} + +void set_tool_pause_state(bool paused) +{ + //TODO: pause/unpause tool. +} Added: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Variables.h =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Variables.h (rev 0) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Variables.h 2009-01-31 20:16:52 UTC (rev 2468) @@ -0,0 +1,45 @@ +//this is the version of our host software +unsigned int host_version = 0; + +//these are our packet classes +Packet hostPacket(0); +Packet slavePacket(1); + +//are we paused? +boolean is_machine_paused = false; +boolean is_machine_aborted = false; + +//init our variables +volatile long max_delta; + +volatile long x_counter; +volatile bool x_can_step; +volatile bool x_direction; + +volatile long y_counter; +volatile bool y_can_step; +volatile bool y_direction; + +volatile long z_counter; +volatile bool z_can_step; +volatile bool z_direction; + +//our position tracking variables +volatile LongPoint current_steps; +volatile LongPoint target_steps; +volatile LongPoint delta_steps; +volatile LongPoint range_steps; + +//our point queue variables +byte rawPointBuffer[POINT_QUEUE_SIZE * POINT_SIZE]; +CircularBuffer pointBuffer(POINT_QUEUE_SIZE * POINT_SIZE, rawPointBuffer); + +//buffer for our commands +uint8_t underlyingBuffer[COMMAND_BUFFER_SIZE]; +CircularBuffer commandBuffer(COMMAND_BUFFER_SIZE, underlyingBuffer); + +//how many queued commands have we processed? +//this will be used to keep track of our current progress. +unsigned long finishedCommands = 0; + +byte currentToolIndex = 0; \ No newline at end of file Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/_misc.h =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/_misc.h 2009-01-31 19:54:09 UTC (rev 2467) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/_misc.h 2009-01-31 20:16:52 UTC (rev 2468) @@ -1,55 +1 @@ -//#include <stddef.h> -#include <stdint.h> -void delayMicrosecondsInterruptible(unsigned int us) -{ - -#if F_CPU >= 16000000L - // for the 16 MHz clock on most Arduino boards - - // for a one-microsecond delay, simply return. the overhead - // of the function call yields a delay of approximately 1 1/8 us. - if (--us == 0) - return; - - // the following loop takes a quarter of a microsecond (4 cycles) - // per iteration, so execute it four times for each microsecond of - // delay requested. - us <<= 2; - - // account for the time taken in the preceeding commands. - us -= 2; -#else - // for the 8 MHz internal clock on the ATmega168 - - // for a one- or two-microsecond delay, simply return. the overhead of - // the function calls takes more than two microseconds. can't just - // subtract two, since us is unsigned; we'd overflow. - if (--us == 0) - return; - if (--us == 0) - return; - - // the following loop takes half of a microsecond (4 cycles) - // per iteration, so execute it twice for each microsecond of - // delay requested. - us <<= 1; - - // partially compensate for the time taken by the preceeding commands. - // we can't subtract any more than this or we'd overflow w/ small delays. - us--; -#endif - - // busy wait - __asm__ __volatile__ ( - "1: sbiw %0,1" "\n\t" // 2 cycles - "brne 1b" : "=w" (us) : "0" (us) // 2 cycles - ); -} - -// our point structure to make things nice. -struct LongPoint { - long x; - long y; - long z; -}; Deleted: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/stepper.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/stepper.pde 2009-01-31 19:54:09 UTC (rev 2467) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/stepper.pde 2009-01-31 20:16:52 UTC (rev 2468) @@ -1,508 +0,0 @@ -//initialize our stepper drivers -void init_steppers() -{ - //clear our point buffer - pointBuffer.clear(); - - //pull in our saved values. - read_range_from_eeprom(); - - //prep timer 1 for handling DDA stuff. - setupTimer1Interrupt(); - - //initialize all our pins. - pinMode(X_STEP_PIN, OUTPUT); - pinMode(X_DIR_PIN, OUTPUT); - pinMode(X_ENABLE_PIN, OUTPUT); - pinMode(X_MIN_PIN, INPUT); - pinMode(X_MAX_PIN, INPUT); - - pinMode(Y_STEP_PIN, OUTPUT); - pinMode(Y_DIR_PIN, OUTPUT); - pinMode(Y_ENABLE_PIN, OUTPUT); - pinMode(Y_MIN_PIN, INPUT); - pinMode(Y_MAX_PIN, INPUT); - - pinMode(Z_STEP_PIN, OUTPUT); - pinMode(Z_DIR_PIN, OUTPUT); - pinMode(Z_ENABLE_PIN, OUTPUT); - pinMode(Z_MIN_PIN, INPUT); - pinMode(Z_MAX_PIN, INPUT); - - //turn them off to start. - disable_steppers(); - - //figure our stuff. - calculate_deltas(); -} - -void seek_minimums(boolean find_x, boolean find_y, boolean find_z, unsigned long step_delay, unsigned int timeout_seconds) -{ - unsigned long start = millis(); - unsigned long end = millis() + (timeout_seconds*1000); - - enable_steppers(); - - boolean found_x = false; - boolean found_y = false; - boolean found_z = false; - - //do it until we time out. - while (millis() < end) - { - //do our steps and check for mins. - if (find_x && !found_x) - { - found_x = find_axis_min(X_STEP_PIN, X_DIR_PIN, X_MIN_PIN); - current_steps.x = 0; - } - if (find_y && !found_y) - { - found_y = find_axis_min(Y_STEP_PIN, Y_DIR_PIN, Y_MIN_PIN); - current_steps.y = 0; - } - if (find_z && !found_z) - { - found_z = find_axis_min(Z_STEP_PIN, Z_DIR_PIN, Z_MIN_PIN); - current_steps.z = 0; - } - - //check to see if we've found all required switches. - if (find_x && !found_x) - true; - else if (find_y && !found_y) - true; - else if (find_z && !found_z) - true; - //found them all. - else - break; - - //do our delay for our axes. - if (step_delay <= 65535) - delayMicrosecondsInterruptible(step_delay); - else - delay(step_delay/1000); - } -} - -boolean find_axis_min(byte step_pin, byte dir_pin, byte min_pin) -{ - //are we at the minimum? - if (read_switch(min_pin)) - { - //move forward until the switch goes open. (slowly) - digitalWrite(dir_pin, HIGH); - while (read_switch(min_pin)) - { - do_step(step_pin); - delay(500); - } - - //okay, now move us back one step. - digitalWrite(dir_pin, LOW); - do_step(step_pin); - - return true; - } - else - { - digitalWrite(dir_pin, LOW); - do_step(step_pin); - } - - return false; -} - -void seek_maximums(boolean find_x, boolean find_y, boolean find_z, unsigned long step_delay, unsigned int timeout_seconds) -{ - unsigned long start = millis(); - unsigned long end = millis() + (timeout_seconds*1000); - - enable_steppers(); - - boolean found_x = false; - boolean found_y = false; - boolean found_z = false; - - //do it until we time out. - while (millis() < end) - { - //do our steps and check for mins. - if (find_x && !found_x) - { - found_x = find_axis_max(X_STEP_PIN, X_DIR_PIN, X_MAX_PIN); - range_steps.x = current_steps.x; - } - if (find_y && !found_y) - { - found_y = find_axis_max(Y_STEP_PIN, Y_DIR_PIN, Y_MAX_PIN); - range_steps.x = current_steps.x; - } - if (find_z && !found_z) - { - found_z = find_axis_max(Z_STEP_PIN, Z_DIR_PIN, Z_MAX_PIN); - range_steps.x = current_steps.x; - } - - //check to see if we've found all required switches. - if (find_x && !found_x) - true; - else if (find_y && !found_y) - true; - else if (find_z && !found_z) - true; - //found them all. - else - { - write_range_to_eeprom(); - break; - } - - //do our delay for our axes. - if (step_delay <= 65535) - delayMicrosecondsInterruptible(step_delay); - else - delay(step_delay/1000); - } -} - -boolean find_axis_max(byte step_pin, byte dir_pin, byte max_pin) -{ - //are we at the minimum? - if (read_switch(max_pin)) - { - //move forward until the switch goes open. (slowly) - digitalWrite(dir_pin, LOW); - while (read_switch(max_pin)) - { - do_step(step_pin); - delay(500); - } - - //okay, now move us back one step. - digitalWrite(dir_pin, HIGH); - do_step(step_pin); - - return true; - } - else - { - digitalWrite(dir_pin, HIGH); - do_step(step_pin); - } - - return false; -} - - -//prepare our variables for a bresenham DDA run. -void prepare_dda() -{ - //enable our steppers if needed. - enable_steppers(); - - //figure out our deltas - max_delta = 0; - max_delta = max(delta_steps.x, delta_steps.y); - max_delta = max(delta_steps.z, max_delta); - - //init stuff. - x_counter = -max_delta/2; - y_counter = -max_delta/2; - z_counter = -max_delta/2; -} - -//do a single step on our DDA line! -inline void dda_step() -{ - //check endstops, position, etc. - x_can_step = can_step(X_MIN_PIN, X_MAX_PIN, current_steps.x, target_steps.x, x_direction); - y_can_step = can_step(Y_MIN_PIN, Y_MAX_PIN, current_steps.y, target_steps.y, y_direction); - z_can_step = can_step(Z_MIN_PIN, Z_MAX_PIN, current_steps.z, target_steps.z, z_direction); - - //increment our x counter, and take steps if required. - if (x_can_step) - { - x_counter += delta_steps.x; - - if (x_counter > 0) - { - do_step(X_STEP_PIN); - x_counter -= max_delta; - - if (x_direction) - current_steps.x++; - else - current_steps.x--; - } - } - - //increment our y counter, and take steps if required. - if (y_can_step) - { - y_counter += delta_steps.y; - - if (y_counter > 0) - { - do_step(Y_STEP_PIN); - y_counter -= max_delta; - - if (y_direction) - current_steps.y++; - else - current_steps.y--; - } - } - - //increment our z counter, and take steps if required. - if (z_can_step) - { - z_counter += delta_steps.z; - - if (z_counter > 0) - { - do_step(Z_STEP_PIN); - z_counter -= max_delta; - - if (z_direction) - current_steps.z++; - else - current_steps.z--; - } - } - - //we're either at our target, or we're stuck. - if (!x_can_step && !y_can_step && !z_can_step) - { - //set us to be at our target. - current_steps.x = target_steps.x; - current_steps.y = target_steps.y; - current_steps.z = target_steps.z; - - //where to next, boss? - grab_next_point(); - } -} - -void grab_next_point() -{ - //can we even step to this? - if (pointBuffer.size() >= POINT_SIZE) - { - //make it so we dont interrupt ourself. - disableTimer1Interrupt(); - - //grab our new target - target_steps.x += pointBuffer.remove_16(); - target_steps.y += pointBuffer.remove_16(); - target_steps.z += pointBuffer.remove_16(); - - //figure out stuff for the move. - calculate_deltas(); - prepare_dda(); - - //start the move! - setTimer1Resolution(pointBuffer.remove_8()); - setTimer1Ceiling(pointBuffer.remove_16()); - enableTimer1Interrupt(); - } -} - -bool can_step(byte min_pin, byte max_pin, long current, long target, byte direction) -{ - //stop us if we're on target - if (target == current) - return false; - //stop us if we're at home and still going - else if (read_switch(min_pin) && !direction) - return false; - //stop us if we're at max and still going - else if (read_switch(max_pin) && direction) - return false; - - //default to being able to step - return true; -} - -//actually send a step signal. -void do_step(byte step_pin) -{ - digitalWrite(step_pin, HIGH); - delayMicrosecondsInterruptible(5); - digitalWrite(step_pin, LOW); -} - -//figure out if we're at a switch or not -bool read_switch(byte pin) -{ - //dual read as crude debounce - if (SENSORS_INVERTING) - return !digitalRead(pin) && !digitalRead(pin); - else - return digitalRead(pin) && digitalRead(pin); -} - -//prepare our deltas and such for our DDA action -void calculate_deltas() -{ - //figure our deltas. - delta_steps.x = abs(target_steps.x - current_steps.x); - delta_steps.y = abs(target_steps.y - current_steps.y); - delta_steps.z = abs(target_steps.z - current_steps.z); - - //what is our direction - x_direction = (target_steps.x >= current_steps.x); - y_direction = (target_steps.y >= current_steps.y); - z_direction = (target_steps.z >= current_steps.z); - - //set our direction pins as well - digitalWrite(X_DIR_PIN, x_direction); - digitalWrite(Y_DIR_PIN, y_direction); - digitalWrite(Z_DIR_PIN, z_direction); -} - -//enable our steppers so we can move them. -void enable_steppers() -{ - if (delta_steps.x > 0) - digitalWrite(X_ENABLE_PIN, STEPPER_ENABLE); - if (delta_steps.y > 0) - digitalWrite(Y_ENABLE_PIN, STEPPER_ENABLE); - if (delta_steps.z > 0) - digitalWrite(Z_ENABLE_PIN, STEPPER_ENABLE); -} - -//turn off steppers to save juice / keep things cool. -void disable_steppers() -{ - //disable our steppers - digitalWrite(X_ENABLE_PIN, STEPPER_DISABLE); - digitalWrite(Y_ENABLE_PIN, STEPPER_DISABLE); - digitalWrite(Z_ENABLE_PIN, STEPPER_DISABLE); -} - -//read all of our states into a single byte. -byte get_endstop_states() -{ - byte state = 0; - - //each one is its own bit in the byte. - state |= read_switch(Z_MAX_PIN) << 5; - state |= read_switch(Z_MIN_PIN) << 4; - state |= read_switch(Y_MAX_PIN) << 3; - state |= read_switch(Y_MIN_PIN) << 2; - state |= read_switch(X_MAX_PIN) << 1; - state |= read_switch(X_MIN_PIN); - - return state; -} - -//TODO: make me work! -void write_range_to_eeprom() -{ - -} - -//TODO: make me work! -void read_range_from_eeprom() -{ - -} - -//queue a point for us to move to -void queue_incremental_point(int x, int y, int z, byte prescaler, unsigned int count) -{ - //wait until we have free space - while (pointBuffer.remainingCapacity() > POINT_SIZE) - delayMicrosecondsInterruptible(500); - - //okay, add in our points. - // x - pointBuffer.append(x & 0xff); - pointBuffer.append(x >> 8); - // y - pointBuffer.append(y & 0xff); - pointBuffer.append(y >> 8); - // z - pointBuffer.append(z & 0xff); - pointBuffer.append(z >> 8); - // prescaler - pointBuffer.append(prescaler); - // counter - pointBuffer.append(count & 0xff); - pointBuffer.append(count >> 8); - - //turn our interrupt on. - enableTimer1Interrupt(); -} - -//TODO: make this proportional based on the delta proportions. -//queue a point for us to move to -void queue_absolute_point(long x, long y, long z, byte prescaler, unsigned int count) -{ - //calculate our total travel in steps - unsigned long delta_x = abs(x - current_steps.x); - unsigned long delta_y = abs(y - current_steps.y); - unsigned long delta_z = abs(z - current_steps.z); - - //setup some variables. - int x_inc = 0; - int y_inc = 0; - int z_inc = 0; - - //keep queueing points while we can. - while (delta_x >= 0 || delta_y >= 0 || delta_z >= 0) - { - //figure out our incremental points. - x_inc = get_increment_from_absolute(delta_x, current_steps.x, x); - y_inc = get_increment_from_absolute(delta_y, current_steps.y, y); - z_inc = get_increment_from_absolute(delta_z, current_steps.z, z); - - //queue our point. - queue_incremental_point(x_inc, y_inc, z_inc, prescaler, count); - - //remove them from our deltas. - delta_x -= x_inc; - delta_x -= y_inc; - delta_x -= z_inc; - } -} - -int get_increment_from_absolute(unsigned long delta, long current, long target) -{ - if (delta > 32767) - { - if (target < current) - return -32767; - else - return 32767; - } - else - { - if (target < current) - return -((int)delta); - else - return (int)delta; - } -} - -boolean is_point_buffer_empty() -{ - //okay, we got points in the buffer. - if (pointBuffer.size() > 0) - return false; - - //still working on a point. - if (current_steps.x != target_steps.x && current_steps.y != target_steps.y && current_steps.z != target_steps.z) - return false; - - //nope, we're done. - return true; -} - -void wait_until_target_reached() -{ - while(!is_point_buffer_empty()) - delayMicrosecondsInterruptible(500); -} Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/timer1_interrupt_routines.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/timer1_interrupt_routines.pde 2009-01-31 19:54:09 UTC (rev 2467) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/timer1_interrupt_routines.pde 2009-01-31 20:16:52 UTC (rev 2468) @@ -8,126 +8,126 @@ void enableTimer1Interrupt() { - //enable our interrupt! - TIMSK1 |= (1<<OCIE1A); + //enable our interrupt! + TIMSK1 |= (1<<OCIE1A); } void disableTimer1Interrupt() { - TIMSK1 &= ~(1<<ICIE1); - TIMSK1 &= ~(1<<OCIE1A); + TIMSK1 &= ~(1<<ICIE1); + TIMSK1 &= ~(1<<OCIE1A); } void setTimer1Resolution(byte r) { - //from table ... [truncated message content] |
From: <hoe...@us...> - 2009-01-31 19:54:13
|
Revision: 2467 http://reprap.svn.sourceforge.net/reprap/?rev=2467&view=rev Author: hoekstar Date: 2009-01-31 19:54:09 +0000 (Sat, 31 Jan 2009) Log Message: ----------- moving stuff around. Added Paths: ----------- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Configuration.h trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/PacketProcessor.pde trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/stepper.pde trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/tools2.pde Removed Paths: ------------- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/HostPacketProcessor.pde trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/_init.pde trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/steppers.pde trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/tools.pde Copied: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Configuration.h (from rev 2461, trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/_init.pde) =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Configuration.h (rev 0) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Configuration.h 2009-01-31 19:54:09 UTC (rev 2467) @@ -0,0 +1,137 @@ +/**************************************************************************************** +* Here's where you define the overall electronics setup for your machine. +****************************************************************************************/ + +// +// CHOOSE WHICH MOTHERBOARD YOU'RE USING: +// +#define REPRAP_MOTHERBOARD_VERSION_1_0 +//#define REPRAP_MOTHERBOARD_VERSION_1_1 + +// +// CHOOSE WHICH FAMILY OF STEPPER DRIVER YOU'RE USING: +// +//#define STEPPER_DRIVER_VERSION_1_X +#define STEPPER_DRIVER_VERSION_2_X + +// +// CHOOSE WHICH FAMILY OF OPTO ENDSTOP YOU'RE USING: +// +//#define OPTO_ENDSTOP_1_X +#define OPTO_ENDSTOP_2_X + +/**************************************************************************************** +* Sanguino Pin Assignment +****************************************************************************************/ + +//these are the pins for the v1.0 Motherboard. +#ifdef REPRAP_MOTHERBOARD_VERSION_1_0 + +//x axis pins +#define X_STEP_PIN 15 +#define X_DIR_PIN 18 +#define X_ENABLE_PIN 19 +#define X_MIN_PIN 20 +#define X_MAX_PIN 21 + +//y axis pins +#define Y_STEP_PIN 23 +#define Y_DIR_PIN 22 +#define Y_ENABLE_PIN 19 +#define Y_MIN_PIN 25 +#define Y_MAX_PIN 26 + +//z axis pins +#define Z_STEP_PIN 29 +#define Z_DIR_PIN 30 +#define Z_ENABLE_PIN 31 +#define Z_MIN_PIN 2 +#define Z_MAX_PIN 1 + +//our pin for debugging. +#define DEBUG_PIN 0 + +//various SPI select pins +#define SPI_SELECT_1 ? +#define SPI_SELECT_2 ? +#define SPI_SELECT_3 ? + +//our SD card pins +#define SD_CARD_SELECT ? +#define SD_CARD_WRITE ? +#define SD_CARD_DETECT ? + +//our RS485 pins +#define RS485_TX_ENABLE ? +#define RS485_RX_ENABLE ? + +#endif + +//these are the pins for the v1.1 Motherboard. +#ifdef REPRAP_MOTHERBOARD_VERSION_1_1 + +//x axis pins +#define X_STEP_PIN 15 +#define X_DIR_PIN 18 +#define X_ENABLE_PIN 19 +#define X_MIN_PIN 20 +#define X_MAX_PIN 21 + +//y axis pins +#define Y_STEP_PIN 23 +#define Y_DIR_PIN 22 +#define Y_ENABLE_PIN 24 +#define Y_MIN_PIN 25 +#define Y_MAX_PIN 26 + +//z axis pins +#define Z_STEP_PIN 27 +#define Z_DIR_PIN 28 +#define Z_ENABLE_PIN 29 +#define Z_MIN_PIN 30 +#define Z_MAX_PIN 31 + +//our pin for debugging. +#define DEBUG_PIN 0 + +//various SPI select pins +#define SPI_SELECT_1 1 +#define SPI_SELECT_2 3 +#define SPI_SELECT_3 14 + +//our SD card pins +#define SD_CARD_SELECT 4 +#define SD_CARD_WRITE 2 +#define SD_CARD_DETECT 3 + +//our RS485 pins +#define RS485_TX_ENABLE 12 +#define RS485_RX_ENABLE 13 + +#endif + +/**************************************************************************************** +* Stepper Driver Behaviour Definition +****************************************************************************************/ + +#ifdef STEPPER_DRIVER_VERSION_1_X +#define STEPPER_ENABLE 1 +#define STEPPER_DISABLE 0 +#endif + +#ifdef STEPPER_DRIVER_VERSION_2_X +#define STEPPER_ENABLE 0 +#define STEPPER_DISABLE 1 +#endif + +/**************************************************************************************** +* Opto Endstop Behaviour Definition +****************************************************************************************/ + +#ifdef OPTO_ENDSTOP_1_X +#define SENSORS_INVERTING 0 +#endif + +#ifdef OPTO_ENDSTOP_2_X +#define SENSORS_INVERTING 1 +#endif Deleted: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/HostPacketProcessor.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/HostPacketProcessor.pde 2009-01-31 17:42:46 UTC (rev 2466) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/HostPacketProcessor.pde 2009-01-31 19:54:09 UTC (rev 2467) @@ -1,273 +0,0 @@ -// These are our query commands from the host -#define HOST_CMD_VERSION 0 -#define HOST_CMD_INIT 1 -#define HOST_CMD_GET_BUFFER_SIZE 2 -#define HOST_CMD_CLEAR_BUFFER 3 -#define HOST_CMD_GET_POSITION 4 -#define HOST_CMD_GET_RANGE 5 -#define HOST_CMD_SET_RANGE 6 -#define HOST_CMD_ABORT 7 -#define HOST_CMD_PAUSE 8 -#define HOST_CMD_PROBE 9 -#define HOST_CMD_TOOL_QUERY 10 - -// These are our bufferable commands from the host -#define HOST_CMD_QUEUE_POINT_INC 128 -#define HOST_CMD_QUEUE_POINT_ABS 129 -#define HOST_CMD_SET_POSITION 130 -#define HOST_CMD_FIND_AXES_MINIMUM 131 -#define HOST_CMD_FIND_AXES_MAXIMUM 132 -#define HOST_CMD_DELAY 133 -#define HOST_CMD_CHANGE_TOOL 134 -#define HOST_CMD_WAIT_FOR_TOOL 135 -#define HOST_CMD_TOOL_COMMAND 136 - -//how many queued commands have we processed? -//this will be used to keep track of our current progress. -unsigned long finishedCommands = 0; - -//initialize the firmware to default state. -void init_commands() -{ - finishedCommands = 0; -} - -//handle our packets. -void process_host_packets() -{ - //read through our available data - while (Serial.available() > 0) - { - //grab a byte and process it. - byte d = Serial.read(); - hostPacket.process_byte(d); - - //do we have a finished packet? - if (hostPacket.isFinished()) - { - byte b = hostPacket.get_8(0); - // top bit high == bufferable command packet (eg. #128-255) - if (b & 1 << 7) - { - //okay, throw it in the buffer. - for (int i=1; i<hostPacket.getLength(); i++) - commandBuffer.append(hostPacket.get_8(i)); - } - // top bit low == reply needed query packet (eg. #0-127) - else - { - handle_query(b); - } - } - - //okay, send our response - hostPacket.sendReply(); - - //only process one packet at a time. - break; - } - } -} - -//this is for handling query commands that need a response. -void handle_query(byte cmd) -{ - //which one did we get? - switch (cmd) - { - case HOST_CMD_VERSION: - //get our host version - host_version = hostPacket.get_16(1); - - //send our version back. - hostPacket.add_16(FIRMWARE_VERSION); - break; - - case HOST_CMD_INIT: - //just initialize - initialize(); - break; - - case HOST_CMD_GET_BUFFER_SIZE: - //send our remaining buffer size. - hostPacket.add_16(commandBuffer.remainingCapacity()); - break; - - case HOST_CMD_CLEAR_BUFFER: - //just clear it. - commandBuffer.clear(); - break; - - case HOST_CMD_GET_POSITION: - //send our position - hostPacket.add_32(current_steps.x); - hostPacket.add_32(current_steps.y); - hostPacket.add_32(current_steps.z); - hostPacket.add_8(get_endstop_states()); - break; - - case HOST_CMD_GET_RANGE: - //send our range - hostPacket.add_32(range_steps.x); - hostPacket.add_32(range_steps.y); - hostPacket.add_32(range_steps.z); - break; - - case HOST_CMD_SET_RANGE: - //set our range to what the host tells us - range_steps.x = hostPacket.get_32(1); - range_steps.y = hostPacket.get_32(5); - range_steps.z = hostPacket.get_32(9); - - //write it back to eeprom - write_range_to_eeprom(); - break; - - case HOST_CMD_ABORT: - //support a microcontrollers right to choice. - abort_print(); - break; - - case HOST_CMD_PAUSE: - if (is_machine_paused) - { - //unpause our machine. - is_machine_paused = false; - - //unpause our tools - set_tool_pause_state(false); - - //resume stepping. - enableTimer1Interrupt(); - enable_steppers(); - } - else - { - //pause our activity. - is_machine_paused = true; - - //pause our tools - set_tool_pause_state(true); - - //pause stepping - disableTimer1Interrupt(); - disable_steppers(); - } - break; - - case HOST_CMD_PROBE: - //we dont support this yet. - hostPacket.unsupported(); - break; - - case HOST_CMD_TOOL_QUERY: - send_tool_query(); - break; - } -} - -//this is for handling buffered commands with no response -void handle_commands() -{ - byte flags = 0; - - //do we have any commands? - if (commandBuffer.size()) - { - //okay, which command are we handling? - byte cmd = commandBuffer.remove_8(); - switch(cmd) - { - //add it to our poitn queue. - case HOST_CMD_QUEUE_POINT_INC: - queue_incremental_point( - commandBuffer.remove_16(), - commandBuffer.remove_16(), - commandBuffer.remove_16(), - commandBuffer.remove_8(), - commandBuffer.remove_16() - ); - break; - - //add it to our point queue. - case HOST_CMD_QUEUE_POINT_ABS: - queue_absolute_point( - commandBuffer.remove_32(), - commandBuffer.remove_32(), - commandBuffer.remove_32(), - commandBuffer.remove_8(), - commandBuffer.remove_16() - ); - break; - - //update our current point to where we're told. - case HOST_CMD_SET_POSITION: - wait_until_target_reached(); //dont want to get hasty. - - current_steps.x = commandBuffer.remove_32(); - current_steps.y = commandBuffer.remove_32(); - current_steps.z = commandBuffer.remove_32(); - break; - - //figure out our minimums. - case HOST_CMD_FIND_AXES_MINIMUM: - wait_until_target_reached(); //dont want to get hasty. - - //no dda interrupts. - disableTimer1Interrupt(); - - //which ones are we going to? - flags = commandBuffer.remove_8(); - - //find them! - seek_minimums( - flags & 1, - flags & (1 << 1), - flags & (1 << 2), - commandBuffer.remove_32(), - commandBuffer.remove_16() - ); - - //turn on point seekign agian. - enableTimer1Interrupt(); - - break; - - //gotta know your limits. - case HOST_CMD_FIND_AXES_MAXIMUM: - wait_until_target_reached(); //dont want to get hasty. - - //TODO: implement this. - break; - - case HOST_CMD_DELAY: - wait_until_target_reached(); //dont want to get hasty. - - //take it easy. - delay(commandBuffer.remove_32()); - break; - - case HOST_CMD_CHANGE_TOOL: - wait_until_target_reached(); //dont want to get hasty. - - //extruder, i choose you! - select_tool(commandBuffer.remove_8()); - break; - - case HOST_CMD_WAIT_FOR_TOOL: - wait_until_target_reached(); //dont want to get hasty. - - //get your temp in gear, you lazy bum. - wait_for_tool_ready_state( - commandBuffer.remove_8(), - commandBuffer.remove_16(), - commandBuffer.remove_16() - ); - break; - - case HOST_CMD_TOOL_QUERY: - send_tool_command(); - break; - } - } -} Copied: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/PacketProcessor.pde (from rev 2465, trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/HostPacketProcessor.pde) =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/PacketProcessor.pde (rev 0) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/PacketProcessor.pde 2009-01-31 19:54:09 UTC (rev 2467) @@ -0,0 +1,273 @@ +// These are our query commands from the host +#define HOST_CMD_VERSION 0 +#define HOST_CMD_INIT 1 +#define HOST_CMD_GET_BUFFER_SIZE 2 +#define HOST_CMD_CLEAR_BUFFER 3 +#define HOST_CMD_GET_POSITION 4 +#define HOST_CMD_GET_RANGE 5 +#define HOST_CMD_SET_RANGE 6 +#define HOST_CMD_ABORT 7 +#define HOST_CMD_PAUSE 8 +#define HOST_CMD_PROBE 9 +#define HOST_CMD_TOOL_QUERY 10 + +// These are our bufferable commands from the host +#define HOST_CMD_QUEUE_POINT_INC 128 +#define HOST_CMD_QUEUE_POINT_ABS 129 +#define HOST_CMD_SET_POSITION 130 +#define HOST_CMD_FIND_AXES_MINIMUM 131 +#define HOST_CMD_FIND_AXES_MAXIMUM 132 +#define HOST_CMD_DELAY 133 +#define HOST_CMD_CHANGE_TOOL 134 +#define HOST_CMD_WAIT_FOR_TOOL 135 +#define HOST_CMD_TOOL_COMMAND 136 + +//how many queued commands have we processed? +//this will be used to keep track of our current progress. +unsigned long finishedCommands = 0; + +//initialize the firmware to default state. +void init_commands() +{ + finishedCommands = 0; +} + +//handle our packets. +void process_host_packets() +{ + //read through our available data + while (Serial.available() > 0) + { + //grab a byte and process it. + byte d = Serial.read(); + hostPacket.process_byte(d); + + //do we have a finished packet? + if (hostPacket.isFinished()) + { + byte b = hostPacket.get_8(0); + // top bit high == bufferable command packet (eg. #128-255) + if (b & 1 << 7) + { + //okay, throw it in the buffer. + for (int i=1; i<hostPacket.getLength(); i++) + commandBuffer.append(hostPacket.get_8(i)); + } + // top bit low == reply needed query packet (eg. #0-127) + else + { + handle_query(b); + } + } + + //okay, send our response + hostPacket.sendReply(); + + //only process one packet at a time. + break; + } + } +} + +//this is for handling query commands that need a response. +void handle_query(byte cmd) +{ + //which one did we get? + switch (cmd) + { + case HOST_CMD_VERSION: + //get our host version + host_version = hostPacket.get_16(1); + + //send our version back. + hostPacket.add_16(FIRMWARE_VERSION); + break; + + case HOST_CMD_INIT: + //just initialize + initialize(); + break; + + case HOST_CMD_GET_BUFFER_SIZE: + //send our remaining buffer size. + hostPacket.add_16(commandBuffer.remainingCapacity()); + break; + + case HOST_CMD_CLEAR_BUFFER: + //just clear it. + commandBuffer.clear(); + break; + + case HOST_CMD_GET_POSITION: + //send our position + hostPacket.add_32(current_steps.x); + hostPacket.add_32(current_steps.y); + hostPacket.add_32(current_steps.z); + hostPacket.add_8(get_endstop_states()); + break; + + case HOST_CMD_GET_RANGE: + //send our range + hostPacket.add_32(range_steps.x); + hostPacket.add_32(range_steps.y); + hostPacket.add_32(range_steps.z); + break; + + case HOST_CMD_SET_RANGE: + //set our range to what the host tells us + range_steps.x = hostPacket.get_32(1); + range_steps.y = hostPacket.get_32(5); + range_steps.z = hostPacket.get_32(9); + + //write it back to eeprom + write_range_to_eeprom(); + break; + + case HOST_CMD_ABORT: + //support a microcontrollers right to choice. + abort_print(); + break; + + case HOST_CMD_PAUSE: + if (is_machine_paused) + { + //unpause our machine. + is_machine_paused = false; + + //unpause our tools + set_tool_pause_state(false); + + //resume stepping. + enableTimer1Interrupt(); + enable_steppers(); + } + else + { + //pause our activity. + is_machine_paused = true; + + //pause our tools + set_tool_pause_state(true); + + //pause stepping + disableTimer1Interrupt(); + disable_steppers(); + } + break; + + case HOST_CMD_PROBE: + //we dont support this yet. + hostPacket.unsupported(); + break; + + case HOST_CMD_TOOL_QUERY: + send_tool_query(); + break; + } +} + +//this is for handling buffered commands with no response +void handle_commands() +{ + byte flags = 0; + + //do we have any commands? + if (commandBuffer.size()) + { + //okay, which command are we handling? + byte cmd = commandBuffer.remove_8(); + switch(cmd) + { + //add it to our poitn queue. + case HOST_CMD_QUEUE_POINT_INC: + queue_incremental_point( + commandBuffer.remove_16(), + commandBuffer.remove_16(), + commandBuffer.remove_16(), + commandBuffer.remove_8(), + commandBuffer.remove_16() + ); + break; + + //add it to our point queue. + case HOST_CMD_QUEUE_POINT_ABS: + queue_absolute_point( + commandBuffer.remove_32(), + commandBuffer.remove_32(), + commandBuffer.remove_32(), + commandBuffer.remove_8(), + commandBuffer.remove_16() + ); + break; + + //update our current point to where we're told. + case HOST_CMD_SET_POSITION: + wait_until_target_reached(); //dont want to get hasty. + + current_steps.x = commandBuffer.remove_32(); + current_steps.y = commandBuffer.remove_32(); + current_steps.z = commandBuffer.remove_32(); + break; + + //figure out our minimums. + case HOST_CMD_FIND_AXES_MINIMUM: + wait_until_target_reached(); //dont want to get hasty. + + //no dda interrupts. + disableTimer1Interrupt(); + + //which ones are we going to? + flags = commandBuffer.remove_8(); + + //find them! + seek_minimums( + flags & 1, + flags & (1 << 1), + flags & (1 << 2), + commandBuffer.remove_32(), + commandBuffer.remove_16() + ); + + //turn on point seekign agian. + enableTimer1Interrupt(); + + break; + + //gotta know your limits. + case HOST_CMD_FIND_AXES_MAXIMUM: + wait_until_target_reached(); //dont want to get hasty. + + //TODO: implement this. + break; + + case HOST_CMD_DELAY: + wait_until_target_reached(); //dont want to get hasty. + + //take it easy. + delay(commandBuffer.remove_32()); + break; + + case HOST_CMD_CHANGE_TOOL: + wait_until_target_reached(); //dont want to get hasty. + + //extruder, i choose you! + select_tool(commandBuffer.remove_8()); + break; + + case HOST_CMD_WAIT_FOR_TOOL: + wait_until_target_reached(); //dont want to get hasty. + + //get your temp in gear, you lazy bum. + wait_for_tool_ready_state( + commandBuffer.remove_8(), + commandBuffer.remove_16(), + commandBuffer.remove_16() + ); + break; + + case HOST_CMD_TOOL_QUERY: + send_tool_command(); + break; + } + } +} Deleted: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/_init.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/_init.pde 2009-01-31 17:42:46 UTC (rev 2466) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/_init.pde 2009-01-31 19:54:09 UTC (rev 2467) @@ -1,137 +0,0 @@ -/**************************************************************************************** -* Here's where you define the overall electronics setup for your machine. -****************************************************************************************/ - -// -// CHOOSE WHICH MOTHERBOARD YOU'RE USING: -// -#define REPRAP_MOTHERBOARD_VERSION_1_0 -//#define REPRAP_MOTHERBOARD_VERSION_1_1 - -// -// CHOOSE WHICH FAMILY OF STEPPER DRIVER YOU'RE USING: -// -//#define STEPPER_DRIVER_VERSION_1_X -#define STEPPER_DRIVER_VERSION_2_X - -// -// CHOOSE WHICH FAMILY OF OPTO ENDSTOP YOU'RE USING: -// -//#define OPTO_ENDSTOP_1_X -#define OPTO_ENDSTOP_2_X - -/**************************************************************************************** -* Sanguino Pin Assignment -****************************************************************************************/ - -//these are the pins for the v1.0 Motherboard. -#ifdef REPRAP_MOTHERBOARD_VERSION_1_0 - -//x axis pins -#define X_STEP_PIN 15 -#define X_DIR_PIN 18 -#define X_ENABLE_PIN 19 -#define X_MIN_PIN 20 -#define X_MAX_PIN 21 - -//y axis pins -#define Y_STEP_PIN 23 -#define Y_DIR_PIN 22 -#define Y_ENABLE_PIN 19 -#define Y_MIN_PIN 25 -#define Y_MAX_PIN 26 - -//z axis pins -#define Z_STEP_PIN 29 -#define Z_DIR_PIN 30 -#define Z_ENABLE_PIN 31 -#define Z_MIN_PIN 2 -#define Z_MAX_PIN 1 - -//our pin for debugging. -#define DEBUG_PIN 0 - -//various SPI select pins -#define SPI_SELECT_1 ? -#define SPI_SELECT_2 ? -#define SPI_SELECT_3 ? - -//our SD card pins -#define SD_CARD_SELECT ? -#define SD_CARD_WRITE ? -#define SD_CARD_DETECT ? - -//our RS485 pins -#define RS485_TX_ENABLE ? -#define RS485_RX_ENABLE ? - -#endif - -//these are the pins for the v1.1 Motherboard. -#ifdef REPRAP_MOTHERBOARD_VERSION_1_1 - -//x axis pins -#define X_STEP_PIN 15 -#define X_DIR_PIN 18 -#define X_ENABLE_PIN 19 -#define X_MIN_PIN 20 -#define X_MAX_PIN 21 - -//y axis pins -#define Y_STEP_PIN 23 -#define Y_DIR_PIN 22 -#define Y_ENABLE_PIN 24 -#define Y_MIN_PIN 25 -#define Y_MAX_PIN 26 - -//z axis pins -#define Z_STEP_PIN 27 -#define Z_DIR_PIN 28 -#define Z_ENABLE_PIN 29 -#define Z_MIN_PIN 30 -#define Z_MAX_PIN 31 - -//our pin for debugging. -#define DEBUG_PIN 0 - -//various SPI select pins -#define SPI_SELECT_1 1 -#define SPI_SELECT_2 3 -#define SPI_SELECT_3 14 - -//our SD card pins -#define SD_CARD_SELECT 4 -#define SD_CARD_WRITE 2 -#define SD_CARD_DETECT 3 - -//our RS485 pins -#define RS485_TX_ENABLE 12 -#define RS485_RX_ENABLE 13 - -#endif - -/**************************************************************************************** -* Stepper Driver Behaviour Definition -****************************************************************************************/ - -#ifdef STEPPER_DRIVER_VERSION_1_X -#define STEPPER_ENABLE 1 -#define STEPPER_DISABLE 0 -#endif - -#ifdef STEPPER_DRIVER_VERSION_2_X -#define STEPPER_ENABLE 0 -#define STEPPER_DISABLE 1 -#endif - -/**************************************************************************************** -* Opto Endstop Behaviour Definition -****************************************************************************************/ - -#ifdef OPTO_ENDSTOP_1_X -#define SENSORS_INVERTING 0 -#endif - -#ifdef OPTO_ENDSTOP_2_X -#define SENSORS_INVERTING 1 -#endif Copied: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/stepper.pde (from rev 2461, trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/steppers.pde) =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/stepper.pde (rev 0) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/stepper.pde 2009-01-31 19:54:09 UTC (rev 2467) @@ -0,0 +1,508 @@ +//initialize our stepper drivers +void init_steppers() +{ + //clear our point buffer + pointBuffer.clear(); + + //pull in our saved values. + read_range_from_eeprom(); + + //prep timer 1 for handling DDA stuff. + setupTimer1Interrupt(); + + //initialize all our pins. + pinMode(X_STEP_PIN, OUTPUT); + pinMode(X_DIR_PIN, OUTPUT); + pinMode(X_ENABLE_PIN, OUTPUT); + pinMode(X_MIN_PIN, INPUT); + pinMode(X_MAX_PIN, INPUT); + + pinMode(Y_STEP_PIN, OUTPUT); + pinMode(Y_DIR_PIN, OUTPUT); + pinMode(Y_ENABLE_PIN, OUTPUT); + pinMode(Y_MIN_PIN, INPUT); + pinMode(Y_MAX_PIN, INPUT); + + pinMode(Z_STEP_PIN, OUTPUT); + pinMode(Z_DIR_PIN, OUTPUT); + pinMode(Z_ENABLE_PIN, OUTPUT); + pinMode(Z_MIN_PIN, INPUT); + pinMode(Z_MAX_PIN, INPUT); + + //turn them off to start. + disable_steppers(); + + //figure our stuff. + calculate_deltas(); +} + +void seek_minimums(boolean find_x, boolean find_y, boolean find_z, unsigned long step_delay, unsigned int timeout_seconds) +{ + unsigned long start = millis(); + unsigned long end = millis() + (timeout_seconds*1000); + + enable_steppers(); + + boolean found_x = false; + boolean found_y = false; + boolean found_z = false; + + //do it until we time out. + while (millis() < end) + { + //do our steps and check for mins. + if (find_x && !found_x) + { + found_x = find_axis_min(X_STEP_PIN, X_DIR_PIN, X_MIN_PIN); + current_steps.x = 0; + } + if (find_y && !found_y) + { + found_y = find_axis_min(Y_STEP_PIN, Y_DIR_PIN, Y_MIN_PIN); + current_steps.y = 0; + } + if (find_z && !found_z) + { + found_z = find_axis_min(Z_STEP_PIN, Z_DIR_PIN, Z_MIN_PIN); + current_steps.z = 0; + } + + //check to see if we've found all required switches. + if (find_x && !found_x) + true; + else if (find_y && !found_y) + true; + else if (find_z && !found_z) + true; + //found them all. + else + break; + + //do our delay for our axes. + if (step_delay <= 65535) + delayMicrosecondsInterruptible(step_delay); + else + delay(step_delay/1000); + } +} + +boolean find_axis_min(byte step_pin, byte dir_pin, byte min_pin) +{ + //are we at the minimum? + if (read_switch(min_pin)) + { + //move forward until the switch goes open. (slowly) + digitalWrite(dir_pin, HIGH); + while (read_switch(min_pin)) + { + do_step(step_pin); + delay(500); + } + + //okay, now move us back one step. + digitalWrite(dir_pin, LOW); + do_step(step_pin); + + return true; + } + else + { + digitalWrite(dir_pin, LOW); + do_step(step_pin); + } + + return false; +} + +void seek_maximums(boolean find_x, boolean find_y, boolean find_z, unsigned long step_delay, unsigned int timeout_seconds) +{ + unsigned long start = millis(); + unsigned long end = millis() + (timeout_seconds*1000); + + enable_steppers(); + + boolean found_x = false; + boolean found_y = false; + boolean found_z = false; + + //do it until we time out. + while (millis() < end) + { + //do our steps and check for mins. + if (find_x && !found_x) + { + found_x = find_axis_max(X_STEP_PIN, X_DIR_PIN, X_MAX_PIN); + range_steps.x = current_steps.x; + } + if (find_y && !found_y) + { + found_y = find_axis_max(Y_STEP_PIN, Y_DIR_PIN, Y_MAX_PIN); + range_steps.x = current_steps.x; + } + if (find_z && !found_z) + { + found_z = find_axis_max(Z_STEP_PIN, Z_DIR_PIN, Z_MAX_PIN); + range_steps.x = current_steps.x; + } + + //check to see if we've found all required switches. + if (find_x && !found_x) + true; + else if (find_y && !found_y) + true; + else if (find_z && !found_z) + true; + //found them all. + else + { + write_range_to_eeprom(); + break; + } + + //do our delay for our axes. + if (step_delay <= 65535) + delayMicrosecondsInterruptible(step_delay); + else + delay(step_delay/1000); + } +} + +boolean find_axis_max(byte step_pin, byte dir_pin, byte max_pin) +{ + //are we at the minimum? + if (read_switch(max_pin)) + { + //move forward until the switch goes open. (slowly) + digitalWrite(dir_pin, LOW); + while (read_switch(max_pin)) + { + do_step(step_pin); + delay(500); + } + + //okay, now move us back one step. + digitalWrite(dir_pin, HIGH); + do_step(step_pin); + + return true; + } + else + { + digitalWrite(dir_pin, HIGH); + do_step(step_pin); + } + + return false; +} + + +//prepare our variables for a bresenham DDA run. +void prepare_dda() +{ + //enable our steppers if needed. + enable_steppers(); + + //figure out our deltas + max_delta = 0; + max_delta = max(delta_steps.x, delta_steps.y); + max_delta = max(delta_steps.z, max_delta); + + //init stuff. + x_counter = -max_delta/2; + y_counter = -max_delta/2; + z_counter = -max_delta/2; +} + +//do a single step on our DDA line! +inline void dda_step() +{ + //check endstops, position, etc. + x_can_step = can_step(X_MIN_PIN, X_MAX_PIN, current_steps.x, target_steps.x, x_direction); + y_can_step = can_step(Y_MIN_PIN, Y_MAX_PIN, current_steps.y, target_steps.y, y_direction); + z_can_step = can_step(Z_MIN_PIN, Z_MAX_PIN, current_steps.z, target_steps.z, z_direction); + + //increment our x counter, and take steps if required. + if (x_can_step) + { + x_counter += delta_steps.x; + + if (x_counter > 0) + { + do_step(X_STEP_PIN); + x_counter -= max_delta; + + if (x_direction) + current_steps.x++; + else + current_steps.x--; + } + } + + //increment our y counter, and take steps if required. + if (y_can_step) + { + y_counter += delta_steps.y; + + if (y_counter > 0) + { + do_step(Y_STEP_PIN); + y_counter -= max_delta; + + if (y_direction) + current_steps.y++; + else + current_steps.y--; + } + } + + //increment our z counter, and take steps if required. + if (z_can_step) + { + z_counter += delta_steps.z; + + if (z_counter > 0) + { + do_step(Z_STEP_PIN); + z_counter -= max_delta; + + if (z_direction) + current_steps.z++; + else + current_steps.z--; + } + } + + //we're either at our target, or we're stuck. + if (!x_can_step && !y_can_step && !z_can_step) + { + //set us to be at our target. + current_steps.x = target_steps.x; + current_steps.y = target_steps.y; + current_steps.z = target_steps.z; + + //where to next, boss? + grab_next_point(); + } +} + +void grab_next_point() +{ + //can we even step to this? + if (pointBuffer.size() >= POINT_SIZE) + { + //make it so we dont interrupt ourself. + disableTimer1Interrupt(); + + //grab our new target + target_steps.x += pointBuffer.remove_16(); + target_steps.y += pointBuffer.remove_16(); + target_steps.z += pointBuffer.remove_16(); + + //figure out stuff for the move. + calculate_deltas(); + prepare_dda(); + + //start the move! + setTimer1Resolution(pointBuffer.remove_8()); + setTimer1Ceiling(pointBuffer.remove_16()); + enableTimer1Interrupt(); + } +} + +bool can_step(byte min_pin, byte max_pin, long current, long target, byte direction) +{ + //stop us if we're on target + if (target == current) + return false; + //stop us if we're at home and still going + else if (read_switch(min_pin) && !direction) + return false; + //stop us if we're at max and still going + else if (read_switch(max_pin) && direction) + return false; + + //default to being able to step + return true; +} + +//actually send a step signal. +void do_step(byte step_pin) +{ + digitalWrite(step_pin, HIGH); + delayMicrosecondsInterruptible(5); + digitalWrite(step_pin, LOW); +} + +//figure out if we're at a switch or not +bool read_switch(byte pin) +{ + //dual read as crude debounce + if (SENSORS_INVERTING) + return !digitalRead(pin) && !digitalRead(pin); + else + return digitalRead(pin) && digitalRead(pin); +} + +//prepare our deltas and such for our DDA action +void calculate_deltas() +{ + //figure our deltas. + delta_steps.x = abs(target_steps.x - current_steps.x); + delta_steps.y = abs(target_steps.y - current_steps.y); + delta_steps.z = abs(target_steps.z - current_steps.z); + + //what is our direction + x_direction = (target_steps.x >= current_steps.x); + y_direction = (target_steps.y >= current_steps.y); + z_direction = (target_steps.z >= current_steps.z); + + //set our direction pins as well + digitalWrite(X_DIR_PIN, x_direction); + digitalWrite(Y_DIR_PIN, y_direction); + digitalWrite(Z_DIR_PIN, z_direction); +} + +//enable our steppers so we can move them. +void enable_steppers() +{ + if (delta_steps.x > 0) + digitalWrite(X_ENABLE_PIN, STEPPER_ENABLE); + if (delta_steps.y > 0) + digitalWrite(Y_ENABLE_PIN, STEPPER_ENABLE); + if (delta_steps.z > 0) + digitalWrite(Z_ENABLE_PIN, STEPPER_ENABLE); +} + +//turn off steppers to save juice / keep things cool. +void disable_steppers() +{ + //disable our steppers + digitalWrite(X_ENABLE_PIN, STEPPER_DISABLE); + digitalWrite(Y_ENABLE_PIN, STEPPER_DISABLE); + digitalWrite(Z_ENABLE_PIN, STEPPER_DISABLE); +} + +//read all of our states into a single byte. +byte get_endstop_states() +{ + byte state = 0; + + //each one is its own bit in the byte. + state |= read_switch(Z_MAX_PIN) << 5; + state |= read_switch(Z_MIN_PIN) << 4; + state |= read_switch(Y_MAX_PIN) << 3; + state |= read_switch(Y_MIN_PIN) << 2; + state |= read_switch(X_MAX_PIN) << 1; + state |= read_switch(X_MIN_PIN); + + return state; +} + +//TODO: make me work! +void write_range_to_eeprom() +{ + +} + +//TODO: make me work! +void read_range_from_eeprom() +{ + +} + +//queue a point for us to move to +void queue_incremental_point(int x, int y, int z, byte prescaler, unsigned int count) +{ + //wait until we have free space + while (pointBuffer.remainingCapacity() > POINT_SIZE) + delayMicrosecondsInterruptible(500); + + //okay, add in our points. + // x + pointBuffer.append(x & 0xff); + pointBuffer.append(x >> 8); + // y + pointBuffer.append(y & 0xff); + pointBuffer.append(y >> 8); + // z + pointBuffer.append(z & 0xff); + pointBuffer.append(z >> 8); + // prescaler + pointBuffer.append(prescaler); + // counter + pointBuffer.append(count & 0xff); + pointBuffer.append(count >> 8); + + //turn our interrupt on. + enableTimer1Interrupt(); +} + +//TODO: make this proportional based on the delta proportions. +//queue a point for us to move to +void queue_absolute_point(long x, long y, long z, byte prescaler, unsigned int count) +{ + //calculate our total travel in steps + unsigned long delta_x = abs(x - current_steps.x); + unsigned long delta_y = abs(y - current_steps.y); + unsigned long delta_z = abs(z - current_steps.z); + + //setup some variables. + int x_inc = 0; + int y_inc = 0; + int z_inc = 0; + + //keep queueing points while we can. + while (delta_x >= 0 || delta_y >= 0 || delta_z >= 0) + { + //figure out our incremental points. + x_inc = get_increment_from_absolute(delta_x, current_steps.x, x); + y_inc = get_increment_from_absolute(delta_y, current_steps.y, y); + z_inc = get_increment_from_absolute(delta_z, current_steps.z, z); + + //queue our point. + queue_incremental_point(x_inc, y_inc, z_inc, prescaler, count); + + //remove them from our deltas. + delta_x -= x_inc; + delta_x -= y_inc; + delta_x -= z_inc; + } +} + +int get_increment_from_absolute(unsigned long delta, long current, long target) +{ + if (delta > 32767) + { + if (target < current) + return -32767; + else + return 32767; + } + else + { + if (target < current) + return -((int)delta); + else + return (int)delta; + } +} + +boolean is_point_buffer_empty() +{ + //okay, we got points in the buffer. + if (pointBuffer.size() > 0) + return false; + + //still working on a point. + if (current_steps.x != target_steps.x && current_steps.y != target_steps.y && current_steps.z != target_steps.z) + return false; + + //nope, we're done. + return true; +} + +void wait_until_target_reached() +{ + while(!is_point_buffer_empty()) + delayMicrosecondsInterruptible(500); +} Deleted: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/steppers.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/steppers.pde 2009-01-31 17:42:46 UTC (rev 2466) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/steppers.pde 2009-01-31 19:54:09 UTC (rev 2467) @@ -1,508 +0,0 @@ -//initialize our stepper drivers -void init_steppers() -{ - //clear our point buffer - pointBuffer.clear(); - - //pull in our saved values. - read_range_from_eeprom(); - - //prep timer 1 for handling DDA stuff. - setupTimer1Interrupt(); - - //initialize all our pins. - pinMode(X_STEP_PIN, OUTPUT); - pinMode(X_DIR_PIN, OUTPUT); - pinMode(X_ENABLE_PIN, OUTPUT); - pinMode(X_MIN_PIN, INPUT); - pinMode(X_MAX_PIN, INPUT); - - pinMode(Y_STEP_PIN, OUTPUT); - pinMode(Y_DIR_PIN, OUTPUT); - pinMode(Y_ENABLE_PIN, OUTPUT); - pinMode(Y_MIN_PIN, INPUT); - pinMode(Y_MAX_PIN, INPUT); - - pinMode(Z_STEP_PIN, OUTPUT); - pinMode(Z_DIR_PIN, OUTPUT); - pinMode(Z_ENABLE_PIN, OUTPUT); - pinMode(Z_MIN_PIN, INPUT); - pinMode(Z_MAX_PIN, INPUT); - - //turn them off to start. - disable_steppers(); - - //figure our stuff. - calculate_deltas(); -} - -void seek_minimums(boolean find_x, boolean find_y, boolean find_z, unsigned long step_delay, unsigned int timeout_seconds) -{ - unsigned long start = millis(); - unsigned long end = millis() + (timeout_seconds*1000); - - enable_steppers(); - - boolean found_x = false; - boolean found_y = false; - boolean found_z = false; - - //do it until we time out. - while (millis() < end) - { - //do our steps and check for mins. - if (find_x && !found_x) - { - found_x = find_axis_min(X_STEP_PIN, X_DIR_PIN, X_MIN_PIN); - current_steps.x = 0; - } - if (find_y && !found_y) - { - found_y = find_axis_min(Y_STEP_PIN, Y_DIR_PIN, Y_MIN_PIN); - current_steps.y = 0; - } - if (find_z && !found_z) - { - found_z = find_axis_min(Z_STEP_PIN, Z_DIR_PIN, Z_MIN_PIN); - current_steps.z = 0; - } - - //check to see if we've found all required switches. - if (find_x && !found_x) - true; - else if (find_y && !found_y) - true; - else if (find_z && !found_z) - true; - //found them all. - else - break; - - //do our delay for our axes. - if (step_delay <= 65535) - delayMicrosecondsInterruptible(step_delay); - else - delay(step_delay/1000); - } -} - -boolean find_axis_min(byte step_pin, byte dir_pin, byte min_pin) -{ - //are we at the minimum? - if (read_switch(min_pin)) - { - //move forward until the switch goes open. (slowly) - digitalWrite(dir_pin, HIGH); - while (read_switch(min_pin)) - { - do_step(step_pin); - delay(500); - } - - //okay, now move us back one step. - digitalWrite(dir_pin, LOW); - do_step(step_pin); - - return true; - } - else - { - digitalWrite(dir_pin, LOW); - do_step(step_pin); - } - - return false; -} - -void seek_maximums(boolean find_x, boolean find_y, boolean find_z, unsigned long step_delay, unsigned int timeout_seconds) -{ - unsigned long start = millis(); - unsigned long end = millis() + (timeout_seconds*1000); - - enable_steppers(); - - boolean found_x = false; - boolean found_y = false; - boolean found_z = false; - - //do it until we time out. - while (millis() < end) - { - //do our steps and check for mins. - if (find_x && !found_x) - { - found_x = find_axis_max(X_STEP_PIN, X_DIR_PIN, X_MAX_PIN); - range_steps.x = current_steps.x; - } - if (find_y && !found_y) - { - found_y = find_axis_max(Y_STEP_PIN, Y_DIR_PIN, Y_MAX_PIN); - range_steps.x = current_steps.x; - } - if (find_z && !found_z) - { - found_z = find_axis_max(Z_STEP_PIN, Z_DIR_PIN, Z_MAX_PIN); - range_steps.x = current_steps.x; - } - - //check to see if we've found all required switches. - if (find_x && !found_x) - true; - else if (find_y && !found_y) - true; - else if (find_z && !found_z) - true; - //found them all. - else - { - write_range_to_eeprom(); - break; - } - - //do our delay for our axes. - if (step_delay <= 65535) - delayMicrosecondsInterruptible(step_delay); - else - delay(step_delay/1000); - } -} - -boolean find_axis_max(byte step_pin, byte dir_pin, byte max_pin) -{ - //are we at the minimum? - if (read_switch(max_pin)) - { - //move forward until the switch goes open. (slowly) - digitalWrite(dir_pin, LOW); - while (read_switch(max_pin)) - { - do_step(step_pin); - delay(500); - } - - //okay, now move us back one step. - digitalWrite(dir_pin, HIGH); - do_step(step_pin); - - return true; - } - else - { - digitalWrite(dir_pin, HIGH); - do_step(step_pin); - } - - return false; -} - - -//prepare our variables for a bresenham DDA run. -void prepare_dda() -{ - //enable our steppers if needed. - enable_steppers(); - - //figure out our deltas - max_delta = 0; - max_delta = max(delta_steps.x, delta_steps.y); - max_delta = max(delta_steps.z, max_delta); - - //init stuff. - x_counter = -max_delta/2; - y_counter = -max_delta/2; - z_counter = -max_delta/2; -} - -//do a single step on our DDA line! -inline void dda_step() -{ - //check endstops, position, etc. - x_can_step = can_step(X_MIN_PIN, X_MAX_PIN, current_steps.x, target_steps.x, x_direction); - y_can_step = can_step(Y_MIN_PIN, Y_MAX_PIN, current_steps.y, target_steps.y, y_direction); - z_can_step = can_step(Z_MIN_PIN, Z_MAX_PIN, current_steps.z, target_steps.z, z_direction); - - //increment our x counter, and take steps if required. - if (x_can_step) - { - x_counter += delta_steps.x; - - if (x_counter > 0) - { - do_step(X_STEP_PIN); - x_counter -= max_delta; - - if (x_direction) - current_steps.x++; - else - current_steps.x--; - } - } - - //increment our y counter, and take steps if required. - if (y_can_step) - { - y_counter += delta_steps.y; - - if (y_counter > 0) - { - do_step(Y_STEP_PIN); - y_counter -= max_delta; - - if (y_direction) - current_steps.y++; - else - current_steps.y--; - } - } - - //increment our z counter, and take steps if required. - if (z_can_step) - { - z_counter += delta_steps.z; - - if (z_counter > 0) - { - do_step(Z_STEP_PIN); - z_counter -= max_delta; - - if (z_direction) - current_steps.z++; - else - current_steps.z--; - } - } - - //we're either at our target, or we're stuck. - if (!x_can_step && !y_can_step && !z_can_step) - { - //set us to be at our target. - current_steps.x = target_steps.x; - current_steps.y = target_steps.y; - current_steps.z = target_steps.z; - - //where to next, boss? - grab_next_point(); - } -} - -void grab_next_point() -{ - //can we even step to this? - if (pointBuffer.size() >= POINT_SIZE) - { - //make it so we dont interrupt ourself. - disableTimer1Interrupt(); - - //grab our new target - target_steps.x += pointBuffer.remove_16(); - target_steps.y += pointBuffer.remove_16(); - target_steps.z += pointBuffer.remove_16(); - - //figure out stuff for the move. - calculate_deltas(); - prepare_dda(); - - //start the move! - setTimer1Resolution(pointBuffer.remove_8()); - setTimer1Ceiling(pointBuffer.remove_16()); - enableTimer1Interrupt(); - } -} - -bool can_step(byte min_pin, byte max_pin, long current, long target, byte direction) -{ - //stop us if we're on target - if (target == current) - return false; - //stop us if we're at home and still going - else if (read_switch(min_pin) && !direction) - return false; - //stop us if we're at max and still going - else if (read_switch(max_pin) && direction) - return false; - - //default to being able to step - return true; -} - -//actually send a step signal. -void do_step(byte step_pin) -{ - digitalWrite(step_pin, HIGH); - delayMicrosecondsInterruptible(5); - digitalWrite(step_pin, LOW); -} - -//figure out if we're at a switch or not -bool read_switch(byte pin) -{ - //dual read as crude debounce - if (SENSORS_INVERTING) - return !digitalRead(pin) && !digitalRead(pin); - else - return digitalRead(pin) && digitalRead(pin); -} - -//prepare our deltas and such for our DDA action -void calculate_deltas() -{ - //figure our deltas. - delta_steps.x = abs(target_steps.x - current_steps.x); - delta_steps.y = abs(target_steps.y - current_steps.y); - delta_steps.z = abs(target_steps.z - current_steps.z); - - //what is our direction - x_direction = (target_steps.x >= current_steps.x); - y_direction = (target_steps.y >= current_steps.y); - z_direction = (target_steps.z >= current_steps.z); - - //set our direction pins as well - digitalWrite(X_DIR_PIN, x_direction); - digitalWrite(Y_DIR_PIN, y_direction); - digitalWrite(Z_DIR_PIN, z_direction); -} - -//enable our steppers so we can move them. -void enable_steppers() -{ - if (delta_steps.x > 0) - digitalWrite(X_ENABLE_PIN, STEPPER_ENABLE); - if (delta_steps.y > 0) - digitalWrite(Y_ENABLE_PIN, STEPPER_ENABLE); - if (delta_steps.z > 0) - digitalWrite(Z_ENABLE_PIN, STEPPER_ENABLE); -} - -//turn off steppers to save juice / keep things cool. -void disable_steppers() -{ - //disable our steppers - digitalWrite(X_ENABLE_PIN, STEPPER_DISABLE); - digitalWrite(Y_ENABLE_PIN, STEPPER_DISABLE); - digitalWrite(Z_ENABLE_PIN, STEPPER_DISABLE); -} - -//read all of our states into a single byte. -byte get_endstop_states() -{ - byte state = 0; - - //each one is its own bit in the byte. - state |= read_switch(Z_MAX_PIN) << 5; - state |= read_switch(Z_MIN_PIN) << 4; - state |= read_switch(Y_MAX_PIN) << 3; - state |= read_switch(Y_MIN_PIN) << 2; - state |= read_switch(X_MAX_PIN) << 1; - state |= read_switch(X_MIN_PIN); - - return state; -} - -//TODO: make me work! -void write_range_to_eeprom() -{ - -} - -//TODO: make me work! -void read_range_from_eeprom() -{ - -} - -//queue a point for us to move to -void queue_incremental_point(int x, int y, int z, byte prescaler, unsigned int count) -{ - //wait until we have free space - while (pointBuffer.remainingCapacity() > POINT_SIZE) - delayMicrosecondsInterruptible(500); - - //okay, add in our points. - // x - pointBuffer.append(x & 0xff); - pointBuffer.append(x >> 8); - // y - pointBuffer.append(y & 0xff); - pointBuffer.append(y >> 8); - // z - pointBuffer.append(z & 0xff); - pointBuffer.append(z >> 8); - // prescaler - pointBuffer.append(prescaler); - // counter - pointBuffer.append(count & 0xff); - pointBuffer.append(count >> 8); - - //turn our interrupt on. - enableTimer1Interrupt(); -} - -//TODO: make this proportional based on the delta proportions. -//queue a point for us to move to -void queue_absolute_point(long x, long y, long z, byte prescaler, unsigned int count) -{ - //calculate our total travel in steps - unsigned long delta_x = abs(x - current_steps.x); - unsigned long delta_y = abs(y - current_steps.y); - unsigned long delta_z = abs(z - current_steps.z); - - //setup some variables. - int x_inc = 0; - int y_inc = 0; - int z_inc = 0; - - //keep queueing points while we can. - while (delta_x >= 0 || delta_y >= 0 || delta_z >= 0) - { - //figure out our incremental points. - x_inc = get_increment_from_absolute(delta_x, current_steps.x, x); - y_inc = get_increment_from_absolute(delta_y, current_steps.y, y); - z_inc = get_increment_from_absolute(delta_z, current_steps.z, z); - - //queue our point. - queue_incremental_point(x_inc, y_inc, z_inc, prescaler, count); - - //remove them from our deltas. - delta_x -= x_inc; - delta_x -= y_inc; - delta_x -= z_inc; - } -} - -int get_increment_from_absolute(unsigned long delta, long current, long target) -{ - if (delta > 32767) - { - if (target < current) - return -32767; - else - return 32767; - } - else - { - if (target < current) - return -((int)delta); - else - return (int)delta; - } -} - -boolean is_point_buffer_empty() -{ - //okay, we got points in the buffer. - if (pointBuffer.size() > 0) - return false; - - //still working on a point. - if (current_steps.x != target_steps.x && current_steps.y != target_steps.y && current_steps.z != target_steps.z) - return false; - - //nope, we're done. - return true; -} - -void wait_until_target_reached() -{ - while(!is_point_buffer_empty()) - delayMicrosecondsInterruptible(500); -} Deleted: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/tools.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/tools.pde 2009-01-31 17:42:46 UTC (rev 2466) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/tools.pde 2009-01-31 19:54:09 UTC (rev 2467) @@ -1,197 +0,0 @@ -// These are our query commands from the host -#define SLAVE_CMD_VERSION 0 -#define SLAVE_CMD_INIT 1 -#define SLAVE_CMD_GET_TEMP 2 -#define SLAVE_CMD_SET_TEMP 3 -#define SLAVE_CMD_SET_MOTOR_1_PWM 4 -#define SLAVE_CMD_SET_MOTOR_2_PWM 5 -#define SLAVE_CMD_SET_MOTOR_1_RPM 6 -#define SLAVE_CMD_SET_MOTOR_2_RPM 7 -#define SLAVE_CMD_SET_MOTOR_1_DIR 8 -#define SLAVE_CMD_SET_MOTOR_2_DIR 9 -#define SLAVE_CMD_TOGGLE_MOTOR_1 10 -#define SLAVE_CMD_TOGGLE_MOTOR_2 11 -#define SLAVE_CMD_TOGGLE_FAN 12 -#define SLAVE_CMD_TOGGLE_VALVE 13 -#define SLAVE_CMD_SET_SERVO_1_POS 14 -#define SLAVE_CMD_SET_SERVO_2_POS 15 -#define SLAVE_CMD_FILAMENT_STATUS 16 -#define SLAVE_CMD_GET_MOTOR_1_PWM 17 -#define SLAVE_CMD_GET_MOTOR_2_PWM 18 -#define SLAVE_CMD_GET_MOTOR_1_RPM 19 -#define SLAVE_CMD_GET_MOTOR_2_RPM 20 -#define SLAVE_CMD_SELECT_TOOL 21 -#define SLAVE_CMD_IS_TOOL_READY 22 - -byte currentToolIndex = 0; - -//initialize our tools -void init_tools() -{ - //do a scan of tools from address 0-255? - //with a 1 millisecond timeout, this takes ~0.256 seconds. - //we may also want to store which tools are available in eeprom? - for (int i=0; i<256; i++) - { - //are you out there? - if (ping_tool(i)) - { - init_tool(i); - } - } -} - -//ask a tool if its there. -boolean ping_tool(byte i) -{ - slavePacket.init(); - - slavePacket.add_8(i); - slavePacket.add_8(SLAVE_CMD_VERSION); - slavePacket.add_16(FIRMWARE_VERSION); - slavePacket.sendPacket(); - - return read_tool_response(1); -} - -//initialize a tool to its default state. -void init_tool(byte i) -{ - slavePacket.init(); - - slavePacket.add_8(i); - slavePacket.add_8(SLAVE_CMD_INIT); - slavePacket.sendPacket(); - - read_tool_response(1); -} - -//select a tool as our current tool, and let it know. -void select_tool(byte tool) -{ - currentToolIndex = tool; - - slavePacket.init(); - - slavePacket.add_8(tool); - slavePacket.add_8(SLAVE_CMD_SELECT_TOOL); - slavePacket.sendPacket(); - - read_tool_response(1); -} - -//ping the tool until it tells us its ready -void wait_for_tool_ready_state(byte tool, int delay_millis, int timeout_seconds) -{ - //setup some defaults - if (delay_millis == 0) - delay_millis = 100; - if (timeout_seconds == 0) - timeout_seconds = 60; - - //check for our end time. - unsigned long now = millis(); - unsigned long end = now + (timeout_seconds * 1000); - - //do it until we hear something, or time out. - while (1) - { - //did we time out yet? - if (millis() >= end) - return; - - //did we hear back from the tool? - if (is_tool_ready(tool)) - return; - - //try again... - delay(delay_millis); - } -} - -//is our tool ready for action? -boolean is_tool_ready(byte tool) -{ - slavePacket.init(); - - slavePacket.add_8(tool); - slavePacket.add_8(SLAVE_CMD_IS_TOOL_READY); - slavePacket.sendPacket(); - - //did we get a response? - if (read_tool_response(1)) - { - //is it true? - if (slavePacket.get_8(1) == 1) - return true; - } - - //bail. - return false; -} - -void send_tool_query() -{ - //zero out our packet - slavePacket.init(); - - //load up our packet. - for (byte i=1; i<hostPacket.getLength(); i++) - slavePacket.add_8(hostPacket.get_8(i)); - - //send it and then get our response - slavePacket.sendPacket(); - read_tool_response(60000); - - //now load it up into the host. - for (byte i=0; i<slavePacket.getLength(); i++) - hostPacket.add_8(slavePacket.get_8(i)); -} - -void send_tool_command() -{ - //zero out our packet - slavePacket.init(); - - //add in our tool id and command. - slavePacket.add_16(commandBuffer.remove_16()); - - //load up our packet. - byte len = commandBuffer.remove_8(); - for (byte i=0; i<len; i++) - slavePacket.add_8(commandBuffer.remove_8()); - - //send it and then get our response - slavePacket.sendPacket(); - read_tool_response(60000); -} - -boolean read_tool_response(int timeout) -{ - //figure out our timeout stuff. - long start = millis(); - long end = start + timeout; - - //keep reading until we got it. - while (!slavePacket.isFinished()) - { - //read through our available data - if (Serial.available() > 0) - { - //grab a byte and process it. - byte d = Serial1.read(); - slavePacket.process_byte(d); - - //our timeout guy. - if (millis() > end) - return false; - } - } - - return true; -} - -void set_tool_pause_state(boolean paused) -{ - //TODO: pause/unpause tool. -} Copied: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/tools2.pde (from rev 2461, trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/tools.pde) =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/tools2.pde (rev 0) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/tools2.pde 2009-01-31 19:54:09 UTC (rev 2467) @@ -0,0 +1,197 @@ +// These are our query commands from the host +#define SLAVE_CMD_VERSION 0 +#define SLAVE_CMD_INIT 1 +#define SLAVE_CMD_GET_TEMP 2 +#define SLAVE_CMD_SET_TEMP 3 +#define SLAVE_CMD_SET_MOTOR_1_PWM 4 +#define SLAVE_CMD_SET_MOTOR_2_PWM 5 +#define SLAVE_CMD_SET_MOTOR_1_RPM 6 +#define SLAVE_CMD_SET_MOTOR_2_RPM 7 +#define SLAVE_CMD_SET_MOTOR_1_DIR 8 +#define SLAVE_CMD_SET_MOTOR_2_DIR 9 +#define SLAVE_CMD_TOGGLE_MOTOR_1 10 +#define SLAVE_CMD_TOGGLE_MOTOR_2 11 +#define SLAVE_CMD_TOGGLE_FAN 12 +#define SLAVE_CMD_TOGGLE_VALVE 13 +#define SLAVE_CMD_SET_SERVO_1_POS 14 +#define SLAVE_CMD_SET_SERVO_2_POS 15 +#define SLAVE_CMD_FILAMENT_STATUS 16 +#define SLAVE_CMD_GET_MOTOR_1_PWM 17 +#define SLAVE_CMD_GET_MOTOR_2_PWM 18 +#define SLAVE_CMD_GET_MOTOR_1_RPM 19 +#define SLAVE_CMD_GET_MOTOR_2_RPM 20 +#define SLAVE_CMD_SELECT_TOOL 21 +#define SLAVE_CMD_IS_TOOL_READY 22 + +byte currentToolIndex = 0; + +//initialize our tools +void init_tools() +{ + //do a scan of tools from address 0-255? + //with a 1 millisecond timeout, this takes ~0.256 seconds. + //we may also want to store which tools are available in eeprom? + for (int i=0; i<256; i++) + { + //are you out there? + if (ping_tool(i)) + { + init_tool(i); + } + } +} + +//ask a tool if its there. +boolean ping_tool(byte i) +{ + slavePacket.init(); + + slavePacket.add_8(i); + slavePacket.add_8(SLAVE_CMD_VERSION); + slavePacket.add_16(FIRMWARE_VERSION); + slavePacket.sendPacket(); + + return read_tool_response(1); +} + +//initialize a tool to its default state. +void init_tool(byte i) +{ + slavePacket.init(); + + slavePacket.add_8(i); + slavePacket.add_8(SLAVE_CMD_INIT); + slavePacket.sendPacket(); + + read_tool_response(1); +} + +//select a tool as our current tool, and let it know. +void select_tool(byte tool) +{ + currentToolIndex = tool; + + slavePacket.init(); + + slavePacket.add_8(tool); + slavePacket.add_8(SLAVE_CMD_SELECT_TOOL); + slavePacket.sendPacket(); + + read_tool_response(1); +} + +//ping the tool until it tells us its ready +void wait_for_tool_ready_state(byte tool, int delay_millis, int timeout_seconds) +{ + //setup some defaults + if (delay_millis == 0) + delay_millis = 100; + if (timeout_seconds == 0) + timeout_seconds = 60; + + //check for our end time. + unsigned long now = millis(); + unsigned long end = now + (timeout_seconds * 1000); + + //do it until we hear something, or time out. + while (1) + { + //did we time out yet? + if (millis() >= end) + return; + + //did we hear back from the tool? + if (is_tool_ready(tool)) + return; + + //try again... + delay(delay_millis); + } +} + +//is our tool ready for action? +boolean is_tool_ready(byte tool) +{ + slavePacket.init(); + + slavePacket.add_8(tool); + slavePacket.add_8(SLAVE_CMD_IS_TOOL_READY); + slavePacket.sendPacket(); + + //did we get a response? + if (read_tool_response(1)) + { + //is it true? + if (slavePacket.get_8(1) == 1) + return true; + } + + //bail. + return false; +} + +void send_tool_query() +{ + //zero out our packet + slavePacket.init(); + + //load up our packet. + for (byte i=1; i<hostPacket.getLength(); i++) + slavePacket.add_8(hostPacket.get_8(i)); + + //send it and then get our response + slavePacket.sendPacket(); + read_tool_response(60000); + + //now load it up into the host. + for (byte i=0; i<slavePacket.getLength(); i++) + hostPacket.add_8(slavePacket.get_8(i)); +} + +void send_tool_command() +{ + //zero out our packet + slavePacket.init(); + + //add in our tool id and command. + slavePacket.add_16(commandBuffer.remove_16()); + + //load up our packet. + byte len = commandBuffer.remove_8(); + for (byte i=0; i<len; i++) + slavePacket.add_8(commandBuffer.remove_8()); + + //send it and then get our response + slavePacket.sendPacket(); + read_tool_response(60000); +} + +boolean read_tool_response(int timeout) +{ + //figure out our timeout stuff. + long start = millis(); + long end = start + timeout; + + //keep reading until we got it. + while (!slavePacket.isFinished()) + { + //read through our available data + if (Serial.available() > 0) + { + //grab a byte and process it. + byte d = Serial1.read(); + slavePacket.process_byte(d); + + //our timeout guy. + if (millis() > end) + return false; + } + } + + return true; +} + +void set_tool_pause_state(boolean paused) +{ + //TODO: pause/unpause tool. +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hoe...@us...> - 2009-01-31 17:42:48
|
Revision: 2466 http://reprap.svn.sourceforge.net/reprap/?rev=2466&view=rev Author: hoekstar Date: 2009-01-31 17:42:46 +0000 (Sat, 31 Jan 2009) Log Message: ----------- okay, the slave firmware compiles. Modified Paths: -------------- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/ArduinoSlaveExtruder.pde trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Packet.h trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/extruder.pde trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/timer1_interrupt_routines.pde Added Paths: ----------- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/PacketProcessor.pde Removed Paths: ------------- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/HostPacketProcessor.pde Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/ArduinoSlaveExtruder.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/ArduinoSlaveExtruder.pde 2009-01-31 17:24:42 UTC (rev 2465) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/ArduinoSlaveExtruder.pde 2009-01-31 17:42:46 UTC (rev 2466) @@ -32,6 +32,39 @@ //are we paused? boolean is_tool_paused = false; +#include <Servo.h> + +int current_temperature; +int target_temperature; + +// motor control states. +typedef enum { + MC_PWM = 0, + MC_ENCODER +} +MotorControlStyle; + +typedef enum { + MC_FORWARD = 0, + MC_REVERSE = 1 +} +MotorControlDirection; + +MotorControlStyle motor1_control = MC_PWM; +MotorControlDirection motor1_dir = MC_FORWARD; +byte motor1_pwm = 0; +long motor1_target_rpm = 0; +long motor1_current_rpm = 0; + +MotorControlStyle motor2_control = MC_PWM; +MotorControlDirection motor2_dir = MC_FORWARD; +byte motor2_pwm = 0; +long motor2_target_rpm = 0; +long motor2_current_rpm = 0; + +Servo servo1; +Servo servo2; + //set up our firmware for actual usage. void setup() { Deleted: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/HostPacketProcessor.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/HostPacketProcessor.pde 2009-01-31 17:24:42 UTC (rev 2465) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/HostPacketProcessor.pde 2009-01-31 17:42:46 UTC (rev 2466) @@ -1,199 +0,0 @@ -// These are our query commands from the host -#define SLAVE_CMD_VERSION 0 -#define SLAVE_CMD_INIT 1 -#define SLAVE_CMD_GET_TEMP 2 -#define SLAVE_CMD_SET_TEMP 3 -#define SLAVE_CMD_SET_MOTOR_1_PWM 4 -#define SLAVE_CMD_SET_MOTOR_2_PWM 5 -#define SLAVE_CMD_SET_MOTOR_1_RPM 6 -#define SLAVE_CMD_SET_MOTOR_2_RPM 7 -#define SLAVE_CMD_SET_MOTOR_1_DIR 8 -#define SLAVE_CMD_SET_MOTOR_2_DIR 9 -#define SLAVE_CMD_TOGGLE_MOTOR_1 10 -#define SLAVE_CMD_TOGGLE_MOTOR_2 11 -#define SLAVE_CMD_TOGGLE_FAN 12 -#define SLAVE_CMD_TOGGLE_VALVE 13 -#define SLAVE_CMD_SET_SERVO_1_POS 14 -#define SLAVE_CMD_SET_SERVO_2_POS 15 -#define SLAVE_CMD_FILAMENT_STATUS 16 -#define SLAVE_CMD_GET_MOTOR_1_PWM 17 -#define SLAVE_CMD_GET_MOTOR_2_PWM 18 -#define SLAVE_CMD_GET_MOTOR_1_RPM 19 -#define SLAVE_CMD_GET_MOTOR_2_RPM 20 -#define SLAVE_CMD_SELECT_TOOL 21 -#define SLAVE_CMD_IS_TOOL_READY 22 - -//how many queued commands have we processed? -//this will be used to keep track of our current progress. -unsigned long finishedCommands = 0; - -//initialize the firmware to default state. -void init_commands() -{ - finishedCommands = 0; -} - -//handle our packets. -void process_packets() -{ - //read through our available data - while (Serial.available() > 0) - { - //grab a byte and process it. - byte d = Serial.read(); - masterPacket.process_byte(d); - - //do we have a finished packet? - if (masterPacket.isFinished()) - { - //take some action. - handle_query(); - - //okay, send our response - masterPacket.sendReply(); - - //only process one packet at a time. - break; - } - } -} - -//this is for handling query commands that need a response. -void handle_query() -{ - byte temp; - - //which one did we get? - switch (masterPacket.getData(0)) - { - case SLAVE_CMD_VERSION: - //get our host version - master_version = masterPacket.get_16(1); - - //send our version back. - masterPacket.add_16(FIRMWARE_VERSION); - break; - - case SLAVE_CMD_INIT: - //just initialize - initialize(); - break; - - case SLAVE_CMD_GET_TEMP: - masterPacket.add_16(current_temperature); - break; - - case SLAVE_CMD_SET_TEMP: - target_temperature = masterPacket.get_16(1); - break; - - case SLAVE_CMD_SET_MOTOR_1_PWM: - motor1_control = MC_PWM; - motor1_pwm = masterPacket.get_8(1); - break; - - case SLAVE_CMD_SET_MOTOR_2_PWM: - motor2_control = MC_PWM; - motor2_pwm = masterPacket.get_8(1); - break; - - case SLAVE_CMD_SET_MOTOR_1_RPM: - motor1_control = MC_ENCODER; - motor1_target_rpm = masterPacket.get_32(1); - break; - - case SLAVE_CMD_SET_MOTOR_2_RPM: - motor2_control = MC_ENCODER; - motor2_target_rpm = masterPacket.get_32(1); - break; - - case SLAVE_CMD_SET_MOTOR_1_DIR: - motor1_dir = masterPacket.get_8(1); - break; - - case SLAVE_CMD_SET_MOTOR_2_DIR: - motor2_dir = masterPacket.get_8(1); - break; - - case SLAVE_CMD_TOGGLE_MOTOR_1: - temp = masterPacket.get_8(1); - if (temp & 1<<2) - motor_1_dir = MC_FORWARD; - else - motor_1_dir = MC_REVERSE; - - if (temp & 1) - enable_motor_1(); - else - disable_motor_1(); - break; - - case SLAVE_CMD_TOGGLE_MOTOR_2: - temp = masterPacket.get_8(1); - if (temp & 1<<2) - motor_2_dir = MC_FORWARD; - else - motor_2_dir = MC_REVERSE; - - if (temp & 1) - enable_motor_2(); - else - disable_motor_2(); - break; - - case SLAVE_CMD_TOGGLE_FAN: - temp = masterPacket.get_8(1); - if (temp & 1) - enable_fan(); - else - disable_fan(); - break; - - case SLAVE_CMD_TOGGLE_VALVE: - temp = masterPacket.get_8(1); - if (temp & 1) - open_valve(); - else - close_valve(); - break; - - case SLAVE_CMD_SET_SERVO_1_POS: - servo1.attach(); - servo1.write(masterPacket.get_8(1)); - break; - - case SLAVE_CMD_SET_SERVO_2_POS: - servo2.attach(); - servo2.write(masterPacket.get_8(1)); - break; - - case SLAVE_CMD_FILAMENT_STATUS: - //TODO: figure out how to detect this. - masterPacket.add_8(255); - break; - - case SLAVE_CMD_GET_MOTOR_1_PWM: - masterPacket.add_8(motor1_pwm); - break; - - case SLAVE_CMD_GET_MOTOR_2_PWM: - masterPacket.add_8(motor2_pwm); - break; - - case SLAVE_CMD_GET_MOTOR_1_RPM: - masterPacket.add_32(motor1_current_rpm); - break; - - case SLAVE_CMD_GET_MOTOR_2_RPM: - masterPacket.add_32(motor1_current_rpm); - break; - - case SLAVE_CMD_SELECT_TOOL: - //do we do anything? - break; - - case SLAVE_CMD_IS_TOOL_READY: - masterPacket.add_8(is_tool_ready()); - break; - } -} Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Packet.h =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Packet.h 2009-01-31 17:24:42 UTC (rev 2465) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Packet.h 2009-01-31 17:42:46 UTC (rev 2466) @@ -187,8 +187,8 @@ { if (uart == 0) Serial.print(d, BYTE); - else - Serial1.print(d, BYTE); +// else +// Serial1.print(d, BYTE); } //add a four byte chunk of data to our reply Copied: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/PacketProcessor.pde (from rev 2465, trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/HostPacketProcessor.pde) =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/PacketProcessor.pde (rev 0) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/PacketProcessor.pde 2009-01-31 17:42:46 UTC (rev 2466) @@ -0,0 +1,207 @@ +// These are our query commands from the host +#define SLAVE_CMD_VERSION 0 +#define SLAVE_CMD_INIT 1 +#define SLAVE_CMD_GET_TEMP 2 +#define SLAVE_CMD_SET_TEMP 3 +#define SLAVE_CMD_SET_MOTOR_1_PWM 4 +#define SLAVE_CMD_SET_MOTOR_2_PWM 5 +#define SLAVE_CMD_SET_MOTOR_1_RPM 6 +#define SLAVE_CMD_SET_MOTOR_2_RPM 7 +#define SLAVE_CMD_SET_MOTOR_1_DIR 8 +#define SLAVE_CMD_SET_MOTOR_2_DIR 9 +#define SLAVE_CMD_TOGGLE_MOTOR_1 10 +#define SLAVE_CMD_TOGGLE_MOTOR_2 11 +#define SLAVE_CMD_TOGGLE_FAN 12 +#define SLAVE_CMD_TOGGLE_VALVE 13 +#define SLAVE_CMD_SET_SERVO_1_POS 14 +#define SLAVE_CMD_SET_SERVO_2_POS 15 +#define SLAVE_CMD_FILAMENT_STATUS 16 +#define SLAVE_CMD_GET_MOTOR_1_PWM 17 +#define SLAVE_CMD_GET_MOTOR_2_PWM 18 +#define SLAVE_CMD_GET_MOTOR_1_RPM 19 +#define SLAVE_CMD_GET_MOTOR_2_RPM 20 +#define SLAVE_CMD_SELECT_TOOL 21 +#define SLAVE_CMD_IS_TOOL_READY 22 + +//how many queued commands have we processed? +//this will be used to keep track of our current progress. +unsigned long finishedCommands = 0; + +//initialize the firmware to default state. +void init_commands() +{ + finishedCommands = 0; +} + +//handle our packets. +void process_packets() +{ + //read through our available data + while (Serial.available() > 0) + { + //grab a byte and process it. + byte d = Serial.read(); + masterPacket.process_byte(d); + + //do we have a finished packet? + if (masterPacket.isFinished()) + { + //take some action. + handle_query(); + + //okay, send our response + masterPacket.sendReply(); + + //only process one packet at a time. + break; + } + } +} + +//this is for handling query commands that need a response. +void handle_query() +{ + byte temp; + + //which one did we get? + switch (masterPacket.getData(0)) + { + case SLAVE_CMD_VERSION: + //get our host version + master_version = masterPacket.get_16(1); + + //send our version back. + masterPacket.add_16(FIRMWARE_VERSION); + break; + + case SLAVE_CMD_INIT: + //just initialize + initialize(); + break; + + case SLAVE_CMD_GET_TEMP: + masterPacket.add_16(current_temperature); + break; + + case SLAVE_CMD_SET_TEMP: + target_temperature = masterPacket.get_16(1); + break; + + case SLAVE_CMD_SET_MOTOR_1_PWM: + motor1_control = MC_PWM; + motor1_pwm = masterPacket.get_8(1); + break; + + case SLAVE_CMD_SET_MOTOR_2_PWM: + motor2_control = MC_PWM; + motor2_pwm = masterPacket.get_8(1); + break; + + case SLAVE_CMD_SET_MOTOR_1_RPM: + motor1_control = MC_ENCODER; + motor1_target_rpm = masterPacket.get_32(1); + break; + + case SLAVE_CMD_SET_MOTOR_2_RPM: + motor2_control = MC_ENCODER; + motor2_target_rpm = masterPacket.get_32(1); + break; + + case SLAVE_CMD_SET_MOTOR_1_DIR: + temp = masterPacket.get_8(1); + if (temp & 1) + motor1_dir = MC_FORWARD; + else + motor1_dir = MC_REVERSE; + break; + + case SLAVE_CMD_SET_MOTOR_2_DIR: + temp = masterPacket.get_8(1); + if (temp & 1) + motor2_dir = MC_FORWARD; + else + motor2_dir = MC_REVERSE; + break; + + case SLAVE_CMD_TOGGLE_MOTOR_1: + temp = masterPacket.get_8(1); + if (temp & 1<<2) + motor1_dir = MC_FORWARD; + else + motor1_dir = MC_REVERSE; + + if (temp & 1) + enable_motor_1(); + else + disable_motor_1(); + break; + + case SLAVE_CMD_TOGGLE_MOTOR_2: + temp = masterPacket.get_8(1); + if (temp & 1<<2) + motor2_dir = MC_FORWARD; + else + motor2_dir = MC_REVERSE; + + if (temp & 1) + enable_motor_2(); + else + disable_motor_2(); + break; + + case SLAVE_CMD_TOGGLE_FAN: + temp = masterPacket.get_8(1); + if (temp & 1) + enable_fan(); + else + disable_fan(); + break; + + case SLAVE_CMD_TOGGLE_VALVE: + temp = masterPacket.get_8(1); + if (temp & 1) + open_valve(); + else + close_valve(); + break; + + case SLAVE_CMD_SET_SERVO_1_POS: + servo1.attach(9); + servo1.write(masterPacket.get_8(1)); + break; + + case SLAVE_CMD_SET_SERVO_2_POS: + servo2.attach(10); + servo2.write(masterPacket.get_8(1)); + break; + + case SLAVE_CMD_FILAMENT_STATUS: + //TODO: figure out how to detect this. + masterPacket.add_8(255); + break; + + case SLAVE_CMD_GET_MOTOR_1_PWM: + masterPacket.add_8(motor1_pwm); + break; + + case SLAVE_CMD_GET_MOTOR_2_PWM: + masterPacket.add_8(motor2_pwm); + break; + + case SLAVE_CMD_GET_MOTOR_1_RPM: + masterPacket.add_32(motor1_current_rpm); + break; + + case SLAVE_CMD_GET_MOTOR_2_RPM: + masterPacket.add_32(motor1_current_rpm); + break; + + case SLAVE_CMD_SELECT_TOOL: + //do we do anything? + break; + + case SLAVE_CMD_IS_TOOL_READY: + masterPacket.add_8(is_tool_ready()); + break; + } +} Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/extruder.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/extruder.pde 2009-01-31 17:24:42 UTC (rev 2465) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/extruder.pde 2009-01-31 17:42:46 UTC (rev 2466) @@ -1,36 +1,5 @@ -#include <Servo.h> -int current_temperature; -int target_temperature; -// motor control states. -typedef enum { - MC_PWM = 0, - MC_ENCODER -} -MotorControlStyle; - -typedef enum { - MC_FORWARD = 0, - MC_REVERSE = 1 -} -MotorControlDirection; - -MotorControlStyle motor1_control = MC_PWM; -MotorControlDirection motor1_dir = MC_FORWARD; -byte motor1_pwm = 0; -long motor1_target_rpm = 0; -long motor1_current_rpm = 0; - -MotorControlStyle motor2_control = MC_PWM; -MotorControlDirection motor2_dir = MC_FORWARD; -byte motor2_pwm = 0; -long motor2_target_rpm = 0; -long motor2_current_rpm = 0; - -Servo servo1; -Servo servo2; - void init_extruder() { @@ -51,6 +20,15 @@ } +void enable_motor_2() +{ + +} + +void disable_motor_2() +{ + +} void enable_fan() { @@ -78,4 +56,4 @@ return 1; else return 0; -} \ No newline at end of file +} Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/timer1_interrupt_routines.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/timer1_interrupt_routines.pde 2009-01-31 17:24:42 UTC (rev 2465) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/timer1_interrupt_routines.pde 2009-01-31 17:42:46 UTC (rev 2466) @@ -3,7 +3,6 @@ //this handles the timer interrupt event SIGNAL(SIG_OUTPUT_COMPARE1A) { - dda_step(); } void enableTimer1Interrupt() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hoe...@us...> - 2009-01-31 17:24:45
|
Revision: 2465 http://reprap.svn.sourceforge.net/reprap/?rev=2465&view=rev Author: hoekstar Date: 2009-01-31 17:24:42 +0000 (Sat, 31 Jan 2009) Log Message: ----------- implemented most of the commands for the extruder. Modified Paths: -------------- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/ArduinoSlaveExtruder.pde trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/HostPacketProcessor.pde trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Packet.h trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/HostPacketProcessor.pde trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/SanguinoMaster.pde Added Paths: ----------- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/extruder.pde Removed Paths: ------------- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/CircularBuffer.h Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/ArduinoSlaveExtruder.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/ArduinoSlaveExtruder.pde 2009-01-31 01:03:36 UTC (rev 2464) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/ArduinoSlaveExtruder.pde 2009-01-31 17:24:42 UTC (rev 2465) @@ -31,7 +31,6 @@ //are we paused? boolean is_tool_paused = false; -boolean is_tool_aborted = false; //set up our firmware for actual usage. void setup() @@ -50,7 +49,7 @@ is_tool_paused = false; init_serial(); - init_tool(); + init_extruder(); } //start our hardware serial drivers @@ -63,15 +62,17 @@ void loop() { //check for and handle any packets that come in. - process_master_packets(); + process_packets(); + + //manage our extruder stuff. + manage_temperature(); } //handle the abortion of a print job void abort_print() { - //yes, we're done here. - is_tool_aborted = true; - + //TODO: shut down all things + //initalize everything to the beginning initialize(); } Deleted: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/CircularBuffer.h =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/CircularBuffer.h 2009-01-31 01:03:36 UTC (rev 2464) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/CircularBuffer.h 2009-01-31 17:24:42 UTC (rev 2465) @@ -1,83 +0,0 @@ -#ifndef _CIRCULAR_BUFFER_H_ -#define _CIRCULAR_BUFFER_H_ - -#include <stddef.h> -#include <stdint.h> - -/// -/// Implementation of an in-memory circular byte buffer. -/// Originally a template, bowlderized to make the -/// arduino build happy. Sigh. -/// -/// No safety checks are made in this -/// implementation. It will allow you to cheerfully -/// write bytes all over yourself. -/// - -class CircularBuffer { -private: - uint8_t* buffer; - size_t capacity; - size_t start; - size_t count; // elements filled -public: - CircularBuffer(size_t capacity, uint8_t* pBuf) { - this->capacity = capacity; - buffer = pBuf; - clear(); - } - - ~CircularBuffer() { - } - - /// Reset buffer. (Note: does not zero data.) - void clear() { - start = count = 0; - } - - uint8_t operator[](const size_t i) const { - const size_t idx = (i+start)%capacity; - return buffer[idx]; - } - - /// Check remaining capacity of this vector. - size_t remainingCapacity() const { - return capacity-count; - } - - /// Get the current number of elements in the buffer. - size_t size() const { - return count; - } - - /// Append a character to the end of the circular buffer. - bool append(const uint8_t datum) { - buffer[(start+count)%capacity] = datum; - count++; - } - - /// Remove and return a character from the start of the - /// circular buffer. - const uint8_t remove_8() { - const uint8_t c = buffer[start]; - start = (start+1)%capacity; - count--; - return c; - } - - const uint16_t remove_16() { - return (remove_8() << 8) & remove_8(); - } - - const uint32_t remove_32() { - return (remove_16() << 16) & remove_16(); - } -}; - -//we store all queueable commands in one big giant buffer. -// Explicitly allocate memory at compile time for buffer. -#define COMMAND_BUFFER_SIZE 2048 -uint8_t underlyingBuffer[COMMAND_BUFFER_SIZE]; -CircularBuffer commandBuffer(COMMAND_BUFFER_SIZE, underlyingBuffer); - -#endif // _CIRCULAR_BUFFER_H_ Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/HostPacketProcessor.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/HostPacketProcessor.pde 2009-01-31 01:03:36 UTC (rev 2464) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/HostPacketProcessor.pde 2009-01-31 17:24:42 UTC (rev 2465) @@ -1,27 +1,28 @@ // These are our query commands from the host -#define HOST_CMD_VERSION 0 -#define HOST_CMD_INIT 1 -#define HOST_CMD_GET_BUFFER_SIZE 2 -#define HOST_CMD_CLEAR_BUFFER 3 -#define HOST_CMD_GET_POSITION 4 -#define HOST_CMD_GET_RANGE 5 -#define HOST_CMD_SET_RANGE 6 -#define HOST_CMD_ABORT 7 -#define HOST_CMD_PAUSE 8 -#define HOST_CMD_PROBE 9 -#define HOST_CMD_TOOL_QUERY 10 +#define SLAVE_CMD_VERSION 0 +#define SLAVE_CMD_INIT 1 +#define SLAVE_CMD_GET_TEMP 2 +#define SLAVE_CMD_SET_TEMP 3 +#define SLAVE_CMD_SET_MOTOR_1_PWM 4 +#define SLAVE_CMD_SET_MOTOR_2_PWM 5 +#define SLAVE_CMD_SET_MOTOR_1_RPM 6 +#define SLAVE_CMD_SET_MOTOR_2_RPM 7 +#define SLAVE_CMD_SET_MOTOR_1_DIR 8 +#define SLAVE_CMD_SET_MOTOR_2_DIR 9 +#define SLAVE_CMD_TOGGLE_MOTOR_1 10 +#define SLAVE_CMD_TOGGLE_MOTOR_2 11 +#define SLAVE_CMD_TOGGLE_FAN 12 +#define SLAVE_CMD_TOGGLE_VALVE 13 +#define SLAVE_CMD_SET_SERVO_1_POS 14 +#define SLAVE_CMD_SET_SERVO_2_POS 15 +#define SLAVE_CMD_FILAMENT_STATUS 16 +#define SLAVE_CMD_GET_MOTOR_1_PWM 17 +#define SLAVE_CMD_GET_MOTOR_2_PWM 18 +#define SLAVE_CMD_GET_MOTOR_1_RPM 19 +#define SLAVE_CMD_GET_MOTOR_2_RPM 20 +#define SLAVE_CMD_SELECT_TOOL 21 +#define SLAVE_CMD_IS_TOOL_READY 22 -// These are our bufferable commands from the host -#define HOST_CMD_QUEUE_POINT_INC 128 -#define HOST_CMD_QUEUE_POINT_ABS 129 -#define HOST_CMD_SET_POSITION 130 -#define HOST_CMD_FIND_AXES_MINIMUM 131 -#define HOST_CMD_FIND_AXES_MAXIMUM 132 -#define HOST_CMD_DELAY 133 -#define HOST_CMD_CHANGE_TOOL 134 -#define HOST_CMD_WAIT_FOR_TOOL 135 -#define HOST_CMD_TOOL_COMMAND 136 - //how many queued commands have we processed? //this will be used to keep track of our current progress. unsigned long finishedCommands = 0; @@ -33,24 +34,23 @@ } //handle our packets. -void process_host_packets() +void process_packets() { //read through our available data while (Serial.available() > 0) { //grab a byte and process it. byte d = Serial.read(); - hostPacket.process_byte(d); + masterPacket.process_byte(d); //do we have a finished packet? - if (hostPacket.isFinished()) + if (masterPacket.isFinished()) { - //are we cool? - if (hostPacket.isQuery()) + //take some action. handle_query(); //okay, send our response - hostPacket.sendReply(); + masterPacket.sendReply(); //only process one packet at a time. break; @@ -61,202 +61,139 @@ //this is for handling query commands that need a response. void handle_query() { + byte temp; + //which one did we get? - switch (hostPacket.getData(0)) + switch (masterPacket.getData(0)) { - case HOST_CMD_VERSION: - //get our host version - host_version = hostPacket.get_16(1); - - //send our version back. - hostPacket.add_16(FIRMWARE_VERSION); - break; + case SLAVE_CMD_VERSION: + //get our host version + master_version = masterPacket.get_16(1); - case HOST_CMD_INIT: - //just initialize - initialize(); - break; - - case HOST_CMD_GET_BUFFER_SIZE: - //send our remaining buffer size. - hostPacket.add_16(commandBuffer.remainingCapacity()); - break; + //send our version back. + masterPacket.add_16(FIRMWARE_VERSION); + break; - case HOST_CMD_CLEAR_BUFFER: - //just clear it. - commandBuffer.clear(); - break; + case SLAVE_CMD_INIT: + //just initialize + initialize(); + break; - case HOST_CMD_GET_POSITION: - //send our position - hostPacket.add_32(current_steps.x); - hostPacket.add_32(current_steps.y); - hostPacket.add_32(current_steps.z); - hostPacket.add_8(get_endstop_states()); - break; + case SLAVE_CMD_GET_TEMP: + masterPacket.add_16(current_temperature); + break; - case HOST_CMD_GET_RANGE: - //send our range - hostPacket.add_32(range_steps.x); - hostPacket.add_32(range_steps.y); - hostPacket.add_32(range_steps.z); - break; + case SLAVE_CMD_SET_TEMP: + target_temperature = masterPacket.get_16(1); + break; - case HOST_CMD_SET_RANGE: - //set our range to what the host tells us - range_steps.x = hostPacket.get_32(1); - range_steps.y = hostPacket.get_32(5); - range_steps.z = hostPacket.get_32(9); - - //write it back to eeprom - write_range_to_eeprom(); - break; + case SLAVE_CMD_SET_MOTOR_1_PWM: + motor1_control = MC_PWM; + motor1_pwm = masterPacket.get_8(1); + break; - case HOST_CMD_ABORT: - //support a microcontrollers right to choice. - abort_print(); - break; + case SLAVE_CMD_SET_MOTOR_2_PWM: + motor2_control = MC_PWM; + motor2_pwm = masterPacket.get_8(1); + break; - case HOST_CMD_PAUSE: - if (is_machine_paused) - { - //unpause our machine. - is_machine_paused = false; - - //unpause our tools - set_tool_pause_state(false); - - //resume stepping. - enableTimer1Interrupt(); - enable_steppers(); - } - else - { - //pause our activity. - is_machine_paused = true; + case SLAVE_CMD_SET_MOTOR_1_RPM: + motor1_control = MC_ENCODER; + motor1_target_rpm = masterPacket.get_32(1); + break; - //pause our tools - set_tool_pause_state(true); + case SLAVE_CMD_SET_MOTOR_2_RPM: + motor2_control = MC_ENCODER; + motor2_target_rpm = masterPacket.get_32(1); + break; - //pause stepping - disableTimer1Interrupt(); - disable_steppers(); - } - break; + case SLAVE_CMD_SET_MOTOR_1_DIR: + motor1_dir = masterPacket.get_8(1); + break; - case HOST_CMD_PROBE: - //we dont support this yet. - hostPacket.unsupported(); - break; - - case HOST_CMD_TOOL_QUERY: - send_tool_query(); - break; - } -} + case SLAVE_CMD_SET_MOTOR_2_DIR: + motor2_dir = masterPacket.get_8(1); + break; -//this is for handling buffered commands with no response -void handle_commands() -{ - byte flags = 0; - - //do we have any commands? - if (commandBuffer.size()) - { - //okay, which command are we handling? - byte cmd = commandBuffer.remove_8(); - switch(cmd) - { - //add it to our poitn queue. - case HOST_CMD_QUEUE_POINT_INC: - queue_incremental_point( - commandBuffer.remove_16(), - commandBuffer.remove_16(), - commandBuffer.remove_16(), - commandBuffer.remove_8(), - commandBuffer.remove_16() - ); - break; + case SLAVE_CMD_TOGGLE_MOTOR_1: + temp = masterPacket.get_8(1); + if (temp & 1<<2) + motor_1_dir = MC_FORWARD; + else + motor_1_dir = MC_REVERSE; - //add it to our point queue. - case HOST_CMD_QUEUE_POINT_ABS: - queue_absolute_point( - commandBuffer.remove_32(), - commandBuffer.remove_32(), - commandBuffer.remove_32(), - commandBuffer.remove_8(), - commandBuffer.remove_16() - ); - break; - - //update our current point to where we're told. - case HOST_CMD_SET_POSITION: - wait_until_target_reached(); //dont want to get hasty. - - current_steps.x = commandBuffer.remove_32(); - current_steps.y = commandBuffer.remove_32(); - current_steps.z = commandBuffer.remove_32(); - break; + if (temp & 1) + enable_motor_1(); + else + disable_motor_1(); + break; - //figure out our minimums. - case HOST_CMD_FIND_AXES_MINIMUM: - wait_until_target_reached(); //dont want to get hasty. + case SLAVE_CMD_TOGGLE_MOTOR_2: + temp = masterPacket.get_8(1); + if (temp & 1<<2) + motor_2_dir = MC_FORWARD; + else + motor_2_dir = MC_REVERSE; - //no dda interrupts. - disableTimer1Interrupt(); - - //which ones are we going to? - flags = commandBuffer.remove_8(); - - //find them! - seek_minimums( - flags & 1, - flags & (1 << 1), - flags & (1 << 2), - commandBuffer.remove_32(), - commandBuffer.remove_16() - ); - - //turn on point seekign agian. - enableTimer1Interrupt(); - - break; + if (temp & 1) + enable_motor_2(); + else + disable_motor_2(); + break; - //gotta know your limits. - case HOST_CMD_FIND_AXES_MAXIMUM: - wait_until_target_reached(); //dont want to get hasty. + case SLAVE_CMD_TOGGLE_FAN: + temp = masterPacket.get_8(1); + if (temp & 1) + enable_fan(); + else + disable_fan(); + break; - //TODO: implement this. - break; + case SLAVE_CMD_TOGGLE_VALVE: + temp = masterPacket.get_8(1); + if (temp & 1) + open_valve(); + else + close_valve(); + break; - case HOST_CMD_DELAY: - wait_until_target_reached(); //dont want to get hasty. + case SLAVE_CMD_SET_SERVO_1_POS: + servo1.attach(); + servo1.write(masterPacket.get_8(1)); + break; - //take it easy. - delay(commandBuffer.remove_32()); - break; + case SLAVE_CMD_SET_SERVO_2_POS: + servo2.attach(); + servo2.write(masterPacket.get_8(1)); + break; - case HOST_CMD_CHANGE_TOOL: - wait_until_target_reached(); //dont want to get hasty. + case SLAVE_CMD_FILAMENT_STATUS: + //TODO: figure out how to detect this. + masterPacket.add_8(255); + break; - //extruder, i choose you! - select_tool(commandBuffer.remove_8()); - break; + case SLAVE_CMD_GET_MOTOR_1_PWM: + masterPacket.add_8(motor1_pwm); + break; - case HOST_CMD_WAIT_FOR_TOOL: - wait_until_target_reached(); //dont want to get hasty. + case SLAVE_CMD_GET_MOTOR_2_PWM: + masterPacket.add_8(motor2_pwm); + break; - //get your temp in gear, you lazy bum. - wait_for_tool_ready_state( - commandBuffer.remove_8(), - commandBuffer.remove_16(), - commandBuffer.remove_16() - ); - break; + case SLAVE_CMD_GET_MOTOR_1_RPM: + masterPacket.add_32(motor1_current_rpm); + break; - case HOST_CMD_TOOL_QUERY: - send_tool_command(); - break; - } + case SLAVE_CMD_GET_MOTOR_2_RPM: + masterPacket.add_32(motor1_current_rpm); + break; + + case SLAVE_CMD_SELECT_TOOL: + //do we do anything? + break; + + case SLAVE_CMD_IS_TOOL_READY: + masterPacket.add_8(is_tool_ready()); + break; } } Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Packet.h =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Packet.h 2009-01-31 01:03:36 UTC (rev 2464) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Packet.h 2009-01-31 17:24:42 UTC (rev 2465) @@ -3,7 +3,6 @@ //include our various libraries. #include <util/crc16.h> -//#include <stddef.h> #include <stdint.h> #include "HardwareSerial.h" @@ -42,7 +41,6 @@ uint8_t tx_length; uint8_t tx_data[MAX_PACKET_LENGTH]; uint8_t tx_crc; - uint8_t is_command_packet; ResponseCode response_code; uint8_t uart; @@ -64,7 +62,6 @@ rx_crc = 0; tx_length = 0; tx_crc = 0; - is_command_packet = false; } //process a byte from our packet @@ -86,49 +83,26 @@ } else if (state == PS_LEN) // process length byte { - //figure out how much data is coming. - //please note: data may go into command buffer - //instead of query packet buffer, so don't check the size target_length = b; rx_length = 0; state = PS_PAYLOAD; + + if (target_length > MAX_PACKET_LENGTH) + response_code = RC_PACKET_TOO_BIG; } else if (state == PS_PAYLOAD) // process payload byte { - //the first byte determines command vs query - if (rx_length == 0) - { - // top bit high == bufferable command packet (eg. #128-255) - if (b & 1 << 7) - is_command_packet = true; - // top bit low == reply needed query packet (eg. #0-127) - else - is_command_packet = false; - } //just keep reading bytes while we got them. if (rx_length < target_length) { //keep track of CRC. rx_crc = _crc_ibutton_update(rx_crc, b); - //we put different things in different buffers. (query vs command) - if (is_command_packet) - { - //will it fit? - if (commandBuffer.remainingCapacity() == 0) - response_code = RC_BUFFER_OVERFLOW; - else - commandBuffer.append(b); - } - else - { - //will it fit? - if (rx_length < MAX_PACKET_LENGTH) - rx_data[rx_length] = b; - else - response_code = RC_PACKET_TOO_BIG; - } + //will it fit? + if (rx_length < MAX_PACKET_LENGTH) + rx_data[rx_length] = b; + //keep track. rx_length++; } @@ -152,11 +126,6 @@ return (state == PS_LAST); } - bool isQuery() - { - return (response_code == RC_OK && !is_command_packet); - } - uint8_t getLength() { return rx_length; Added: trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/extruder.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/extruder.pde (rev 0) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/extruder.pde 2009-01-31 17:24:42 UTC (rev 2465) @@ -0,0 +1,81 @@ +#include <Servo.h> + +int current_temperature; +int target_temperature; + +// motor control states. +typedef enum { + MC_PWM = 0, + MC_ENCODER +} +MotorControlStyle; + +typedef enum { + MC_FORWARD = 0, + MC_REVERSE = 1 +} +MotorControlDirection; + +MotorControlStyle motor1_control = MC_PWM; +MotorControlDirection motor1_dir = MC_FORWARD; +byte motor1_pwm = 0; +long motor1_target_rpm = 0; +long motor1_current_rpm = 0; + +MotorControlStyle motor2_control = MC_PWM; +MotorControlDirection motor2_dir = MC_FORWARD; +byte motor2_pwm = 0; +long motor2_target_rpm = 0; +long motor2_current_rpm = 0; + +Servo servo1; +Servo servo2; + +void init_extruder() +{ + +} + +void manage_temperature() +{ + +} + +void enable_motor_1() +{ + +} + +void disable_motor_1() +{ + +} + +void enable_fan() +{ + +} + +void disable_fan() +{ + +} + +void open_valve() +{ + +} + +void close_valve() +{ + +} + +byte is_tool_ready() +{ + //are we within 5% of the temperature? + if (current_temperature > (int)(target_temperature * 0.95)) + return 1; + else + return 0; +} \ No newline at end of file Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/HostPacketProcessor.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/HostPacketProcessor.pde 2009-01-31 01:03:36 UTC (rev 2464) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/HostPacketProcessor.pde 2009-01-31 17:24:42 UTC (rev 2465) @@ -45,10 +45,21 @@ //do we have a finished packet? if (hostPacket.isFinished()) { - //are we cool? - if (hostPacket.isQuery()) - handle_query(); - + byte b = hostPacket.get_8(0); + // top bit high == bufferable command packet (eg. #128-255) + if (b & 1 << 7) + { + //okay, throw it in the buffer. + for (int i=1; i<hostPacket.getLength(); i++) + commandBuffer.append(hostPacket.get_8(i)); + } + // top bit low == reply needed query packet (eg. #0-127) + else + { + handle_query(b); + } + } + //okay, send our response hostPacket.sendReply(); @@ -59,10 +70,10 @@ } //this is for handling query commands that need a response. -void handle_query() +void handle_query(byte cmd) { //which one did we get? - switch (hostPacket.getData(0)) + switch (cmd) { case HOST_CMD_VERSION: //get our host version Modified: trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/SanguinoMaster.pde =================================================================== --- trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/SanguinoMaster.pde 2009-01-31 01:03:36 UTC (rev 2464) +++ trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/SanguinoMaster.pde 2009-01-31 17:24:42 UTC (rev 2465) @@ -65,7 +65,7 @@ initialize(); //this is a simple text string that identifies us. - Serial.print("S3G v"); + Serial.print("R3G Master v"); Serial.print(FIRMWARE_VERSION); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: nop h. <nop...@go...> - 2009-01-31 17:16:08
|
From: Zach 'H. S. <ho...@gm...> - 2009-01-31 16:22:01
|
test |