Exemplo n.º 1
0
void loop() {
  uint8_t c;
  uint16_t newKeys;

  //read in characters if we got them.
  if (Serial.available() > 0)	{
    c = (uint8_t)Serial.read();
    no_data = 0;
    command_word[serial_count++] = c;
  } 
  else {
    no_data++;
    delayMicroseconds(100);
  }

  //if theres a pause or we got a real command, do it
  if (serial_count && (c == '\n' || no_data > 100)) {
    command_word[serial_count] = 0; //change \n to null terminator
    process_string(command_word); //do
    init_process_string(); //clear
  }

/*
  //keypad actions
  newKeys = keypad_scan();
  if (newKeys != oldKeys) {
    Serial.println(newKeys,HEX);
    oldKeys = newKeys;
    switch(newKeys) {
      case _BV(1):
      case _BV(2):
      case _BV(3):
      case _BV(4):
      case _BV(5):
      case _BV(6):
      case _BV(7):
      case _BV(8):
      case _BV(9):
      case _BV(10):
      case _BV(11):
      case _BV(12):
      case _BV(13):
      case _BV(14):
      case _BV(15):
      default:
        break;
    }
  }
*/

  //no data?  turn off steppers
  if (no_data > 1000)  {
    disable_steppers();
  }
}
Exemplo n.º 2
0
void init_steppers(){
  //turn them off to start.
  disable_steppers();

  // setup data
  xaxis = &xaxis_data;
  yaxis = &yaxis_data;
  zaxis = &zaxis_data;

  axis_array[0] = xaxis;
  axis_array[1] = yaxis;
  axis_array[2] = zaxis;

  bzero((uint8_t*)&xaxis_data, sizeof(struct axis_t)); 
  bzero((uint8_t*)&yaxis_data, sizeof(struct axis_t)); 
  bzero((uint8_t*)&zaxis_data, sizeof(struct axis_t)); 

  // configure pins
  xaxis->step_pin = STEP_X;
  yaxis->step_pin = STEP_Y;
  zaxis->step_pin = STEP_Z;

  xaxis->min_pin  = MIN_X;
  yaxis->min_pin  = MIN_Y;
  zaxis->min_pin  = MIN_Z;

  xaxis->max_pin  = MAX_X;
  yaxis->max_pin  = MAX_Y;
  zaxis->max_pin  = MAX_Z;

  xaxis->direct_step_pin = _STEP_X;
  yaxis->direct_step_pin = _STEP_Y;
  zaxis->direct_step_pin = _STEP_Z;

  //figure our stuff.
  calculate_deltas();
}
Exemplo n.º 3
0
void myStepper_init(void) {
  //Control Pins
  pinMode(MS1, OUTPUT);
  pinMode(MS2, OUTPUT);
  pinMode(MS3, OUTPUT);
  pinMode(RST, OUTPUT);
  pinMode(SLP, OUTPUT);
  pinMode(ENABLE, OUTPUT);
  pinMode(STEP_X, OUTPUT); 
  pinMode(STEP_Y, OUTPUT); 
  pinMode(STEP_Z, OUTPUT);
  pinMode(DIR_X, OUTPUT); 
  pinMode(DIR_Y, OUTPUT); 
  pinMode(DIR_Z, OUTPUT);
  
  //deal with limit switches
  limitConfig(MIN_X);
  limitConfig(MAX_X);
  limitConfig(MIN_Y);
  limitConfig(MAX_Y);
  limitConfig(MIN_Z);
  limitConfig(MAX_Z);

  //set pin values to stop PWM
  digitalWrite(STEP_X, LOW); 
  digitalWrite(STEP_Y, LOW); 
  digitalWrite(STEP_Z, LOW);
  digitalWrite(DIR_X, LOW); 
  digitalWrite(DIR_Y, LOW); 
  digitalWrite(DIR_Z, LOW);

  //reset and leave on but dissabled
  disable_steppers(); 
  setStep(DEFAULT_STEP);
  myStepper_reset();
}
Exemplo n.º 4
0
//this is for handling buffered commands with no response
void handle_commands()
{
  byte flags = 0;
  
  long x;
  long y;
  long z;
  unsigned long step_delay;
  byte cmd;

  if (is_playing()) {
    while (commandBuffer.remainingCapacity() > 0 && playback_has_next()) {
      commandBuffer.append(playback_next());
    }
  } else {
    digitalWrite(DEBUG_PIN,LOW);
  }


  //do we have any commands?
  if (commandBuffer.size() > 0)
  {
    CircularBuffer::Cursor cursor = commandBuffer.newCursor();
    
    uint16_t index = 0;

    cmd = cursor.read_8();

    // Do it later if it's a point queueing command and we don't have room yet.
    if (cmd == HOST_CMD_QUEUE_POINT_ABS && 
	!point_buffer_has_room(POINT_SIZE)) {
      return;
    }

    switch(cmd)
    {
      case HOST_CMD_QUEUE_POINT_ABS:
        x = (long)cursor.read_32();
        y = (long)cursor.read_32();
        z = (long)cursor.read_32();
        step_delay = (unsigned long)cursor.read_32();
          
        queue_absolute_point(x, y, z, step_delay);
      
        break;

      case HOST_CMD_SET_POSITION:
	// Belay until we're at a good location.
	if (!is_point_buffer_empty()) { return; }
	cli();
	set_position(LongPoint((long)cursor.read_32(),(long)cursor.read_32(),(long)cursor.read_32()));
	sei();
        break;

      case HOST_CMD_FIND_AXES_MINIMUM:
	// Belay until we're at a good location.
	if (!is_point_buffer_empty()) { return; }

        //which ones are we going to?
        flags = cursor.read_8();

        //find them!
        seek_minimums(
          flags & 1,
          flags & 2,
          flags & 4,
          cursor.read_32(),
          cursor.read_16());

        break;

      case HOST_CMD_FIND_AXES_MAXIMUM:
	// Belay until we're at a good location.
	if (!is_point_buffer_empty()) { return; }

        //find them!
        seek_maximums(
          flags & 1,
          flags & 2,
          flags & 4,
          cursor.read_32(),
          cursor.read_16());

        break;

      case HOST_CMD_DELAY:
	// Belay until we're at a good location.
	if (!is_point_buffer_empty()) { return; }

        //take it easy.
        delay(cursor.read_32());
        break;

      case HOST_CMD_CHANGE_TOOL:
	// Belay until we're at a good location.
	if (!is_point_buffer_empty()) { return; }

        //extruder, i choose you!
        select_tool(cursor.read_8());
        break;

      case HOST_CMD_WAIT_FOR_TOOL:
	// Belay until we're at a good location.
	if (!is_point_buffer_empty()) { return; }

        //get your temp in gear, you lazy bum.
        
        //what tool / timeout /etc?
	{
	  uint8_t currentToolIndex = cursor.read_8();
	  uint16_t toolPingDelay = (uint16_t)cursor.read_16();
	  uint16_t toolTimeout = (uint16_t)cursor.read_16();
	  
	  //check to see if its ready now
	  if (!is_tool_ready(currentToolIndex))
	    {
	      //how often to ping?
	      toolNextPing = millis() + toolPingDelay;
	      toolTimeoutEnd = millis() + (toolTimeout * 1000);
	      
	      //okay, put us in ping-tool-until-ready mode
	      commandMode = COMMAND_MODE_WAIT_FOR_TOOL;
	    }
	}
        break;

      case HOST_CMD_TOOL_COMMAND:
	// Belay until we're at a good location.
	if (!is_point_buffer_empty()) { return; }
        
        send_tool_command(cursor);
        break;
    case HOST_CMD_ENABLE_AXES:
      // Belay until we're at a good location.
      if (!is_point_buffer_empty()) { return; }
      {
	unsigned char param = cursor.read_8();
	bool x = (param & 0x01) != 0;
	bool y = (param & 0x02) != 0;
	bool z = (param & 0x04) != 0;
	if ((param & 0x80) != 0) {
	  // enable axes
	  enable_steppers(x,y,z);
	} else {
	  // disable axes
	  disable_steppers(x,y,z);
	}
      }
      break;
    default:
      digitalWrite(DEBUG_PIN,HIGH);
      hostPacket.unsupported();
    }
    cursor.commit();
  }
}