nameless12242312

module tester

Oct 19th, 2024 (edited)
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. local MC = require("motor_controller")
  2. local file = io.open("moduleData", "a")
  3.  
  4. local function all_trim(s)
  5.     return s:match( "^%s*(.-)%s*$" )
  6. end
  7.  
  8. local collector = peripheral.wrap("right")
  9. local monitor = peripheral.wrap("left")
  10.  
  11. -- Initialization of testing variables
  12. local speed = 1
  13. local iterator = 1
  14.  
  15. -- Initialization of testing module
  16. local belt = MC:new("6", 256, 0)
  17. local M_Crusher = MC:new("4", 256, 0)
  18. local S_Crusher = MC:new("5", 256, 0)
  19.  
  20. --Time Initialization
  21. local timer = os.startTimer(15)
  22. local event, time = os.pullEvent()
  23.  
  24. -- Slave specification
  25. M_Crusher:setSlave(S_Crusher, true)
  26.  
  27. -- Main loop for data collection
  28. while speed < 16 do
  29.     local last
  30.     while  event == "timer" and time ~= timer do
  31.         local event, time = os.pullEvent()
  32.  
  33.         --print formatting
  34.         last = string.format("%s,%s,%s,%d\n",
  35.             string.gsub(all_trim(collector.getLine(1)),","," " ),
  36.             all_trim(collector.getLine(2)),
  37.             all_trim(collector.getLine(3)),
  38.             belt:getSpeed())
  39.  
  40.  
  41.         -- Write the same data to the file
  42.         local file_output = string.format("%s,%s,%s,%d\n",
  43.             string.gsub(all_trim(collector.getLine(1)),","," " ),
  44.             all_trim(collector.getLine(2)),
  45.             all_trim(collector.getLine(3)),
  46.             belt:getSpeed())
  47.        
  48.         file:write(file_output)
  49.  
  50.     end
  51.    
  52.     timer = os.startTimer(15)
  53.  
  54.     -- Increment speed for next iteration
  55.     speed = speed + 1
  56.    
  57.     print(speed)
  58.     -- Increase speed and run motors
  59.     M_Crusher:run(tonumber(speed))
  60.     S_Crusher:run(-tonumber(speed))
  61.     belt:run(tonumber(speed))
  62.  
  63.     term.clear()
  64.     term.setCursorPos(1,1)
  65.     print(string.format("currently on: %d",speed))
  66.     term.setCursorPos(1,2)
  67.     print(last)
  68.  
  69. end
  70.  
  71. -- Close the file
  72. io.close(file)
  73.  
Advertisement
Add Comment
Please, Sign In to add comment