APIs, concepts, guides, and more
rapid_code_python_sample_app_tests.py
1
16
17
18import sys
19
20from pathlib import Path
21
22import ctypes
23import time
24import os
25import platform
26import sys
27import importlib.util
28
29if platform.system() == "Windows":
30 # On Windows, we expect RMP to be in a relative path to the current working directory
31 # so we use the helpers to find it
32 import RapidCodeHelpers as helpers
33 rapidcode_dir = helpers.find_rapid_code_directory()
34 sys.path.append(rapidcode_dir)
35
36 #Import the ntx.dll from INtime
37 os.add_dll_directory("c:\\Program Files (x86)\\INtime\\bin") #ntx.dll
38else:
39 # On Linux, we expect RMP to be in an absolute path, so we use it directly
40 rapidcode_dir = "/rsi"
41 sys.path.append(rapidcode_dir)
42 sys.path.append("/rsi/examples/Python")
43 import RapidCodeHelpers as helpers
44
45import RapidCodePython as RapidCode # The RapidCodePython.py wrapper located in your RMP install directory
46
47import unittest
48import HelloRapidCode
49
50class Testing(unittest.TestCase):
51 def test_hello(self):
52 HelloRapidCode.main()
53
54 # def test_gearing(self):
55 # POSITION=1
56 # VELOCITY=1
57 # ACCELERATION=2
58 # DECELERATION=2
59 # JERK_PERCENT=.5
60 # numerator = 2 # Specify the numerator of the gearing ratio.
61 # denominator = 1 # Specify the denominator of the gearing ratio.
62 # self.axis1.ClearFaults()
63 # self.axis1.AmpEnableSet(True)
64 # self.axis0.ClearFaults()
65 # self.axis0.AmpEnableSet(True)
66 # # Configure the 'follower' axis to be a follow to the 'moving' axis at a ratio of 2:1, that is,
67 # # for every rotation of the Moving Axis axis, the Driven axis will rotate twice.
68 # self.axis1.GearingEnable(self.axis0,
69 # RapidCode.RSIAxisMasterType_RSIAxisMasterTypeAXIS_COMMAND_POSITION, # If NOT using a Phantom Axis, switch to RSIAxisMasterTypeAXIS_ACTUAL_POSITION
70 # numerator,
71 # denominator)
72
73 # # Perform a S-curve motion on the Moving Axis axis.
74 # self.axis0.MoveSCurve(POSITION,
75 # VELOCITY,
76 # ACCELERATION,
77 # DECELERATION,
78 # JERK_PERCENT)
79
80 # self.axis0.MotionDoneWait() # Wait for motion to finish.
81
82 # # Test assert
83 # self.assertEqual(self.axis0.CommandPositionGet(), POSITION, "The command position should be equal to POSITION")
84 # self.assertEqual(self.axis1.CommandPositionGet(), POSITION * (numerator / denominator), "The command position should be equal to twice POSITION")
85
86
87 # def test_s_curve_motion(self):
88
89 # # See axis config to learn how to set those values.
90 # self.axis.ClearFaults()
91 # self.axis.AmpEnableSet(True)
92 # self.axis.MoveSCurve(2,1000,100,100,50)
93 # # Wait for motion to finish
94 # self.axis.MotionDoneWait(constants.timeout)
95
96 # # Test assert
97 # self.assertEqual(self.axis.CommandPositionGet(), 2, "The command position should be equal to POSITION")
98
99
100 def test_iopoint(self):
101 creation_params:RapidCode.CreationParameters = helpers.get_creation_parameters()
102 motioncontroller:RapidCode.MotionController = RapidCode.MotionController.Create(creation_params)
103 helpers.check_errors(motioncontroller)
104
105
106 INPUT_INDEX = 0
107 OUTPUT_INDEX = 1
108
109 user_buffer_address = motioncontroller.AddressGet(RapidCode.RSIControllerAddressType_RSIControllerAddressTypeUSER_BUFFER, 0)
110
111 input0 = RapidCode.IOPoint.CreateDigitalInput( motioncontroller, user_buffer_address, INPUT_INDEX)
112 output0 = RapidCode.IOPoint.CreateDigitalOutput( motioncontroller, user_buffer_address, OUTPUT_INDEX)
113
114 output0.Set(False)
115 assert not output0.Get(), "The getter function should return a value equal to false"
116 output0.Set(True)
117 assert output0.Get(), "The getter function should return a value equal to true"
118 motioncontroller.MemorySet(input0.AddressGet(), 0)
119 assert not input0.Get(), "The getter function should return a value equal to false"
120 motioncontroller.MemorySet(input0.AddressGet(), 1)
121 assert input0.Get(), "The getter function should return a value equal to true"
122
123 motioncontroller.Delete()
124
125
126 # def test_custom_robot_types(self):
127
128 # # The joint index of each axis is the index within the MultiAxis object.
129 # # "X-Axis" has joint index 0
130 # # "Y-Axis" has joint index 1
131 # # "Z-Axis" has joint index 2
132 # # "A-Axis" has joint index 3
133 # # "B-Axis" has joint index 4
134 # # "C-Axis" has joint index 5
135 # axes = [self.axis0, self.axis1, self.axis2, self.axis3, self.axis4, self.axis5]
136 # self.joints.AxesAdd(axes, len(axes))
137 # self.joints.ClearFaults()
138
139 # units = RapidCode.LinearUnits.Meters
140 # modelName = "RSI_XYZABC_Meters"
141 # scaling = 1.0
142 # offset = 0.0
143 # builder = RapidCode.LinearModelBuilder(modelName)
144 # builder.UnitsSet(units)
145 # builder.JointAdd(RapidCode.LinearJointMapping(0, RapidCode.CartesianAxis.X) ) #{ ExpectedLabel = xLabel, Scaling = scaling, Offset = offset })
146 # builder.JointAdd(RapidCode.LinearJointMapping(1, RapidCode.CartesianAxis.Y) ) # { ExpectedLabel = yLabel, Scaling = scaling, Offset = offset })
147 # builder.JointAdd(RapidCode.LinearJointMapping(2, RapidCode.CartesianAxis.Z) ) # { ExpectedLabel = zLabel, Scaling = scaling, Offset = offset })
148 # builder.JointAdd(RapidCode.LinearJointMapping(3, RapidCode.CartesianAxis.Roll) )# { ExpectedLabel = aLabel, Scaling = scaling, Offset = offset })
149 # builder.JointAdd(RapidCode.LinearJointMapping(4, RapidCode.CartesianAxis.Pitch) )#{ ExpectedLabel = bLabel, Scaling = scaling, Offset = offset })
150 # builder.JointAdd(RapidCode.LinearJointMapping(5, RapidCode.CartesianAxis.Yaw) )# { ExpectedLabel = cLabel, Scaling = scaling, Offset = offset })
151
152 # # Create a Robot object with a multi axis containing all joints and the kinematic type
153 # motionFrameBufferSize = 50 # This is the minimum valid motion frame buffer size.
154 # robot = RapidCode.Robot.RobotCreate(self.motioncontroller, self.joints, builder, motionFrameBufferSize)
155 # helpers.CheckErrors(robot)
156
157 # robot.PathAccelerationSet(1000) # UserUnits per sec sqd
158 # robot.PathVelocity
159
160
161
162
163if __name__ == '__main__':
164 unittest.main()