mirror of
https://github.com/Wessel/Roommapper.git
synced 2026-07-18 14:03:58 +02:00
update motor code
This commit is contained in:
@@ -1,69 +1,63 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace RobotController
|
||||
{
|
||||
class Motor
|
||||
class Motor(int stepOne, int dirOne, int stepTwo, int dirTwo)
|
||||
{
|
||||
StringBuilder outputBuilder;
|
||||
ProcessStartInfo processStartInfo;
|
||||
Process process;
|
||||
|
||||
public int STEP_PIN1 { get; set; }
|
||||
public int DIR_PIN1 { get; set; }
|
||||
public int STEP_PIN1 { get; set; } = stepOne;
|
||||
public int DIR_PIN1 { get; set; } = dirOne;
|
||||
public int STEP_PIN2 { get; set; } = stepTwo;
|
||||
public int DIR_PIN2 { get; set; } = dirTwo;
|
||||
|
||||
public int STEP_PIN2 { get; set; }
|
||||
public int DIR_PIN2 { get; set; }
|
||||
|
||||
public Motor(sTEP_PIN1, dIR_PIN1, sTEP_PIN2, dIR_PIN2)
|
||||
public void Drive(bool direction, int steps)
|
||||
{
|
||||
this.STEP_PIN1 = sTEP_PIN1;
|
||||
this.DIR_PIN1 = dIR_PIN1;
|
||||
outputBuilder = new StringBuilder();
|
||||
processStartInfo = new ProcessStartInfo
|
||||
{
|
||||
CreateNoWindow = true,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardInput = true,
|
||||
UseShellExecute = false,
|
||||
Arguments = "../stepper.py drive",
|
||||
FileName = "/usr/bin/python3"
|
||||
};
|
||||
|
||||
this.STEP_PIN2 = sTEP_PIN2;
|
||||
this.DIR_PIN2 = dIR_PIN2;
|
||||
process = new Process
|
||||
{
|
||||
StartInfo = processStartInfo,
|
||||
// enable raising events because Process does not raise events by default
|
||||
EnableRaisingEvents = true
|
||||
};
|
||||
|
||||
// attach the event handler for OutputDataReceived before starting the process
|
||||
process.OutputDataReceived += new DataReceivedEventHandler
|
||||
(
|
||||
delegate (object sender, DataReceivedEventArgs e)
|
||||
{
|
||||
// append the new data to the data already read-in
|
||||
outputBuilder.Append(e.Data);
|
||||
}
|
||||
);
|
||||
// start the process
|
||||
// then begin asynchronously reading the output
|
||||
// then wait for the process to exit
|
||||
// then cancel asynchronously reading the output
|
||||
process.Start();
|
||||
process.BeginOutputReadLine();
|
||||
process.WaitForExit();
|
||||
process.CancelOutputRead();
|
||||
|
||||
// use the output
|
||||
string output = outputBuilder.ToString();
|
||||
|
||||
Console.WriteLine(output);
|
||||
|
||||
}
|
||||
|
||||
public Drive(bool direction, int steps)
|
||||
{
|
||||
outputBuilder = new StringBuilder();
|
||||
|
||||
processStartInfo = new ProcessStartInfo();
|
||||
processStartInfo.CreateNoWindow = true;
|
||||
processStartInfo.RedirectStandardOutput = true;
|
||||
processStartInfo.RedirectStandardInput = true;
|
||||
processStartInfo.UseShellExecute = false;
|
||||
processStartInfo.Arguments = "/home/wouter/roommapper/src/Client/RobotController/stepper.py drive";
|
||||
processStartInfo.FileName = "/usr/bin/python3";
|
||||
|
||||
process = new Process();
|
||||
process.StartInfo = processStartInfo;
|
||||
// enable raising events because Process does not raise events by default
|
||||
process.EnableRaisingEvents = true;
|
||||
// attach the event handler for OutputDataReceived before starting the process
|
||||
process.OutputDataReceived += new DataReceivedEventHandler
|
||||
(
|
||||
delegate(object sender, DataReceivedEventArgs e)
|
||||
{
|
||||
// append the new data to the data already read-in
|
||||
outputBuilder.Append(e.Data);
|
||||
}
|
||||
);
|
||||
// start the process
|
||||
// then begin asynchronously reading the output
|
||||
// then wait for the process to exit
|
||||
// then cancel asynchronously reading the output
|
||||
process.Start();
|
||||
process.BeginOutputReadLine();
|
||||
process.WaitForExit();
|
||||
process.CancelOutputRead();
|
||||
|
||||
// use the output
|
||||
string output = outputBuilder.ToString();
|
||||
|
||||
Console.WriteLine(output);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user