Guest User

Untitled

a guest
Sep 12th, 2024
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.16 KB | None | 0 0
  1. #!/usr/bin/python3
  2. from uio.utils import fix_ctypes_struct
  3. from uio.ti.icss import Icss
  4. from ctypes import c_uint32 as u32, c_uint16 as u16, c_int32 as int32, c_bool as boolean, Structure
  5. from time import sleep
  6. from sys import exit
  7. from bone_pinmux import *
  8.  
  9. print(get_pinmux_state("stepper"))
  10. if (get_pinmux_state("stepper") == "default"):
  11.     set_pinmux_state("stepper","active")
  12. pruss = Icss( "/dev/uio/pruss/module" )
  13. pruss.initialize()
  14.  
  15. core_0 = pruss.core0
  16. core_0.load( 'pulse_train.out' )
  17.  
  18.  
  19. # used to communicate ddr layout to C program
  20. class DDRLayout( Structure ):
  21.     _fields_ = [
  22.             ( 'msgbuf',      u32 ),
  23.             ( 'num_msgs',    u16 ),
  24.             ( 'msg_size',    u16 ),
  25.         ]
  26.  
  27. # volatile variables in pruss shared memory
  28. class UserControlVars( Structure ):
  29.     _fields_ = [
  30.             # PRU parameters            
  31.             ( 'abort_file'   , u32 ),
  32.             ( 'abort_line'   , u32 ),
  33.             ( 'ridx'         , u16 ),
  34.             # stepper parameters
  35.             ( 'target_pos'    ,  u32 ),
  36.             ( 'current_pos'   ,  u32 ),
  37.             ( 'speed'         ,  u32 ),
  38.             ( 'hault_request' ,  boolean ),
  39.             ( 'moving'        ,  boolean ),
  40.         ]
  41.  
  42. # map shared memory variables
  43. ddr_layout = core_0.map( DDRLayout,0x10000 )
  44. shmem = core_0.map(UserControlVars, 0x10100)
  45.  
  46. # ready, set, go!
  47. shmem.hault_request = False
  48. pruss.ecap.pwm.initialize( 2**32 )
  49. shmem.current_pos = 0
  50. core_0.run()
  51. print('starting PRU0')
  52.  
  53. try:
  54.     shmem.hault_request = False
  55.     shmem.target_pos = 400
  56.     shmem.speed = 999
  57.     shmem.moving = True
  58.     print(f'Initial position {shmem.current_pos} Target = {shmem.target_pos}')
  59.     while (shmem.moving == True):
  60.         print(f'\rDesired position {shmem.target_pos} current position {shmem.current_pos}', end = '', flush = True)
  61.         sleep(0.01)
  62.  
  63. except KeyboardInterrupt:
  64.     pass
  65.  
  66. finally:
  67.  
  68.     print( '', flush=True )
  69.     shmem.hault_request = True
  70.     sleep( 0.01 )  # make sure that response has been receivedi
  71.     print(f'Position {shmem.current_pos} Target = {shmem.target_pos}')
  72.     core_0.halt()    
  73.     print('done hopefully you moved')
Advertisement
Add Comment
Please, Sign In to add comment