Skip to content

Commit

Permalink
Make Dual Axis settable
Browse files Browse the repository at this point in the history
  • Loading branch information
beniroquai committed Jun 20, 2024
1 parent 106a717 commit b1fbf64
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions main/JsonKeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ __attribute__ ((unused)) static const PROGMEM char * key_home_timestarted = "tim
__attribute__ ((unused)) static const PROGMEM char * key_home_isactive = "isactive";
__attribute__ ((unused)) static const PROGMEM char * key_home_endposrelease = "endposrelease";
__attribute__ ((unused)) static const PROGMEM char * key_home_endstoppolarity = "endstoppolarity";
__attribute__ ((unused)) static const PROGMEM char * key_home_isDualAxis = "dualAxis";


__attribute__ ((unused)) static const PROGMEM char * key_encoder = "encoder";
Expand Down
11 changes: 6 additions & 5 deletions main/src/home/HomeMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int HomeMotor::act(cJSON *j)
motor->data[s]->speed = hdata[s]->homeDirection * abs(hdata[s]->homeSpeed);
motor->data[s]->maxspeed = hdata[s]->homeDirection * abs(hdata[s]->homeMaxspeed);
motor->startStepper(s);
if (s == Stepper::Z and pinConfig.isDualAxisZ)
if (s == Stepper::Z and (motor->isDualAxisZ == true))
{
// we may have a dual axis so we would need to start A too
log_i("Starting A too");
Expand Down Expand Up @@ -150,7 +150,7 @@ void HomeMotor::checkAndProcessHome(Stepper s, int digitalin_val, FocusMotor *mo
// homeInEndposReleaseMode = 2 means we are done
// reverse direction to release endstops
motor->stopStepper(s);
if (s == Stepper::Z and pinConfig.isDualAxisZ)
if (s == Stepper::Z and (motor->isDualAxisZ == true))
{
// we may have a dual axis so we would need to start A too
motor->stopStepper(Stepper::A);
Expand All @@ -168,7 +168,7 @@ void HomeMotor::checkAndProcessHome(Stepper s, int digitalin_val, FocusMotor *mo
log_i("Home Motor %i in endpos release mode %i", s, hdata[s]->homeInEndposReleaseMode);
motor->startStepper(s);

if (s == Stepper::Z and pinConfig.isDualAxisZ)
if (s == Stepper::Z and (motor->isDualAxisZ == true))
{
// we may have a dual axis so we would need to start A too
motor->data[Stepper::A]->speed = -motor->data[Stepper::A]->speed ;
Expand All @@ -184,7 +184,7 @@ void HomeMotor::checkAndProcessHome(Stepper s, int digitalin_val, FocusMotor *mo
log_i("Home Motor %i in endpos release mode %i", s, hdata[s]->homeInEndposReleaseMode);
motor->stopStepper(s);
motor->setPosition(s, 0);
if (s == Stepper::Z and pinConfig.isDualAxisZ)
if (s == Stepper::Z and (motor->isDualAxisZ == true))
{
// we may have a dual axis so we would need to start A too
motor->stopStepper(Stepper::A);
Expand All @@ -193,7 +193,7 @@ void HomeMotor::checkAndProcessHome(Stepper s, int digitalin_val, FocusMotor *mo
motor->data[s]->isforever = false;
log_i("Home Motor X done");
sendHomeDone(s);
if (s == Stepper::A and pinConfig.isDualAxisZ)
if (s == Stepper::A and (motor->isDualAxisZ == true))
{
// we may have a dual axis so we would need to start A too
hdata[Stepper::A]->homeIsActive = false;
Expand Down Expand Up @@ -238,4 +238,5 @@ void HomeMotor::setup()
{
hdata[i] = new HomeData();
}

}
22 changes: 22 additions & 0 deletions main/src/motor/FocusMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,20 @@ int FocusMotor::act(cJSON *doc)
}
}

// set dual axis if necessary
cJSON *dualaxisZ = cJSON_GetObjectItemCaseSensitive(doc, key_home_isDualAxis);
if (dualaxisZ != NULL)
{
// {"task": "/motor_act", "isDualAxisZ": 1}
// store this in the preferences
Preferences preferences;
isDualAxisZ = dualaxisZ->valueint;
const char *prefNamespace = "UC2";
preferences.begin(prefNamespace, false);
preferences.putBool("dualAxZ", isDualAxisZ);
log_i("isDualAxisZ is set to: %i", isDualAxisZ);
preferences.end();
}
// set position
cJSON *setpos = cJSON_GetObjectItem(doc, key_setposition);
// {"task": "/motor_act", "setpos": {"steppers": [{"stepperid": 0, "posval": 100}, {"stepperid": 1, "posval": 0}, {"stepperid": 2, "posval": 0}, {"stepperid": 3, "posval": 0}]}}
Expand Down Expand Up @@ -550,6 +564,14 @@ void FocusMotor::setup()
}
stageScanningData = new StageScanningData();

// Read dual axis from preferences if available
Preferences preferences;
const char *prefNamespace = "UC2";
preferences.begin(prefNamespace, false);
isDualAxisZ = preferences.getBool("dualAxZ", pinConfig.isDualAxisZ);
preferences.end();

// setup motor pins
log_i("Setting Up Motor A,X,Y,Z");
preferences.begin("motor-positions", false);
if (pinConfig.MOTOR_A_DIR > 0)
Expand Down
2 changes: 2 additions & 0 deletions main/src/motor/FocusMotor.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class FocusMotor : public Module
void move(Stepper s, int steps, bool blocking);
bool isRunning(int i);
long getCurrentPosition(Stepper s);
bool isDualAxisZ = false;

TaskHandle_t TaskHandle_stagescan_t;

Expand All @@ -49,6 +50,7 @@ class FocusMotor : public Module
TCA9535_Register outRegister;
TCA9535_Register inRegister;


int logcount;
bool power_enable = false;

Expand Down

0 comments on commit b1fbf64

Please sign in to comment.