ME 405 Term Project
Loading...
Searching...
No Matches
test Namespace Reference

Functions

 eff_to_key (eff)
 key_to_eff (key)
 create_run (control_mode, control_val, driving_mode, run_num, size)
 clean_data (df, cols=None, mode='all')
 start_stream_handshake (ser, timeout=2.0, retries=3)

Variables

str key = ''
bool running = False
bool streaming = False
bool print_stream_frames = True
bool stream_expected = True
bool first_frame = True
dict runs = {}
int run_count = 0
str frame_buffer = ""
int control_mode = 0
int driving_mode = 0
int effort = 0
int setpoint = 0
float kp = 0.0
float ki = 0.0
float k_line = 0.0
bool first = True
bool done = False
 queue = local_queue.Queue()
bool queuing = False
bool creating_run = False
str test_origin = "manual"
dict control_mode_dict = {0: "effort", 1: "velocity", 2: "line following"}
dict driving_mode_dict = {0: "straight", 1: "pivot", 2: "arc"}
str user_prompt
int GEAR_RATIO = 3952/33
int CPR_MOTOR = 12
int CPR_WHEEL = GEAR_RATIO*CPR_MOTOR
int RAD_PER_COUNT = 2 * math.pi / CPR_WHEEL
int WHEEL_RADIUS_MM = 35
 exist_ok
 ser = Serial('COM3', baudrate=115200, timeout=1)
 selected = input("Enter choice (e, v, l, or q to quit): ")
 key_in = input("Enter effort key (0-9 or 'a' for 100%) or percent (0-100): ").strip()
 eff_val = key_to_eff(key_in)
str line = 'e' + eff_to_key(effort)
 gains = input("Enter setpoint (mm/s), Kp, and Ki separated by a comma (e.g., 40,1.5,0.1): ")
 sp_str
 kp_str
 ki_str
 setpoint_mm_s = float(sp_str)
int setpoint_rad_s = setpoint_mm_s / WHEEL_RADIUS_MM
 setpoint_scaled = int(setpoint_rad_s * 100)
 kp_scaled = int(kp * 100)
 ki_scaled = int(ki * 100)
 k_line_str
 target_str
 target_scaled = int(setpoint_rad_s * 100)
 k_line_scaled = int(k_line * 100)
 eff = input("Enter effort test in the following format: start, end, step (e.g., 0,100,10): ")
 start_str
 end_str
 step_str
 start = int(start_str)
 end = int(end_str)
 step = int(step_str)
 csv_dir = os.path.join('runs', 'csvs')
 plots_dir = os.path.join('runs', 'plots')
 df1 = meta.get('motor_data')
 df2 = meta.get('obsv_data', None)
 df = pd.concat([df1, df2], axis=1)
str run_code = 'E'
str driving_code = "STR"
str base_name = f"{run_name}_{run_code}_{driving_code}"
 csv_name = os.path.join(csv_dir, base_name + ".csv")
list cols = ["_time", "_left_pos", "_right_pos", "_left_vel", "_right_vel", "_obsv_time", "_obsv_left_vel", "_obsv_right_vel", "_obsv_s", "_obsv_yaw"]
 index
 next_test = queue.dequeue()
 mode = next_test[0]
str mode_name = "effort"
 params = None
int sample_size = 200
str run_name = f'run{run_count}'
 chunk = ser.read(ser.in_waiting or 1).decode()
str frame = frame_buffer[start+3 : end]
 idx_str
 time_s
 left_pos
 right_pos
 left_vel
 right_vel
 idx = int(idx_str)

Detailed Description

@file main.py
@brief Script to run on PC to interface with Romi robot over Bluetooth serial.

Sends commands to Romi to run tests in different control modes (effort, velocity, line following), toggles data streaming, and saves received data to CSV files with optional plotting.

Function Documentation

◆ clean_data()

test.clean_data ( df,
cols = None,
mode = 'all' )
Clean DataFrame by removing all zero rows except initial zeros up to the first non-zero data.

Parameters:
  df: pandas.DataFrame
  cols: list of columns to check. If None, defaults to all motor_data columns.
  mode: 'all' -> remove rows where ALL specified cols are zero;
        'any' -> remove rows where ANY specified cols are zero.

Returns: (cleaned_df, removed_count)

◆ create_run()

test.create_run ( control_mode,
control_val,
driving_mode,
run_num,
size )

◆ eff_to_key()

test.eff_to_key ( eff)

◆ key_to_eff()

test.key_to_eff ( key)

◆ start_stream_handshake()

test.start_stream_handshake ( ser,
timeout = 2.0,
retries = 3 )
Send START and wait for ACK from MCU. Returns True if ACK received.

Variable Documentation

◆ base_name

str test.base_name = f"{run_name}_{run_code}_{driving_code}"

◆ chunk

test.chunk = ser.read(ser.in_waiting or 1).decode()

◆ cols

list test.cols = ["_time", "_left_pos", "_right_pos", "_left_vel", "_right_vel", "_obsv_time", "_obsv_left_vel", "_obsv_right_vel", "_obsv_s", "_obsv_yaw"]

◆ control_mode

int test.control_mode = 0

◆ control_mode_dict

dict test.control_mode_dict = {0: "effort", 1: "velocity", 2: "line following"}

◆ CPR_MOTOR

int test.CPR_MOTOR = 12

◆ CPR_WHEEL

int test.CPR_WHEEL = GEAR_RATIO*CPR_MOTOR

◆ creating_run

bool test.creating_run = False

◆ csv_dir

test.csv_dir = os.path.join('runs', 'csvs')

◆ csv_name

test.csv_name = os.path.join(csv_dir, base_name + ".csv")

◆ df

dict test.df = pd.concat([df1, df2], axis=1)

◆ df1

test.df1 = meta.get('motor_data')

◆ df2

test.df2 = meta.get('obsv_data', None)

◆ done

bool test.done = False

◆ driving_code

str test.driving_code = "STR"

◆ driving_mode

tuple test.driving_mode = 0

◆ driving_mode_dict

dict test.driving_mode_dict = {0: "straight", 1: "pivot", 2: "arc"}

◆ eff

test.eff = input("Enter effort test in the following format: start, end, step (e.g., 0,100,10): ")

◆ eff_val

test.eff_val = key_to_eff(key_in)

◆ effort

test.effort = 0

◆ end

str test.end = int(end_str)

◆ end_str

test.end_str

◆ exist_ok

test.exist_ok

◆ first

bool test.first = True

◆ first_frame

bool test.first_frame = True

◆ frame

str test.frame = frame_buffer[start+3 : end]

◆ frame_buffer

str test.frame_buffer = ""

◆ gains

test.gains = input("Enter setpoint (mm/s), Kp, and Ki separated by a comma (e.g., 40,1.5,0.1): ")

◆ GEAR_RATIO

int test.GEAR_RATIO = 3952/33

◆ idx

test.idx = int(idx_str)

◆ idx_str

test.idx_str

◆ index

test.index

◆ k_line

test.k_line = 0.0

◆ k_line_scaled

test.k_line_scaled = int(k_line * 100)

◆ k_line_str

test.k_line_str

◆ key

test.key = ''

◆ key_in

test.key_in = input("Enter effort key (0-9 or 'a' for 100%) or percent (0-100): ").strip()

◆ ki

test.ki = 0.0

◆ ki_scaled

test.ki_scaled = int(ki * 100)

◆ ki_str

test.ki_str

◆ kp

test.kp = 0.0

◆ kp_scaled

test.kp_scaled = int(kp * 100)

◆ kp_str

test.kp_str

◆ left_pos

test.left_pos

◆ left_vel

test.left_vel

◆ line

str test.line = 'e' + eff_to_key(effort)

◆ mode

test.mode = next_test[0]

◆ mode_name

str test.mode_name = "effort"

◆ next_test

test.next_test = queue.dequeue()

◆ params

dict test.params = None

◆ plots_dir

test.plots_dir = os.path.join('runs', 'plots')

◆ print_stream_frames

bool test.print_stream_frames = True

◆ queue

test.queue = local_queue.Queue()

◆ queuing

bool test.queuing = False

◆ RAD_PER_COUNT

int test.RAD_PER_COUNT = 2 * math.pi / CPR_WHEEL

◆ right_pos

test.right_pos

◆ right_vel

test.right_vel

◆ run_code

str test.run_code = 'E'

◆ run_count

int test.run_count = 0

◆ run_name

str test.run_name = f'run{run_count}'

◆ running

bool test.running = False

◆ runs

dict test.runs = {}

◆ sample_size

int test.sample_size = 200

◆ selected

test.selected = input("Enter choice (e, v, l, or q to quit): ")

◆ ser

test.ser = Serial('COM3', baudrate=115200, timeout=1)

◆ setpoint

test.setpoint = 0

◆ setpoint_mm_s

test.setpoint_mm_s = float(sp_str)

◆ setpoint_rad_s

int test.setpoint_rad_s = setpoint_mm_s / WHEEL_RADIUS_MM

◆ setpoint_scaled

test.setpoint_scaled = int(setpoint_rad_s * 100)

◆ sp_str

test.sp_str

◆ start

str test.start = int(start_str)

◆ start_str

test.start_str

◆ step

test.step = int(step_str)

◆ step_str

test.step_str

◆ stream_expected

bool test.stream_expected = True

◆ streaming

bool test.streaming = False

◆ target_scaled

test.target_scaled = int(setpoint_rad_s * 100)

◆ target_str

test.target_str

◆ test_origin

str test.test_origin = "manual"

◆ time_s

test.time_s

◆ user_prompt

str test.user_prompt
Initial value:
1= '''\r\nCommand keys:
2 t : Select a test to run: Effort, Velocity, Line Following
3 u : Queue tests
4 r : Run test
5 k : Kill (stop) motors
6 s : Toggle live data streaming ON/OFF
7 p : Toggle printing of streamed data frames
8 d : Save complete data to CSV and optionally create plots
9 b : Check battery voltage (prints to this terminal)
10 c : Calibrate sensors: IR sensors or IMU
11 h : Help / show this menu
12 ctrl-c : Interrupt this program
13'''

◆ WHEEL_RADIUS_MM

int test.WHEEL_RADIUS_MM = 35