diff --git a/sdk/master_board_sdk/example/com_analyser.py b/sdk/master_board_sdk/example/com_analyser.py index 1eefca5c..99079eab 100644 --- a/sdk/master_board_sdk/example/com_analyser.py +++ b/sdk/master_board_sdk/example/com_analyser.py @@ -6,9 +6,11 @@ import time import subprocess try: - from time import process_time + from time import perf_counter except(ImportError): - from time import clock as process_time + # You are still in python2… pleas upgrade :) + from time import clock as perf_counter + import libmaster_board_sdk_pywrap as mbs import matplotlib.pyplot as plt @@ -72,12 +74,12 @@ def example_script(name_interface): robot_if.GetDriver(i).SetTimeout(5) robot_if.GetDriver(i).Enable() - last = process_time() + last = perf_counter() prev_time = 0 while (not robot_if.IsTimeout() and not robot_if.IsAckMsgReceived()): - if ((process_time() - last) > dt): - last = process_time() + if ((perf_counter() - last) > dt): + last = perf_counter() robot_if.SendInit() if robot_if.IsTimeout(): @@ -97,7 +99,7 @@ def example_script(name_interface): last_cmd_packet_index = first_cmd_index while ((not robot_if.IsTimeout()) - and (process_time() < duration)): # Stop after 15 seconds (around 5 seconds are used at the start for calibration) + and (perf_counter() < duration)): # Stop after 15 seconds (around 5 seconds are used at the start for calibration) if (robot_if.GetLastRecvCmdIndex() > robot_if.GetCmdPacketIndex()): last_recv_cmd_index = (overflow_cmd_cpt-1) * 65536 + robot_if.GetLastRecvCmdIndex() @@ -105,9 +107,9 @@ def example_script(name_interface): last_recv_cmd_index = overflow_cmd_cpt * 65536 + robot_if.GetLastRecvCmdIndex() if (last_recv_cmd_index >= first_cmd_index and received_list[last_recv_cmd_index-first_cmd_index] == 0): - received_list[last_recv_cmd_index-first_cmd_index] = process_time() + received_list[last_recv_cmd_index-first_cmd_index] = perf_counter() - if ((process_time() - last) > dt): + if ((perf_counter() - last) > dt): last += dt cpt += 1 @@ -144,9 +146,9 @@ def example_script(name_interface): sensor_lost_list.append(robot_if.GetSensorsLost()) cmd_ratio_list.append(100.*robot_if.GetCmdLost()/robot_if.GetCmdSent()) sensor_ratio_list.append(100.*robot_if.GetSensorsLost()/robot_if.GetSensorsSent()) - time_list.append(process_time()) + time_list.append(perf_counter()) - current_time = process_time() + current_time = perf_counter() diff = robot_if.GetCmdPacketIndex() - last_cmd_packet_index if diff < 0: diff --git a/sdk/master_board_sdk/example/example.py b/sdk/master_board_sdk/example/example.py index 8b03d244..d8dac120 100644 --- a/sdk/master_board_sdk/example/example.py +++ b/sdk/master_board_sdk/example/example.py @@ -4,7 +4,11 @@ import math import os import sys -from time import perf_counter +try: + from time import perf_counter +except ImportError: + # You are still in python2… pleas upgrade :) + from time import clock as perf_counter import libmaster_board_sdk_pywrap as mbs @@ -53,9 +57,8 @@ def example_script(name_interface): robot_if.GetDriver(i).SetTimeout(5) robot_if.GetDriver(i).Enable() - start = perf_counter() - last = start - + last = perf_counter() + print("last =",last) while (not robot_if.IsTimeout() and not robot_if.IsAckMsgReceived()): if ((perf_counter() - last) > dt): last = perf_counter() @@ -71,10 +74,11 @@ def example_script(name_interface): # if slave i is connected then motors 2i and 2i+1 are potentially connected motors_spi_connected_indexes.append(2 * i) motors_spi_connected_indexes.append(2 * i + 1) + glob_last = perf_counter() # Stop after 15 seconds (around 5 seconds are used at the start for calibration) while ((not robot_if.IsTimeout()) - and (perf_counter() - start < 20)): + and ( (perf_counter() - glob_last) < 20)): # Stop after 15 seconds (around 5 seconds are used at the start for calibration) if ((perf_counter() - last) > dt): last = perf_counter() @@ -102,6 +106,7 @@ def example_script(name_interface): continue #user should decide what to do in that case, here we ignore that motor if robot_if.GetMotor(i).IsEnabled(): + print("sending ",i," motor settings.") ref = init_pos[i] + amplitude * math.sin(2.0 * math.pi * freq * t) # Sine wave pattern v_ref = 2.0 * math.pi * freq * amplitude * math.cos(2.0 * math.pi * freq * t) p_err = ref - robot_if.GetMotor(i).GetPosition() # Position error diff --git a/sdk/master_board_sdk/example/listener.py b/sdk/master_board_sdk/example/listener.py index 2c9868e8..67d44da2 100644 --- a/sdk/master_board_sdk/example/listener.py +++ b/sdk/master_board_sdk/example/listener.py @@ -5,9 +5,10 @@ import os import sys try: - from time import process_time -except(ImportError): - from time import clock as process_time + from time import perf_counter +except ImportError: + # You are still in python2… pleas upgrade :) + from time import clock as perf_counter import libmaster_board_sdk_pywrap as mbs @@ -24,12 +25,12 @@ def listener_script(name_interface): robot_if = mbs.MasterBoardInterface(name_interface, True) robot_if.Init() # Initialization of the interface between the computer and the master board - last = process_time() + last = perf_counter() while (True): - if ((process_time() - last) > dt): - last = process_time() + if ((perf_counter() - last) > dt): + last = perf_counter() cpt += 1 t += dt robot_if.ParseSensorData() # Read sensor data sent by the masterboard