Ok, here is how far I’ve gotten.
First, I wanted to verify (with config file I’m using and firmware I’m using), whether the pin assignments could be changed manually in config file. So, I did the following:
alpha_step_pin 2.3 # Pin for alpha stepper step signal
alpha_dir_pin 0.22 # Pin for alpha stepper direction
alpha_en_pin 0.21 # Pin for alpha enable pin
alpha_current 1.5 # X stepper motor current
alpha_max_rate 30000.0 # mm/min
beta_step_pin 2.1 # Pin for beta stepper step signal
beta_dir_pin 0.11 # Pin for beta stepper direction
beta_en_pin 0.10 # Pin for beta enable
beta_current 1.5 # Y stepper motor current
beta_max_rate 30000.0 # mm/min
gamma_step_pin 2.2 # Pin for gamma stepper step signal
gamma_dir_pin 0.20 # Pin for gamma stepper direction
gamma_en_pin 0.19 # Pin for gamma enable
gamma_current 1.5 # Z stepper motor current
gamma_max_rate 30000.0 # mm/min
Note that above there is no delta section, and I merely assigned the alpha section the M4 pin numbers.
After rebooting the Smoothieboard, I streamed a regular XYZ job to it, and got the desired results: the X moves were assigned to the M4 stepper, the Y and Z remained as normal.
That exercise verified that merely assigning different numbers DOES work, and WITH my CURRENT config file (NO delta section) and current firmware.
I then set the values back to normal:
alpha_step_pin 2.0 # Pin for alpha stepper step signal
alpha_dir_pin 0.5 # Pin for alpha stepper direction
alpha_en_pin 0.4 # Pin for alpha enable pin
alpha_current 1.5 # X stepper motor current
alpha_max_rate 30000.0 # mm/min
beta_step_pin 2.1 # Pin for beta stepper step signal
beta_dir_pin 0.11 # Pin for beta stepper direction
beta_en_pin 0.10 # Pin for beta enable
beta_current 1.5 # Y stepper motor current
beta_max_rate 30000.0 # mm/min
gamma_step_pin 2.2 # Pin for gamma stepper step signal
gamma_dir_pin 0.20 # Pin for gamma stepper direction
gamma_en_pin 0.19 # Pin for gamma enable
gamma_current 1.5 # Z stepper motor current
gamma_max_rate 30000.0 # mm/min
…basically making sure that the alpha section was assigned to M1 pins in config file.
Then I started working on the firmware to create a programmatic way to use g-codes to remap the pin assignments.
For the g-code, I settled on the arbitrary value of 800 because I didn’t see where there was any 800 g-code. I decided to use a format like:
M800 X1 Y2
meaning that the X axis would be mapped to the M1 motor, and the Y axis would be mapped to the M2 motor. To remap, the idea is to do something like as follows:
M800 X4 Y2
This would map the X axis to the M4 motor, and leave the Y axis on the M4 motor, etc.
Working from the bottom up, the first thing I did was add a new function to the StepperMotor Class:
void StepperMotor::RemapPins(std::string step, std::string dir, std::string en)
{
step_pin.from_string(step);
dir_pin.from_string(dir);
en_pin.from_string(en);
}
The Pin class already provided the Pin::from_string() function, which is already used by the Robot class to create and assign pins.
Next, I added the following block to the Robot::on_gcode_received() function:
case 800: // this is for remapping pins on stepper motors
if (gcode->has_letter('X'))
{
switch ((char)gcode->get_value('X'))
{
case 1:
this->alpha_stepper_motor->RemapPins("2.0", "0.5", "0.4");
break;
case 2:
this->alpha_stepper_motor->RemapPins("2.1", "0.11", "0.10");
break;
case 3:
this->alpha_stepper_motor->RemapPins("2.2", "0.20", "0.19");
break;
case 4:
this->alpha_stepper_motor->RemapPins("2.3", "0.22", "0.21");
break;
}
}
if (gcode->has_letter('Y'))
{
switch ((char)gcode->get_value('Y'))
{
case 1:
this->beta_stepper_motor->RemapPins("2.0", "0.5", "0.4");
break;
case 2:
this->beta_stepper_motor->RemapPins("2.1", "0.11", "0.10");
break;
case 3:
this->beta_stepper_motor->RemapPins("2.2", "0.20", "0.19");
break;
case 4:
this->beta_stepper_motor->RemapPins("2.3", "0.22", "0.21");
break;
}
}
break;
I then successfully compiled the modified firmware and loaded it onto the Smoothieboard and rebooted the Smoothieboard. Then came the big moment.
First, without using the new gcode, I streamed a regular XYZ job to the controller. Everything worked fine, the modifications did not break current capability, etc.
Then, before running the job again, I had my software send the following gcode to the Smoothieboard:
M800 X2 Y1
This was to see whether the new code would work, and should merely swap (remap) the X and Y axis with each other. I pressed the “run” button to begin the stream…
It worked!!
The job ran completely, with the X and Y axis swapped, i.e., the X axis was running the M2 motor and the Y axis was running the M1 motor.
I then sent the following gocde to the controller:
M800 X1 Y2
this was to see if the code would correctly swap the pins back to their usual assignments. I hit the "run: button, and it worked! The job completely ran, with the X moves running the M1 motor and the Y moves running the M2 motor.
So now I thought I was sitting pretty good. I had proven to myself that the new code would remap the axis to the desired motors, without any hiccups or errors.
Then came the test for the M4 motor. So, I sent out the following gcode:
M800 X4 Y2
The idea here is to have the Y axis remain as usual running the M2 motor, but have the X axis run the M4 motor rather than the M1. I hit the “run” button…
And it didn’t work. The complete job streamed, with only the Y axis moving the M2 motor, but the X axis was NOT moving the M4 motor: it just sat there as if it wasn’t receiving any commands.
So, the sum of it is this:
- with my current config file and modified firmware, which has NO delta section, I can manually remap the config file to send either the X or Y axis to (alpha or beta) to the M4 motor.
- with my modified firmware, I can send new gcode to send X axis to either M1 or M2 motor
- with my modified firmware, I can send new gcode to send Y axis to either M1 or M2 motor
- but I CANNOT use the new code to map either axis to the M4 motor
I find that strange. Why would the new functionality allow me to remap the M1 and M2 motors, but not the M4?