Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class Program
- {
- public static void Main()
- {
- Console.WriteLine("Hello World");
- Elevator elevator = new Elevator();
- while(true) {
- Console.WriteLine("\nPlease enter a value: ");
- String value = Console.ReadLine();
- elevator.run(Double.Parse(value));
- }
- }
- }
- class Elevator {
- const double tiltThreshold = 20;
- const double setpoint = -10;
- double currentAngle = 0;
- bool isFront = true;
- public void run(double currentAngle) {
- this.currentAngle = currentAngle;
- run();
- }
- public void run() {
- double error = setpoint - this.currentAngle;
- Console.WriteLine("Current error: {0}", error);
- if(Math.Abs(error) >= tiltThreshold) {
- Console.WriteLine("Toggling direction.");
- isFront = error <= 0 ? false : true;
- }
- if(isFront == false) {
- setBackElevator(1);
- setFrontElevator(0);
- }
- else {
- setBackElevator(0);
- setFrontElevator(1);
- }
- }
- public void setBackElevator(double value) {
- if(value > 0)
- Console.WriteLine("Running the back elevator down.");
- else if(value == 0)
- Console.WriteLine("Stopping the back elevator.");
- }
- public void setFrontElevator(double value) {
- if(value > 0)
- Console.WriteLine("Running the front elevator down.");
- else if(value == 0)
- Console.WriteLine("Stopping the front elevator.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement