DenseBrainMatrix

Untitled

Sep 23rd, 2024
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.06 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( 'fw-c/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.  
  31.             ( 'abort_file', u32 ),
  32.         ( 'abort_line', u32 ),
  33.         ( 'ridx',       u16 ),
  34.             ( 'buffer1',    u16),
  35.             ( 'target_pos'    ,  u32 ),
  36.             ( 'current_pos'   ,  u32 ),
  37.             ( 'moving'        ,  boolean ),
  38.             ( 'buffer2'  , u16 ),
  39.         ]
  40.  
  41. # map shared memory variables
  42. ddr_layout = core_0.map( DDRLayout,0x10000 )
  43. shmem = core_0.map(UserControlVars, 0x10100)
  44.  
  45. # ready, set, go!
  46. shmem.hault_request = False
  47. pruss.ecap.pwm.initialize( 2**32 )
  48. shmem.current_pos = 0
  49. core_0.run()
  50. print('starting PRU0')
  51.  
  52. try:
  53.     shmem.hault_request = False
  54. #    shmem.target_pos = 400
  55.     shmem.speed = 999
  56.     shmem.moving = True
  57.     print(f'Initial position {shmem.current_pos} Target = {shmem.target_pos}')
  58.     while (shmem.moving == True):
  59.         print(f'\rDesired position {shmem.target_pos} current position {shmem.current_pos}', end = '', flush = True)
  60.         sleep(0.01)
  61.  
  62. except KeyboardInterrupt:
  63.     pass
  64.  
  65. finally:
  66.  
  67.     print( '', flush=True )
  68.     shmem.hault_request = True
  69.     sleep( 0.01 )  # make sure that response has been receivedi
  70.     print(f'Position {shmem.current_pos} Target = {shmem.target_pos}')
  71.     core_0.halt()    
  72.     print('done hopefully you moved')
  73.  
Advertisement
Add Comment
Please, Sign In to add comment