Motion acceleration blending

  1'''
  2Motion - Motion_velocity_blending_acceleration.py with synchronous mode.
  3
  4-------------------------------------------------------------------------------------
  5Please change correct serial number or IP and port number BEFORE you run example code.
  6
  7For other examples please check:
  8    https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
  9See README.md file to get detailed usage of this example.
 10
 11Copyright (c) 2022-2024 WPC Systems Ltd. All rights reserved.
 12'''
 13
 14## Python
 15import time
 16
 17## WPC
 18
 19from wpcsys import pywpc
 20
 21def main():
 22    ## Get Python driver version
 23    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
 24
 25    ## Create device handle
 26    dev = pywpc.EMotion()
 27
 28    ## Connect to device
 29    try:
 30        dev.connect("192.168.1.110") ## Depend on your device
 31    except Exception as err:
 32        pywpc.printGenericError(err)
 33        ## Release device handle
 34        dev.close()
 35        return
 36
 37    try:
 38        ## Parameters setting
 39        port = 0 ## Depend on your device
 40        axis = 0
 41        two_pulse_mode = 1
 42        velocity_mode = 2
 43        stop_decel = 0
 44        timeout = 3 ## second
 45
 46        ## Axis and encoder parameters
 47        axis_dir_cw = 0
 48        encoder_dir_cw = 0
 49
 50        ## Polarity and enable parameters
 51        active_low = 0
 52        active_high = 1
 53        forward_enable_true = 1
 54        reverse_enable_true = 1
 55
 56        ## Get firmware model & version
 57        driver_info = dev.Sys_getDriverInfo(timeout)
 58        print("Model name: " + driver_info[0])
 59        print("Firmware version: " + driver_info[-1])
 60
 61        ## Motion open
 62        err = dev.Motion_open(port, timeout)
 63        print(f"Motion_open in port {port}, status: {err}")
 64
 65        '''
 66        ## Motion open configuration file
 67        err = dev.Motion_openCfgFile('C:/Users/user/Desktop/3AxisStage_2P.ini')
 68        print(f"openCfgFile, status: {err}")
 69
 70        ## Motion load configuration file
 71        err = dev.Motion_loadCfgFile()
 72        print(f"loadCfgFile, status: {err}")
 73        '''
 74
 75        ## Motion configure
 76        err = dev.Motion_cfgAxis(port, axis, two_pulse_mode, axis_dir_cw, encoder_dir_cw, active_low, timeout)
 77        print(f"Motion_cfgAxis in axis{axis}, status: {err}")
 78
 79        err = dev.Motion_cfgAxisMove(port, axis, velocity_mode, target_posi=5000, velo=3000, accel=100000, decel=100000, timeout=timeout)
 80        print(f"Motion_cfgAxisMove in axis{axis}, status: {err}")
 81
 82        ## Servo on
 83        err = dev.Motion_enableServoOn(port, axis, timeout)
 84        print(f"Motion_enableServoOn in axis{axis}, status: {err}")
 85
 86        err = dev.Motion_cfgLimit(port, axis, forward_enable_true, reverse_enable_true, active_low, timeout)
 87        print(f"Motion_cfgLimit in axis{axis}, status: {err}")
 88
 89        err = dev.Motion_cfgEncoder(port, axis, active_low, timeout)
 90        print(f"Motion_cfgEncoder in axis{axis}, status: {err}")
 91
 92        err = dev.Motion_rstEncoderPosi(port, axis, encoder_posi=0, timeout=timeout)
 93        print(f"Motion_rstEncoderPosi in axis{axis}, status: {err}")
 94
 95        ## Motion start
 96        err = dev.Motion_startSingleAxisMove(port, axis, timeout)
 97        print(f"Motion_startSingleAxisMove in axis{axis}, status: {err}")
 98
 99        ## Wait for 5 seconds for moving
100        time.sleep(5) ## delay [s]
101
102        ## Motion override velocity
103        new_velo = -3000
104        new_accel = 100
105        new_decel = 100
106        err = dev.Motion_overrideAxisVelocity(port, axis, new_velo, timeout)
107        print(f"Motion_overrideAxisVelocity in axis{axis}, status: {err}")
108
109        ## Motion override acceleration
110        err = dev.Motion_overrideAxisAccel(port, axis, new_accel, new_decel, timeout)
111        print(f"Motion_overrideAxisAccel in axis{axis}, status: {err}")
112
113        ## Wait for 5 seconds for moving
114        time.sleep(5) ## delay [s]
115
116        new_velo = 6000
117        new_accel = 100000
118        new_decel = 100000
119        ## Motion override velocity
120        err = dev.Motion_overrideAxisVelocity(port, axis, new_velo, timeout)
121        print(f"Motion_overrideAxisVelocity in axis{axis}, status: {err}")
122
123        ## Motion override acceleration
124        err = dev.Motion_overrideAxisAccel(port, axis, new_accel, new_decel, timeout)
125        print(f"Motion_overrideAxisAccel in axis{axis}, status: {err}")
126
127        ## Motion stop
128        err = dev.Motion_stop(port, axis, stop_decel, timeout)
129        print(f"Motion_stop in axis{axis}, status: {err}")
130
131        ## Servo off
132        err = dev.Motion_enableServoOff(port, axis, timeout)
133        print(f"Motion_enableServoOff in axis{axis}, status: {err}")
134
135        ## Motion close
136        err = dev.Motion_close(port, timeout)
137        print(f"Motion_close in port {port}, status: {err}")
138    except Exception as err:
139        pywpc.printGenericError(err)
140
141    ## Disconnect device
142    dev.disconnect()
143
144    ## Release device handle
145    dev.close()
146
147    return
148
149if __name__ == '__main__':
150    main()