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