Best Python code snippet using lemoncheesecake
preprocessing_test.py
Source:preprocessing_test.py
...107 """ Test the load libsvm to S3 function. """108 printer = prefix_print("TEST_LOAD")109 timer = Timer("TEST_LOAD", verbose=True)110 if wipe_keys:111 timer.set_step("Wiping keys in bucket")112 delete_all_keys(s3_bucket_output)113 timer.timestamp()114 if not no_load:115 timer.set_step("Loading libsvm file into S3")116 Preprocessing.load_libsvm(src_file, s3_bucket_output)117 timer.timestamp()118 if not check_output:119 return True120 timer.set_step("Getting keys from bucket")121 objects = get_all_keys(s3_bucket_output)122 timer.timestamp().set_step("Loading libsvm file into memory")123 data = load_data(src_file)[0]124 timer.timestamp().set_step("Checking chunk 0")125 printer("Checking that all values are present")126 obj_num = 0127 obj_idx = -1128 client = boto3.client("s3")129 obj = get_data_from_s3(client, s3_bucket_output, objects[obj_num])130 for row in range(data.shape[0]):131 cols = data[row, :].nonzero()[1]132 obj_idx += 1133 if obj_idx >= 50000:134 obj_idx = 0135 obj_num += 1136 timer.timestamp().set_step("Checking chunk {0}".format(obj_num))137 try:138 obj = get_data_from_s3(139 client, s3_bucket_output, objects[obj_num])140 except ClientError as exc:141 printer("Error: Not enough chunks given" +142 " the number of rows in original data. Finished " +143 "on chunk index {0}, key {1}. Exception: {0}"144 .format(obj_num, objects[obj_num], exc))145 return False146 for idx, col in enumerate(cols):147 v_orig = data[row, col]148 try:149 v_obj = obj[obj_idx][idx]150 except IndexError as exc:151 printer("Found error on row {0}, column {1} of the ".format(152 row, col) +153 "source data, row {2}, column {3} of chunk {4}".format(154 obj_idx, idx, obj_num))155 return False156 if v_obj[0] != col:157 printer("Value on row {0} of S3 object {1} has".format(158 obj_idx, objects[obj_num]) +159 " column {2}, expected column {3}".format(160 v_obj[0], col))161 continue162 if abs(v_obj[1] - v_orig) > .01:163 printer("Value on row {0}, column {1} of S3".format(164 obj_idx, col) +165 " object {2} is {3}, expected {4} from row {5},".format(166 objects[obj_num], v_obj[1], v_orig, row) +167 " column {6} of original data"168 .format(col))169 return True170def test_simple(s3_bucket_input, s3_bucket_output, min_v, max_v,171 objects=(), preprocess=True, wipe_keys=False,172 skip_bounds=False):173 """ Make sure all data is in bounds in output, and all data174 is present from input """175 timer = Timer("TEST_SIMPLE", verbose=True)176 if wipe_keys:177 timer.set_step("Wiping keys in bucket {}".format(s3_bucket_output))178 delete_all_keys(s3_bucket_output)179 timer.timestamp()180 timer.set_step("Getting all keys")181 if not objects:182 # Allow user to specify objects, or otherwise get all objects.183 objects = get_all_keys(s3_bucket_input)184 timer.timestamp()185 if preprocess:186 timer.set_step("Running preprocessing")187 Preprocessing.normalize(s3_bucket_input, s3_bucket_output,188 Normalization.MIN_MAX, min_v, max_v,189 objects, True, False, skip_bounds)190 timer.timestamp()191 timer.set_step("Running threads for each object")192 launch_threads(SimpleTest, objects, 400, s3_bucket_input,193 s3_bucket_output, min_v, max_v)194 timer.timestamp()195def test_hash(s3_bucket_input, s3_bucket_output, columns, n_buckets,196 objects=(), feature_hashing=True):197 """ Test that feature hashing was correct """198 timer = Timer("TEST_HASH", verbose=True).set_step("Getting all keys")199 if not objects:200 # Allow user to specify objects, or otherwise get all objects.201 objects = get_all_keys(s3_bucket_input)202 timer.timestamp()203 if feature_hashing:204 timer.set_step("Running feature hashing")205 Preprocessing.feature_hashing(206 s3_bucket_input, s3_bucket_output, columns, n_buckets, objects)207 timer.timestamp()208 timer.set_step("Running threads for each object")209 launch_threads(HashTest, objects, 400, s3_bucket_input,210 s3_bucket_output, columns, n_buckets)211 timer.timestamp()212def setup_test(timer, wipe_keys, preprocess, skip_load, src_file,213 s3_bucket_output):214 """ Wipe keys and load_libsvm if needed. """215 if wipe_keys:216 timer.set_step("Wiping keys in bucket")217 delete_all_keys(s3_bucket_output)218 timer.timestamp()219 if preprocess and not skip_load:220 timer.set_step("Running load_libsvm")221 Preprocessing.load_libsvm(src_file, s3_bucket_output)222 timer.timestamp()223def test_min_max(src_file, s3_bucket_output, min_v, max_v, objects=(),224 preprocess=False, skip_load=False, wipe_keys=False,225 check_global_map_cache=True):226 """ Check that data was scaled correctly, assuming src_file was serialized227 sequentially into the keys specified in "objects". """228 timer = Timer("TEST_MIN_MAX", verbose=True)229 setup_test(timer, wipe_keys, preprocess, skip_load, src_file,230 s3_bucket_output)231 timer.set_step("Getting all keys")232 if not objects:233 objects = get_all_keys(s3_bucket_output)234 timer.timestamp()235 if preprocess:236 timer.set_step("Running preprocessing")237 Preprocessing.normalize(238 s3_bucket_output, s3_bucket_output, Normalization.MIN_MAX,239 min_v, max_v, objects)240 timer.timestamp()241 timer.set_step("Loading all data")242 data = load_data(src_file)[0]243 timer.timestamp().set_step("Constructing global map")244 if check_global_map_cache and os.path.isfile("global_map"):245 with open("global_map", "rb") as f:246 g_map = pickle.load(f)247 else:248 g_map = {} # Map of min / max by column249 for row in range(data.shape[0]):250 cols = data[row, :].nonzero()[1]251 for col in cols:252 val = data[row, col]253 if col not in g_map:254 g_map[col] = [val, val]255 if val < g_map[col][0]:256 g_map[col][0] = val257 if val > g_map[col][1]:258 g_map[col][1] = val259 with open("global_map", "wb") as f:260 pickle.dump(g_map, f)261 timer.timestamp().set_step("Testing all chunks")262 client = boto3.client("s3")263 obj_num = 0264 obj_idx = -1265 n_errors = 0266 obj = get_data_from_s3(client, s3_bucket_output, objects[obj_num])267 printer = prefix_print("TEST_MIN_MAX")268 for row in range(data.shape[0]):269 # row is the row in the libsvm file object270 # obj_idx is the row in the S3 object271 cols = data[row, :].nonzero()[1]272 obj_idx += 1273 if obj_idx >= 50000:274 obj_idx = 0275 obj_num += 1276 try:277 obj = get_data_from_s3(278 client, s3_bucket_output, objects[obj_num])279 except ClientError as exc:280 printer("Error: Not enough chunks given the " +281 "number of rows in original data. Finished on " +282 "chunk index {0}, key {1}. Exception: {1}".format(283 obj_num, objects[obj_num], exc))284 return285 for idx, col in enumerate(cols):286 try:287 v_orig = data[row, col]288 v_obj = obj[obj_idx][idx]289 if v_obj[0] != col:290 # Ensure the column is correct291 printer("Value on row {0} of S3 object {1}".format(292 obj_idx, obj_num) +293 " has column {2}, expected column {3}".format(294 v_obj[0], col))295 n_errors += 1296 if n_errors == 10:297 return298 obj_min_v, obj_max_v = g_map[col]299 scaled = (min_v + max_v) / 2.0300 if abs(obj_max_v - obj_min_v) > EPSILON:301 scaled = (v_orig - obj_min_v) / (obj_max_v - obj_min_v)302 scaled *= (max_v - min_v)303 scaled += min_v304 if abs(scaled - v_obj[1]) > EPSILON:305 printer("Value on row {0}, column {1} of".format(306 obj_idx, col) +307 " S3 object {0} is value {1}, expected {2} from row"308 .format(obj_num, v_obj[1], scaled) +309 " {0}, column {1} of libsvm file".format(310 row, col))311 printer("Min value {0}, max value {1}"312 .format(obj_min_v, obj_max_v))313 n_errors += 1314 if n_errors == 10:315 return316 except IndexError as exc:317 print("Exception on row {0} of S3 object {1}".format(318 obj_idx, obj_num) +319 ", row {0} col {1} of libsvm file".format(320 row, col))321 print("Original data cols: {0}".format(cols))322 print("S3 data cols: {0}".format(obj[obj_idx]))323 raise exc324 timer.timestamp()325def test_normal(src_file, s3_bucket_output, objects=(),326 preprocess=False, skip_load=False, wipe_keys=False,327 check_global_map_cache=True):328 """ Check that data was normal scaled correctly. """329 timer = Timer("TEST_NORMAL", verbose=True)330 setup_test(timer, wipe_keys, preprocess, skip_load, src_file,331 s3_bucket_output)332 timer.set_step("Getting all keys")333 if not objects:334 objects = get_all_keys(s3_bucket_output)335 if preprocess:336 timer.set_step("Running preprocessing")337 Preprocessing.normalize(338 s3_bucket_output, s3_bucket_output, Normalization.NORMAL,339 objects)340 timer.timestamp()341 timer.set_step("Loading all data")342 data = load_data(src_file)[0]343 timer.timestamp().set_step("Constructing global map")344 if check_global_map_cache and os.path.isfile("global_map"):345 with open("global_map", "rb") as f:346 g_map = pickle.load(f)347 else:348 g_map = {} # Map of sum(X), sum(X^2) and N by column349 for row in range(data.shape[0]):350 cols = data[row, :].nonzero()[1]351 for col in cols:352 val = data[row, col]353 if col not in g_map:354 g_map[col] = [0, 0, 0]355 g_map[col][0] += val356 g_map[col][1] += val**2357 g_map[col][2] += 1358 with open("global_map", "wb") as f:359 pickle.dump(g_map, f)360 timer.timestamp().set_step("Testing all chunks")361 client = boto3.client("s3")362 obj_num = 0363 obj_idx = -1364 n_errors = 0365 obj = get_data_from_s3(client, s3_bucket_output, objects[obj_num])366 printer = prefix_print("TEST_NORMAL")367 for row in range(data.shape[0]):368 # row is the row in the libsvm file object369 # obj_idx is the row in the S3 object370 cols = data[row, :].nonzero()[1]371 obj_idx += 1372 if obj_idx >= 50000:373 obj_idx = 0374 obj_num += 1375 try:376 obj = get_data_from_s3(377 client, s3_bucket_output, objects[obj_num])378 except ClientError as exc:379 printer("Error: Not enough chunks given the " +380 "number of rows in original data. Finished on " +381 "chunk index {0}, key {1}. Exception: {1}".format(382 obj_num, objects[obj_num], exc))383 return384 for idx, col in enumerate(cols):385 try:386 v_orig = data[row, col]387 v_obj = obj[obj_idx][idx]388 if v_obj[0] != col:389 # Ensure the column is correct390 printer("Value on row {0} of S3 object {1}".format(391 obj_idx, obj_num) +392 " has column {2}, expected column {3}".format(393 v_obj[0], col))394 n_errors += 1395 if n_errors == 10:396 return397 sum_x, sum_x_squared, n_vals = g_map[col]398 mean = sum_x / float(n_vals)399 std_dev = 0400 variance = sum_x_squared / float(n_vals) - mean**2401 if abs(variance) < EPSILON:402 std_dev = 0403 else:404 std_dev = (variance)**.5405 scaled = 0406 if std_dev != 0:407 scaled = (v_orig - mean) / std_dev408 if abs(scaled - v_obj[1]) > EPSILON:409 printer("Value on row {0}, column {1} of".format(410 obj_idx, col) +411 " S3 object {0} is value {1}, expected {2} from row"412 .format(obj_num, v_obj[1], scaled) +413 " {0}, column {1} of libsvm file".format(414 row, col))415 printer("Original value {0}".format(v_orig))416 printer("Sum(X) {0}, Sum(X^2) {1}, N {2}"417 .format(sum_x, sum_x_squared, n_vals))418 printer("E[X] {0}, E[X]^2 {1}, E[X^2] {2}"419 .format(sum_x / float(n_vals),420 (sum_x / float(n_vals))**2,421 sum_x_squared / float(n_vals)))422 n_errors += 1423 if n_errors == 10:424 return425 except IndexError as exc:426 print("Exception on row {0} of S3 object {1}".format(427 obj_idx, obj_num) +428 ", row {0} col {1} of libsvm file".format(429 row, col))430 print("Original data cols: {0}".format(cols))431 print("S3 data cols: {0}".format(obj[obj_idx]))432 raise exc433 timer.timestamp()434def main():435 """ Run all of the tests. """436 timer = Timer("MAIN", verbose=True).set_step("Running load_libsvm")437 if RUN_TEST == Test.ALL or RUN_TEST == Test.LOAD_LIBSVM:438 test_load_libsvm(LIBSVM_FILE, OUTPUT_BUCKET, wipe_keys=True)439 timer.timestamp().set_step("Running test_simple")440 if RUN_TEST == Test.ALL or RUN_TEST == Test.SIMPLE_TEST:441 test_simple(INPUT_BUCKET, OUTPUT_BUCKET, 0.0, 1.0,442 objects=["1", "2", "3"],443 preprocess=True, wipe_keys=True)444 timer.timestamp().set_step("Running test_min_max")445 if RUN_TEST == Test.ALL or RUN_TEST == Test.MIN_MAX_TEST:446 test_min_max(LIBSVM_FILE, OUTPUT_BUCKET, 0.0, 1.0,447 objects=["1", "2", "3"], preprocess=True, skip_load=False,448 wipe_keys=True, check_global_map_cache=False)449 timer.timestamp().set_step("Running test_normal")450 if RUN_TEST == Test.ALL or RUN_TEST == Test.NORMAL_TEST:451 test_normal(LIBSVM_FILE, OUTPUT_BUCKET, objects=["1", "2", "3"],452 preprocess=True, skip_load=False, wipe_keys=True,453 check_global_map_cache=False)454 timer.timestamp().set_step("Running test_hash")455 if RUN_TEST == Test.ALL or RUN_TEST == Test.HASH_TEST:456 test_hash(INPUT_BUCKET, OUTPUT_BUCKET, ["40189"], 1000,457 objects=["1", "2", "3"])458 timer.timestamp().global_timestamp()459if __name__ == "__main__":...
z_drive.py
Source:z_drive.py
...28# uchar phasecw[4] ={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09}; # æ£è½¬ çµæºå¯¼éç¸åº D-C-B-A29# uchar phaseccw[4]={0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08}; # å转 çµæºå¯¼éç¸åº A-B-C-D30# DELAY_NORMAL为æ£å¸¸èå²é´éï¼å¯¹äºæ§å¶åå½æ°ä¸ç´æ¥èµå¼ç»delayï¼è°ç¨å½æ°æ¯è¥éä¿®æ¹å¯ä»¥ä»¥å®åå½¢å¼ç´æ¥å¤å¶ç»delay31DELAY_NORMAL = 332def set_step(w1, w2, w3, w4):33 GPIO.output(IN1, w1)34 GPIO.output(IN2, w2)35 GPIO.output(IN3, w3)36 GPIO.output(IN4, w4)37def stop():38 set_step(0, 0, 0, 0)39# 8æ驱å¨ï¼åå40def forward(steps, delay=DELAY_NORMAL):41 for i in range(0, steps):42 set_step(1, 0, 0, 0)43 wiringpi.delay(delay)44 set_step(1, 1, 0, 0)45 wiringpi.delay(delay)46 set_step(0, 1, 0, 0)47 wiringpi.delay(delay)48 set_step(0, 1, 1, 0)49 wiringpi.delay(delay)50 set_step(0, 0, 1, 0)51 wiringpi.delay(delay)52 set_step(0, 0, 1, 1)53 wiringpi.delay(delay)54 set_step(0, 0, 0, 1)55 wiringpi.delay(delay)56 set_step(1, 0, 0, 1)57 wiringpi.delay(delay)58# 8æ驱å¨ï¼åå59def backward(steps, delay=DELAY_NORMAL):60 for i in range(0, steps):61 set_step(0, 0, 0, 1)62 wiringpi.delay(delay)63 set_step(0, 0, 1, 1)64 wiringpi.delay(delay)65 set_step(0, 0, 1, 0)66 wiringpi.delay(delay)67 set_step(0, 1, 1, 0)68 wiringpi.delay(delay)69 set_step(0, 1, 0, 0)70 wiringpi.delay(delay)71 set_step(1, 1, 0, 0)72 wiringpi.delay(delay)73 set_step(1, 0, 0, 0)74 wiringpi.delay(delay)75 set_step(1, 0, 0, 1)76 wiringpi.delay(delay)77# /////////////////////////////////////////////////////////////////////////////////////////78# 4æ驱å¨ï¼direction为æ¹åï¼z_forward 为ååï¼z_backward 为åå79# delay为èå²é´éï¼delayMicrosecondsæ¯ä»¥us为åä½ï¼delayæ¯ä»¥ms为åä½80def step_drive(direction, step_num, delay=DELAY_NORMAL):81 # ååè¿å¨82 if direction == 'z_forward':83 for i in range(0, step_num):84 set_step(0, 1, 1, 0)85 wiringpi.delay(delay)86 set_step(0, 0, 1, 1)87 wiringpi.delay(delay)88 set_step(1, 0, 0, 1)89 wiringpi.delay(delay)90 set_step(1, 1, 0, 0)91 wiringpi.delay(delay)92 # ååè¿å¨93 elif direction == 'z_backward':94 for i in range(0, step_num):95 set_step(1, 1, 0, 0)96 wiringpi.delay(delay)97 set_step(1, 0, 0, 1)98 wiringpi.delay(delay)99 set_step(0, 0, 1, 1)100 wiringpi.delay(delay)101 set_step(0, 1, 1, 0)102 wiringpi.delay(delay)103 # 没æ设å®æ¹åç´æ¥è¿å并æ示104 else:105 print('Z轴没ææå®æ¹åï¼è¯·æ£æ¥')106 return107# \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\108# åå§å设å®109def setup():110 GPIO.setwarnings(False)111 GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location112 GPIO.setup(IN1, GPIO.OUT) # Set pin's mode is output113 GPIO.setup(IN2, GPIO.OUT)114 GPIO.setup(IN3, GPIO.OUT)115 GPIO.setup(IN4, GPIO.OUT)...
z_drive_old.py
Source:z_drive_old.py
...28# uchar phasecw[4] ={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09}; # æ£è½¬ çµæºå¯¼éç¸åº D-C-B-A29# uchar phaseccw[4]={0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08}; # å转 çµæºå¯¼éç¸åº A-B-C-D30# DELAY_NORMAL为æ£å¸¸èå²é´éï¼å¯¹äºæ§å¶åå½æ°ä¸ç´æ¥èµå¼ç»delayï¼è°ç¨å½æ°æ¯è¥éä¿®æ¹å¯ä»¥ä»¥å®åå½¢å¼ç´æ¥å¤å¶ç»delay31DELAY_NORMAL = 332def set_step(w1, w2, w3, w4):33 GPIO.output(IN1, w1)34 GPIO.output(IN2, w2)35 GPIO.output(IN3, w3)36 GPIO.output(IN4, w4)37def stop():38 set_step(0, 0, 0, 0)39# 8æ驱å¨ï¼åå40def forward(steps, delay=DELAY_NORMAL):41 for i in range(0, steps):42 set_step(1, 0, 0, 0)43 wiringpi.delay(delay)44 set_step(1, 1, 0, 0)45 wiringpi.delay(delay)46 set_step(0, 1, 0, 0)47 wiringpi.delay(delay)48 set_step(0, 1, 1, 0)49 wiringpi.delay(delay)50 set_step(0, 0, 1, 0)51 wiringpi.delay(delay)52 set_step(0, 0, 1, 1)53 wiringpi.delay(delay)54 set_step(0, 0, 0, 1)55 wiringpi.delay(delay)56 set_step(1, 0, 0, 1)57 wiringpi.delay(delay)58# 8æ驱å¨ï¼åå59def backward(steps, delay=DELAY_NORMAL):60 for i in range(0, steps):61 set_step(0, 0, 0, 1)62 wiringpi.delay(delay)63 set_step(0, 0, 1, 1)64 wiringpi.delay(delay)65 set_step(0, 0, 1, 0)66 wiringpi.delay(delay)67 set_step(0, 1, 1, 0)68 wiringpi.delay(delay)69 set_step(0, 1, 0, 0)70 wiringpi.delay(delay)71 set_step(1, 1, 0, 0)72 wiringpi.delay(delay)73 set_step(1, 0, 0, 0)74 wiringpi.delay(delay)75 set_step(1, 0, 0, 1)76 wiringpi.delay(delay)77# /////////////////////////////////////////////////////////////////////////////////////////78# 4æ驱å¨ï¼direction为æ¹åï¼z_forward 为ååï¼z_backward 为åå79# delay为èå²é´éï¼delayMicrosecondsæ¯ä»¥us为åä½ï¼delayæ¯ä»¥ms为åä½80def step_drive(direction, step_num, delay=DELAY_NORMAL):81 # ååè¿å¨82 if direction == 'z_forward':83 for i in range(0, step_num):84 set_step(0, 1, 1, 0)85 wiringpi.delay(delay)86 set_step(0, 0, 1, 1)87 wiringpi.delay(delay)88 set_step(1, 0, 0, 1)89 wiringpi.delay(delay)90 set_step(1, 1, 0, 0)91 wiringpi.delay(delay)92 # ååè¿å¨93 elif direction == 'z_backward':94 for i in range(0, step_num):95 set_step(1, 1, 0, 0)96 wiringpi.delay(delay)97 set_step(1, 0, 0, 1)98 wiringpi.delay(delay)99 set_step(0, 0, 1, 1)100 wiringpi.delay(delay)101 set_step(0, 1, 1, 0)102 wiringpi.delay(delay)103 # 没æ设å®æ¹åç´æ¥è¿å并æ示104 else:105 print('Z轴没ææå®æ¹åï¼è¯·æ£æ¥')106 return107# \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\108# åå§å设å®109def setup():110 GPIO.setwarnings(False)111 GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location112 GPIO.setup(IN1, GPIO.OUT) # Set pin's mode is output113 GPIO.setup(IN2, GPIO.OUT)114 GPIO.setup(IN3, GPIO.OUT)115 GPIO.setup(IN4, GPIO.OUT)...
step_motor_z.py
Source:step_motor_z.py
...28# uchar phasecw[4] ={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09}; # æ£è½¬ çµæºå¯¼éç¸åº D-C-B-A29# uchar phaseccw[4]={0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08}; # å转 çµæºå¯¼éç¸åº A-B-C-D30# DELAY_NORMAL为æ£å¸¸èå²é´éï¼å¯¹äºæ§å¶åå½æ°ä¸ç´æ¥èµå¼ç»delayï¼è°ç¨å½æ°æ¯è¥éä¿®æ¹å¯ä»¥ä»¥å®åå½¢å¼ç´æ¥å¤å¶ç»delay31DELAY_NORMAL = 332def set_step(w1, w2, w3, w4):33 GPIO.output(IN1, w1)34 GPIO.output(IN2, w2)35 GPIO.output(IN3, w3)36 GPIO.output(IN4, w4)37def stop():38 set_step(0, 0, 0, 0)39 40def forward(steps, delay=DELAY_NORMAL):41 for i in range(0, steps):42 set_step(1, 0, 0, 0)43 wiringpi.delay(delay)44 set_step(1, 1, 0, 0)45 wiringpi.delay(delay)46 set_step(0, 1, 0, 0)47 wiringpi.delay(delay)48 set_step(0, 1, 1, 0)49 wiringpi.delay(delay)50 set_step(0, 0, 1, 0)51 wiringpi.delay(delay)52 set_step(0, 0, 1, 1)53 wiringpi.delay(delay)54 set_step(0, 0, 0, 1)55 wiringpi.delay(delay)56 set_step(1, 0, 0, 1)57 wiringpi.delay(delay)58def forward_4(steps, delay=DELAY_NORMAL):59 # delay为èå²é´éï¼delayMicrosecondsæ¯ä»¥us为åä½ï¼delayæ¯ä»¥ms为åä½60 for i in range(0, steps):61 set_step(0, 1, 1, 0)62 wiringpi.delay(delay)63 set_step(0, 0, 1, 1)64 wiringpi.delay(delay)65 set_step(1, 0, 0, 1)66 wiringpi.delay(delay)67 set_step(1, 1, 0, 0)68 wiringpi.delay(delay)69 70def backward(steps, delay=DELAY_NORMAL):71 for i in range(0, steps):72 set_step(0, 0, 0, 1)73 wiringpi.delay(delay)74 set_step(0, 0, 1, 1)75 wiringpi.delay(delay)76 set_step(0, 0, 1, 0)77 wiringpi.delay(delay)78 set_step(0, 1, 1, 0)79 wiringpi.delay(delay)80 set_step(0, 1, 0, 0)81 wiringpi.delay(delay)82 set_step(1, 1, 0, 0)83 wiringpi.delay(delay)84 set_step(1, 0, 0, 0)85 wiringpi.delay(delay)86 set_step(1, 0, 0, 1)87 wiringpi.delay(delay)88def backward_4(steps, delay=DELAY_NORMAL):89 # delay为èå²é´éï¼delayMicrosecondsæ¯ä»¥us为åä½ï¼delayæ¯ä»¥ms为åä½90 for i in range(0, steps):91 set_step(1, 1, 0, 0)92 wiringpi.delay(delay)93 set_step(1, 0, 0, 1)94 wiringpi.delay(delay)95 set_step(0, 0, 1, 1)96 wiringpi.delay(delay)97 set_step(0, 1, 1, 0)98 wiringpi.delay(delay)99def setup():100 GPIO.setwarnings(False)101 GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location102 GPIO.setup(IN1, GPIO.OUT) # Set pin's mode is output103 GPIO.setup(IN2, GPIO.OUT)104 GPIO.setup(IN3, GPIO.OUT)105 GPIO.setup(IN4, GPIO.OUT)106 107def loop():108 while True:109 print("stop...")110 stop()111 time.sleep(5)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!