diff options
author | hoekstar <hoekstar@cb376a5e-1013-0410-a455-b6b1f9ac8223> | 2009-04-06 02:55:49 +0000 |
---|---|---|
committer | hoekstar <hoekstar@cb376a5e-1013-0410-a455-b6b1f9ac8223> | 2009-04-06 02:55:49 +0000 |
commit | 5351755726b9990b96b92e6bfb1a7e16b3342f3a (patch) | |
tree | fa867bf34da3a685a0bc94cf3d2eb5a01de9cf44 | |
parent | 868173f869d46b216cfd31cda982d6bdc61b4b11 (diff) | |
download | reprap-backup-5351755726b9990b96b92e6bfb1a7e16b3342f3a.tar.gz reprap-backup-5351755726b9990b96b92e6bfb1a7e16b3342f3a.zip |
fixed a bunch of stuff, buffering problems, and fixed point queue empty problem.
git-svn-id: https://reprap.svn.sourceforge.net/svnroot/reprap@2769 cb376a5e-1013-0410-a455-b6b1f9ac8223
5 files changed, 12 insertions, 113 deletions
diff --git a/trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Configuration.h b/trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Configuration.h index 81a441e2..7873bf60 100644 --- a/trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Configuration.h +++ b/trunk/reprap/firmware/Sanguino/Sanguino3G/ArduinoSlaveExtruder/Configuration.h @@ -26,8 +26,8 @@ //do you want to reverse the motor? #define DELAY_FOR_STOP 5 -#define MOTOR_REVERSE_DURATION 400 -#define MOTOR_FORWARD_DURATION 325 +#define MOTOR_REVERSE_DURATION 300 +#define MOTOR_FORWARD_DURATION 300 /**************************************************************************************** * Here's where you define the speed PID behavior for an encoder diff --git a/trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/CircularBuffer2.h b/trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/CircularBuffer2.h deleted file mode 100644 index ddd1b4b6..00000000 --- a/trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/CircularBuffer2.h +++ /dev/null @@ -1,109 +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. -/// -/// Hacked to make it safer for multi-access by Hoeken. -/// - -class CircularBuffer { -private: - uint8_t* buffer; - uint16_t capacity; - uint16_t head; - uint16_t tail; - uint16_t size; -public: - CircularBuffer(uint16_t capacity, uint8_t* pBuf) { - this->capacity = capacity; - buffer = pBuf; - clear(); - } - - ~CircularBuffer() { - } - - /// Reset buffer. (Note: does not zero data.) - void clear() { - head = tail = 0; - size = 0; - } - - uint8_t operator[](uint16_t i) { - const uint16_t idx = (i + head) % capacity; - return buffer[idx]; - } - - /// Check remaining capacity of this vector. - uint16_t remainingCapacity() { - return capacity - size; - } - - /// Get the current number of elements in the buffer. - uint16_t size() { - return size; - } - - /// Append a character to the end of the circular buffer. - void append(const uint8_t datum) { - - uint16_t i = (head + 1) % capacity; - - // if we should be storing the received character into the location - // just before the tail (meaning that the head would advance to the - // current location of the tail), we're about to overflow the buffer - // and so we don't write the character or advance the head. - if (size + 1 <= capacity) - { - buffer[head] = datum; - head = i; - size++; - } - } - - void append_16(const uint16_t datum) { - append(datum & 0xff); - append(datum >> 8); - } - - void append_32(const uint32_t datum) { - append_16(datum & 0xffff); - append_16(datum >> 16); - } - - /// Remove and return a character from the start of the - /// circular buffer. - const uint8_t remove_8() { - if (size == 0) - return 0; - else - { - uint8_t c = buffer[tail]; - tail = (tail + 1) % capacity; - size--; - return c; - } - } - - const uint16_t remove_16() { - //order is important here! - return remove_8() | ((int16_t)remove_8() << 8); - } - - const uint32_t remove_32() { - //order is important here! - return remove_16() | ((int32_t)remove_16() << 16); - } -}; - -#endif // _CIRCULAR_BUFFER_H_ diff --git a/trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Steppers.pde b/trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Steppers.pde index 5e38b2d0..bd08a73e 100755 --- a/trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Steppers.pde +++ b/trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Steppers.pde @@ -266,6 +266,8 @@ inline void grab_next_point() setTimer1Micros(pointBuffer.remove_32()); enableTimer1Interrupt(); } + else + is_point_queue_empty = true; //only real place to check. } //do a single step on our DDA line! @@ -420,6 +422,9 @@ void read_range_from_eeprom() //queue a point for us to move to void queue_absolute_point(long x, long y, long z, unsigned long micros) { + //point queue is not empty now! + is_point_queue_empty = false; + //wait until we have free space while (pointBuffer.remainingCapacity() < POINT_SIZE) { @@ -448,7 +453,7 @@ void queue_absolute_point(long x, long y, long z, unsigned long micros) inline boolean is_point_buffer_empty() { //okay, we got points in the buffer. - if (pointBuffer.size() > 0) + if (!is_point_queue_empty) return false; //still working on a point. @@ -469,6 +474,6 @@ inline boolean at_target() inline void wait_until_target_reached() { - while(!is_point_buffer_empty() && !at_target()) + while(!is_point_buffer_empty()) delay(1); } diff --git a/trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Variables.h b/trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Variables.h index 25d797fd..836a6669 100644 --- a/trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Variables.h +++ b/trunk/reprap/firmware/Sanguino/Sanguino3G/SanguinoMaster/Variables.h @@ -27,6 +27,8 @@ volatile LongPoint target_steps; volatile LongPoint delta_steps; volatile LongPoint range_steps; +volatile bool is_point_queue_empty = true; + //our point queue variables uint8_t rawPointBuffer[POINT_QUEUE_SIZE * POINT_SIZE]; CircularBuffer pointBuffer((POINT_QUEUE_SIZE * POINT_SIZE), rawPointBuffer); diff --git a/trunk/reprap/firmware/Sanguino/Sanguino3G/testers/rs485_master_receiver/rs485_master_receiver.pde b/trunk/reprap/firmware/Sanguino/Sanguino3G/testers/rs485_master_receiver/rs485_master_receiver.pde index a146d762..51754b0a 100644 --- a/trunk/reprap/firmware/Sanguino/Sanguino3G/testers/rs485_master_receiver/rs485_master_receiver.pde +++ b/trunk/reprap/firmware/Sanguino/Sanguino3G/testers/rs485_master_receiver/rs485_master_receiver.pde @@ -10,6 +10,7 @@ void setup() pinMode(DEBUG_PIN, OUTPUT); Serial.begin(38400); + Serial.println("Started"); Serial1.begin(38400); digitalWrite(TX_ENABLE_PIN, LOW); //disable tx |