Implemented MoveStepper command.

This commit is contained in:
jupfi 2023-08-22 09:04:30 +02:00
parent 359152620a
commit b11d01bf13
5 changed files with 82 additions and 17 deletions

View file

@ -8,6 +8,7 @@
#include "commands/MeasureReflection.h"
#include "commands/VoltageSweep.h"
#include "commands/ControlSwitch.h"
#include "commands/MoveStepper.h"
#define DEBUG
@ -23,6 +24,7 @@ SetVoltages setVoltages;
MeasureReflection measureReflection;
VoltageSweep voltageSweep;
ControlSwitch controlSwitch;
MoveStepper moveStepper;
// Frequency Settings
#define FREQUENCY_STEP 100000U // 100kHz frequency steps for initial frequency sweep
@ -61,9 +63,10 @@ void setup()
commandManager.registerCommand('d', &tuneMatch);
commandManager.registerCommand('h', &homing);
commandManager.registerCommand('v', &setVoltages);
commandManager.registerCommand('m', &measureReflection);
commandManager.registerCommand('r', &measureReflection);
commandManager.registerCommand('s', &voltageSweep);
commandManager.registerCommand('c', &controlSwitch);
commandManager.registerCommand('m', &moveStepper);
pinMode(MISO_PIN, INPUT_PULLUP); // Seems to be necessary for SPI to work
@ -135,26 +138,29 @@ void setup()
adac.configure_ADCs(ADCs);
}
// Serial communication via USB.
// Commands:
// f<start frequency>f<stop frequency>f<frequency step> - Frequency Sweep
// d<target frequency in MHz>f<start frequency>f<stop frequency>f<frequency step> - Tune and Match
// h - Homing
void loop()
{
// Serial communication via USB.
// Commands:
// f<start frequency>f<stop frequency>f<frequency step> - Frequency Sweep
// d<target frequency in MHz>f<start frequency>f<stop frequency>f<frequency step> - Tune and Match
// h - Homing
// v<VM voltage in V>v<VT voltage in V> - Set Voltages
// r<frequency in MHz> - Measure Reflection
// s<start voltage in V>s<stop voltage in V>s<voltage step in V> - Voltage Sweep
// c<filter identifier> - Control Switch for the filterbank 'p' stands for preamplifier and 'a' for automatic tuning and matching.
// m<stepper identifier><steps> - Move stepper motor. 't' for tuner and 'm' for matcher. Positive steps move the stepper away from the motor and negative steps move the stepper towards the motor.
if (Serial.available())
{
String input_line = Serial.readStringUntil('\n'); // read string until newline character
char command = input_line.charAt(0); // gets first character of input
commandManager.executeCommand(command, input_line);
commandManager.printCommandResult(command);
// approximate call
// CAREFULL -> if the coil has no proper matching in the frequency range this will not work! Only use this for testing -> otherwise use the automated 'decide' call.
/*if (command == 'a')
/*
Optimize matching call
else if (command == 'm')
{
printInfo("Optimize Matching around frequency:");
@ -186,10 +192,7 @@ void loop()
{
printInfo("Calibrating ...");
getCalibrationValues();
}
else
{
printInfo("Invalid Input");
}*/
} */
}
}

View file

@ -12,7 +12,7 @@ public:
* @brief This function performs a frequency sweep
* @param input_line The input line from the serial monitor. The syntax is f<start frequency>f<stop frequency>f<frequency step>.
*/
void execute(String input_lne) override;
void execute(String input_line) override;
void printResult() override;
void printHelp() override;
private:

View file

@ -4,7 +4,7 @@
#include "Command.h"
/**
* @brief This class is used to perform a frequency sweep
* @brief This class is used to measure the reflection at a given frequency
*/
class MeasureReflection : public Command
{

View file

@ -0,0 +1,40 @@
#include "Utilities.h"
#include "MoveStepper.h"
void MoveStepper::execute(String input_line)
{
#define MATCHING_STEPPER 'm'
#define TUNING_STEPPER 't'
char stepper = input_line[1];
int steps = input_line.substring(2).toInt();
if (stepper == MATCHING_STEPPER)
{
matcher.STEPPER.move(steps);
matcher.STEPPER.runToPosition();
}
else if (stepper == TUNING_STEPPER)
{
tuner.STEPPER.move(steps);
tuner.STEPPER.runToPosition();
}
else
{
printInfo("Invalid stepper motor");
}
}
void MoveStepper::printResult()
{
// Print Info confirmation
printInfo("Fniished moving stepper");
}
void MoveStepper::printHelp()
{
Serial.println("Move stepper command");
Serial.println("Syntax: m<stepper motor><steps>");
Serial.println("Example: mt100");
Serial.println("This will move the tuning stepper motor 100 steps");
}

View file

@ -0,0 +1,22 @@
#ifndef MOVESTEPPER_H
#define MOVESTEPPER_H
#include "Command.h"
/**
* @brief This class is used to move either the tuning or matching stepper motor
*/
class MoveStepper : public Command {
public:
/**
* @brief This function moves the stepper motor
* @param input_line The input line from the serial monitor.
*/
void execute(String input_line) override;
void printResult() override;
void printHelp() override;
private:
uint32_t resonance_frequency;
};
#endif