Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. using System;
  2.  
  3. public class Program
  4. {
  5. public static void Main()
  6. {
  7. Console.WriteLine("Hello World");
  8. Elevator elevator = new Elevator();
  9. while(true) {
  10. Console.WriteLine("\nPlease enter a value: ");
  11. String value = Console.ReadLine();
  12. elevator.run(Double.Parse(value));
  13. }
  14. }
  15. }
  16.  
  17. class Elevator {
  18. const double tiltThreshold = 20;
  19. const double setpoint = -10;
  20.  
  21. double currentAngle = 0;
  22. bool isFront = true;
  23.  
  24. public void run(double currentAngle) {
  25. this.currentAngle = currentAngle;
  26. run();
  27. }
  28.  
  29. public void run() {
  30. double error = setpoint - this.currentAngle;
  31. Console.WriteLine("Current error: {0}", error);
  32.  
  33. if(Math.Abs(error) >= tiltThreshold) {
  34. Console.WriteLine("Toggling direction.");
  35. isFront = error <= 0 ? false : true;
  36. }
  37.  
  38. if(isFront == false) {
  39. setBackElevator(1);
  40. setFrontElevator(0);
  41. }
  42.  
  43. else {
  44. setBackElevator(0);
  45. setFrontElevator(1);
  46. }
  47. }
  48.  
  49. public void setBackElevator(double value) {
  50. if(value > 0)
  51. Console.WriteLine("Running the back elevator down.");
  52. else if(value == 0)
  53. Console.WriteLine("Stopping the back elevator.");
  54. }
  55.  
  56. public void setFrontElevator(double value) {
  57. if(value > 0)
  58. Console.WriteLine("Running the front elevator down.");
  59. else if(value == 0)
  60. Console.WriteLine("Stopping the front elevator.");
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement