Advertisement
axyd

Three Sorter

Feb 27th, 2025
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. #import the joy of programming python module pyjop
  2. from pyjop import *
  3. #connect to the current SimEnv
  4. SimEnv.connect()
  5.  
  6. #create references to entities in the SimEnv
  7. env = SimEnvManager.first()
  8. env.reset()
  9.  
  10. #function: change belt speed
  11. def setSpd(conv,s):
  12.     conv.set_target_speed(s)
  13.  
  14. #function: check is belt has a package on it
  15. def isTran(conv):
  16.     return conv.get_is_transporting()
  17.  
  18. #function: return rfid tag
  19. def tag(rid):
  20.     return rid.get_rfid_tag()
  21.  
  22. #define list: conveyor belts
  23. belt = []
  24. for b in range(5):
  25.     belt.append(ConveyorBelt.find("belt" + str(b)))
  26.    
  27. #define list: range finders
  28. rf = []
  29. for b in range(2):
  30.     rf.append(RangeFinder.find("scan" + str(b)))
  31.  
  32. #### main loop to retrieve data from the SimEnv, calculate stuff and send commands back into the SimEnv
  33. while SimEnv.run_main():
  34.  
  35.     #initialize the belts that always go forward
  36.     setSpd(belt[0],5)
  37.     setSpd(belt[2],5)
  38.     setSpd(belt[3],5)
  39.  
  40.     #barrel sorter
  41.     if tag(rf[0]) == "Barrel":
  42.         setSpd(belt[1],-10)
  43.         while isTran(belt[1]):
  44.             setSpd(belt[1],-10)
  45.             sleep(1)
  46.     elif tag(rf[0]) == "Cone" or "Box":
  47.         setSpd(belt[1],5)
  48.     else:
  49.         if not isTran(belt[1]):
  50.             setSpd(belt[1],0)
  51.      
  52.     #second sorter
  53.     if tag(rf[1]) == "Cone":
  54.         setSpd(belt[4],7)
  55.     elif tag(rf[1]) == "Box":
  56.         setSpd(belt[4],-7)
  57.     else:
  58.         if not isTran(belt[4]):
  59.             setSpd(belt[4],0)
  60.                
  61.    
  62.            
  63.     #if the first 2 belts are empty then spawn the next package
  64.     if not isTran(belt[0]) and not isTran(belt[1]):
  65.         ObjectSpawner.find("spawner").spawn()
  66.  
  67. #cleanup close code
  68. SimEnv.disconnect()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement