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-2025 WPC Systems Ltd. All rights reserved.
 12'''
 13
 14## WPC
 15from wpcsys import pywpc
 16
 17## Python
 18import time
 19
 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  ## [sec]
 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(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
 59
 60        ## Motion open
 61        err = dev.Motion_open(port, timeout)
 62        print(f"Motion_open in port {port}, status: {err}")
 63
 64        '''
 65        ## Motion open configuration file
 66        err = dev.Motion_openCfgFile('C:/Users/user/Desktop/3AxisStage_2P.ini')
 67        print(f"openCfgFile, status: {err}")
 68
 69        ## Motion load configuration file
 70        err = dev.Motion_loadCfgFile()
 71        print(f"loadCfgFile, status: {err}")
 72        '''
 73
 74        ## Motion configure
 75        err = dev.Motion_cfgAxis(port, axis, two_pulse_mode, axis_dir_cw, encoder_dir_cw, active_low, timeout)
 76        print(f"Motion_cfgAxis in axis{axis}, status: {err}")
 77
 78        err = dev.Motion_cfgAxisMove(port, axis, velocity_mode, target_posi=5000, velo=3000, accel=100000, decel=100000, timeout=timeout)
 79        print(f"Motion_cfgAxisMove in axis{axis}, status: {err}")
 80
 81        ## Servo on
 82        err = dev.Motion_enableServoOn(port, axis, timeout)
 83        print(f"Motion_enableServoOn in axis{axis}, status: {err}")
 84
 85        err = dev.Motion_cfgLimit(port, axis, forward_enable_true, reverse_enable_true, active_low, timeout)
 86        print(f"Motion_cfgLimit in axis{axis}, status: {err}")
 87
 88        err = dev.Motion_cfgEncoder(port, axis, active_low, timeout)
 89        print(f"Motion_cfgEncoder in axis{axis}, status: {err}")
 90
 91        err = dev.Motion_rstEncoderPosi(port, axis, encoder_posi=0, timeout=timeout)
 92        print(f"Motion_rstEncoderPosi in axis{axis}, status: {err}")
 93
 94        ## Motion start
 95        err = dev.Motion_startSingleAxisMove(port, axis, timeout)
 96        print(f"Motion_startSingleAxisMove in axis{axis}, status: {err}")
 97
 98        ## Wait for 5 seconds for moving
 99        time.sleep(5)  ## delay [sec]
100
101        ## Motion override velocity
102        new_velo = -3000
103        new_accel = 100
104        new_decel = 100
105        err = dev.Motion_overrideAxisVelocity(port, axis, new_velo, timeout)
106        print(f"Motion_overrideAxisVelocity in axis{axis}, status: {err}")
107
108        ## Motion override acceleration
109        err = dev.Motion_overrideAxisAccel(port, axis, new_accel, new_decel, timeout)
110        print(f"Motion_overrideAxisAccel in axis{axis}, status: {err}")
111
112        ## Wait for 5 seconds for moving
113        time.sleep(5)  ## delay [sec]
114
115        new_velo = 6000
116        new_accel = 100000
117        new_decel = 100000
118        ## Motion override velocity
119        err = dev.Motion_overrideAxisVelocity(port, axis, new_velo, timeout)
120        print(f"Motion_overrideAxisVelocity in axis{axis}, status: {err}")
121
122        ## Motion override acceleration
123        err = dev.Motion_overrideAxisAccel(port, axis, new_accel, new_decel, timeout)
124        print(f"Motion_overrideAxisAccel in axis{axis}, status: {err}")
125
126        ## Motion stop
127        err = dev.Motion_stop(port, axis, stop_decel, timeout)
128        print(f"Motion_stop in axis{axis}, status: {err}")
129
130        ## Servo off
131        err = dev.Motion_enableServoOff(port, axis, timeout)
132        print(f"Motion_enableServoOff in axis{axis}, status: {err}")
133
134        ## Motion close
135        err = dev.Motion_close(port, timeout)
136        print(f"Motion_close in port {port}, status: {err}")
137    except Exception as err:
138        pywpc.printGenericError(err)
139
140    finally:
141        ## Disconnect device
142        dev.disconnect()
143
144        ## Release device handle
145        dev.close()
146
147
148if __name__ == '__main__':
149    main()