i recently was working on a forklift project but have kinda gotten stuck at this part. i am trying to use a similar code from a different machines that was made a quarter or two ago. basically we have 3 stepper motors and they are supposed to move the forklift to a specific location which will be defined once we figure out how many steps we are going to use to make it to said spot. we want to drive the forklift to a rack which has 9 locations colums A, B, and C and then rows 1 2 and 3 (like an excel spreadsheet layout) so there will be A1, A2, A3, etc…
i need to know which of these code parts i dont need so i can make the program smaller but do what it needs to.
im using this code because it already has the stpper motors defined and the arduino pins layed out
basic summary
tell the forklift to go to said spot (example B2)
forklift goes to b2 and load / unloads the material in box
forklift goes backwards with said item loaded or unloaded and then pauses where it started at
i know it is a little confusing im sorry, but if there are any questions ill get back asap, thanks for the help
im going to have to post the code in two parts sorry 1/2
//arduino g-code interpreter
#include <HardwareSerial.h>
//our command string
#define COMMAND_SIZE 128
#include "WProgram.h"
void setup();
void loop();
void init_process_string();
void process_string(char instruction[], int size);
double search_string(char key, char instruction[], int string_size);
bool has_command(char key, char instruction[], int string_size);
void init_steppers();
void dda_move(long micro_delay);
bool can_step(byte min_pin, byte max_pin, long current, long target, byte direction);
void do_step(byte pinA, byte pinB, byte dir);
bool read_switch(byte pin);
long to_steps(float steps_per_unit, float units);
void set_target(float x, float y, float z);
void set_position(float x, float y, float z);
void calculate_deltas();
long calculate_feedrate_delay(float feedrate);
long getMaxSpeed();
void disable_steppers();
char palabra[COMMAND_SIZE];
byte serial_count;
int no_data = 0;
void setup ( )
{
//startup
Serial.begin(19200);
Serial.println ("starting");
//initilization
init_process_string ( );
init_steppers ( );
}
void loop ( )
{
char c;
//enabling stepper motors
//if data
if (Serial.available ( ) > 0 )
{
c = Serial.read ( );
no_data = 0;
//newlines are ends of command
if (c != '\n' )
{
palabra [serial_count] = c;
serial_count++;
}
}
//no data
else
{
no_data++;
delayMicroseconds (100);
}
//if a pause or a command, do it
if (serial_count && (c == '\n' | | no_data > 100 ) )
{
//process command
process_string (palabra, serial_count);
//clear command
init_process_string ( ) ;
}
//if no data, turn off stepper motors
if (no_data > 1000)
disable_steppers ( );
}
//define parameters of machine
#define X_STEPS_PER_INCH 4800
#define X_STEPS_PER_MM 188.97
#define X_MOTOR_STEPS 200
#define Y_STEPS_PER_INCH 4800
#define Y_STEPS_PER_MM 188.97
#define Y_MOTOR_STEPS 200
#define Z_STEPS_PER_INCH 4800
#define Z_STEPS_PER_MM 188.97
#define Z_MOTOR_STEPS 200
//max feedrates
#define FAST_XY_FEEDRATE 100
#define FAST_Z_FEEDRATE 100
//units in curve section
#define CURVE_SECTION_INCHES 0.019685
#define CURVE_SECTION_MM 0.5
#define SENSORS_INVERTING 0
//define i/o pins
#define X_STEP_PIN 8
#define X_DIR_PIN 9
#define X_MIN_PIN 4
#define X_MAX_PIN 2
#define X_ENABLE_PIN 15
#define Y_STEP_PIN 10
#define Y_DIR_PIN 11
#define Y_MIN_PIN 3
#define Y_MAX_PIN 5
#define Y_ENABLE_PIN 15
#define Z_STEP_PIN 12
#define Z_DIR_PIN 13
#define Z_MIN_PIN 7
#define Z_MAX_PIN 6
#define Z_ENABLE_PIN 15
// point structure
struct Longpoint {
long x;
long y;
long z;
};
struct Floatpoint {
float x:
float y;
float z;
};
FloatPoint current_units;
FloatPoint target_units;
Floatpoint delta_units;
FloatPoint current_steps;
FloatPoint target_steps;
FloatPoint delta_steps;
boolean abs_mode = false;
//default to inches for units
float x_units = X_STEPS_PER_INCHES;
float y_units = Y_STEPS_PER_INCHES;
float z_units = Z_STEPS_PER_INCHES;
float curve_section = CURVE_SECTION_INCHES;
//direction variables
byte x_direction = 1;
byte y_direction = 1;
byte z_direction = 1;
//init the string processing
void init_process_string ( )
{
for (byte i=0; i<COMMAND_SIZE; i++)
palabra[i] = 0;
serial_count = 0;
}
//feedrate variable
float feedrate = 0.0;
long feedrate_micros = 0;
//Read the string and execute instructions
void process_string(char instruction[], int size)
{
//the character / means delete block... used for comments and stuff.
if (instruction[0] == '/')
{
Serial.println("ok");
return;
}
//init baby!
FloatPoint fp;
fp.x = 0.0;
fp.y = 0.0;
fp.z = 0.0;
byte code = 0;;
//did we get a gcode?
if (
has_command('G', instruction, size) ||
has_command('X', instruction, size) ||
has_command('Y', instruction, size) ||
has_command('Z', instruction, size)
)
{
//which one?
code = (int)search_string('G', instruction, size);
// Get co-ordinates if required by the code type given
switch (code)
{
case 0:
case 1:
case 2:
case 3:
if(abs_mode)
{
//we do it like this to save time. makes curves better.
//eg. if only x and y are specified, we dont have to waste time looking up z.
if (has_command('X', instruction, size))
fp.x = search_string('X', instruction, size);
else
fp.x = current_units.x;
if (has_command('Y', instruction, size))
fp.y = search_string('Y', instruction, size);
else
fp.y = current_units.y;
if (has_command('Z', instruction, size))
fp.z = search_string('Z', instruction, size);
else
fp.z = current_units.z;
}
else
{
fp.x = search_string('X', instruction, size) + current_units.x;
fp.y = search_string('Y', instruction, size) + current_units.y;
fp.z = search_string('Z', instruction, size) + current_units.z;
}
break;
}