- BiomechDocs BL Knee PFresearchE
- Biomech Documentation links:
- AKCPU2z BLMD6c BLFT6c PSER1c Imu_2010 Emg_2009 Ric Upd_pcb
wifi_fast.py is the primary utility for receiving real-time telemetry from the target. It makes connection to the target via either a standard RS-232 serial port, or via a TCP connection. Once connected it reads telemetry, can log the data to a file, and can send the data via UDP for real-time plotting. It also sends keyboard characters to the target which are typically used for parameter adjustment. On the SC these characters are read via the C function 'getchar'
- 1 basic command line options
- 2 making a connection to the robot
- 3 matlab support
- 4 vlist
basic command line options
wifi_fast (like most of the robot scripts) is a python 2.7 script that lives in "support_scripts".
- get help with wifi_fast.py -h
The typical command contains 3 or 4 options as show below. wifi_fast.py -f log_file_name -V dataport3d -F -i IP_ADDRESS
- -V option specifies a "Vlist" or variable list that describes the binary format of the telemetry packet. These vlist files live in "support_scripts\vlist". Sometimes matching the vlist to the firmware can be a challenge - as the packet generated by the firmware and that specified by the VLIST two need to be precisely the same length; and the variable types must also match for the data to make sense. If the connection reports "baud rate error", or "crc error" then most likely the packet lengths do not match.
- -f option specifies the base name of the log file.
- As data is received, it converted as specified by the #vlist, and stored in a self documenting .txt file that has a time stamp suffix. Several times an hour a new file will be started and the previous one added to a zip file.
- The zip file often contains a file called "wifiload.m" that can be used with matlab to read the file and create a data structure with named fields. However, there are now easier to use matlab functions for this purpose.
- The "-f xx" file option is a special case that means no-logging.
- -F : this command line option causes wifi_fast to send a command to the SWIFI for it to flush its FIFO. When there is no wifi_fast connection to the SWIFI, this FIFO will fill w/data and when the FIFO overflows (after 1 to 2 mins), the data read the SWIFI will be corrupted until the FIFO is fully emptied. Thus best to always use -F.
- -i, -p : one of these options is required as it specifies how to connect to the target. The -i option specifies an IP address (or resolvable machine name), while the -p option specifies a serial port.
Note: the SWIFI contains a FIFO that can store at least 1min of telemetry sent from the robot. If the wireless connection is poor then the FIFO can cause a significant delay between the actual events and the data that is plot on the PC. If the FIFO has significant data, then take case to confirm that the data from the end of the experimental trial has been received before terminating wififast. Often it is best to have the subject stand still for 5-10 seconds as this will be very evident in the data.
making a connection to the robot
via a wired connection
A wired ASYNC serial connection with the target requires a minimum of 3 wires : GND, Tx, Rx. The signals are 3.3V logical level. Several USB serial port devices called "PSER" have been made for this purpose. When connected to the PC, they will be assigned a "COMM PORT" number. Under windows you can use the "Device manager" to list the serial ports. You can run the command directly with the command "devmgmt"
via a wireless connection
- In lab the access point is :
- user name is "admin"
- password is written on the access point.
- You can also test connectivity with ping bmech4.media.mit.edu
The primary problem connecting to the robot is to determine its IP address and to have a route to the robot via the access points. How this is done depends on how you are connected to the medialab network.
wired or wireless connection to the bmech4 access point
In this case, your PC shares the private subnet connection with the robot. You can make a direct connection to the robot by specifying its full IP address. (Often written on the SWIFI).
Some swifi IPs are: 10.2.0.216 (Ken's test ankle), and 10.2.0.218 (Jing's EMG SWIFI)
The command line run from support_scripts: wifi_fast.py -i 10.2.0.216 -F -f <log_file_name> -V dataport3e
wired connection to the medialab
In this case, a connection is made to the access point (bmech4.media.mit.edu) which then uses address translation (NAT) to route the packet to the robot on the private subnet. The greatest challenge here is configuring the access point.
Once the bmech4 access point is configured, the command line is : wifi_fast.py -i bmech4.media.mit.edu -F -f <log_file_name> -V dataport3e
wireless connection to MIT or medialab
Wireless connections to MIT networks often won't work well with the robot due to packet loss and delays. However, the commands and issues related to robot connection are the same as when using a wired connection.
A number of helpful matlab scripts and functions live in "support_scripts" and "support_scripts\matlab_support". It is helpful add these directories to your matlab path and often best to make the matlab current working directory "support_scrips" with the command "cd". Setting the path can be done from the "File -> Set Path" dialog from the main matlab window.
plot_float : real_time plotting
The command "plot_float.m" is used to listen to a UDP port, and plot the data received on that port. When started, plot_float prompts for a port number (typically 9999) to listen on. Afterward, it runs the script "user_ui.m" and reads the file "auto_ui_9999.txt" for configuration.
Note: for real time plotting to function, matlab must have the Instrumentation Toolbox installed. This can be confirmed by running the command "help udp". If it is unknown - then the toolbox needs to be installed for real-time plotting. Without the toolbox wifi_fast can still be used to collect data, and matlab used to post process the log files. It is allow possible to redirect the UDP packets to a different machine that is able to run plot_float.
compiled real time plotting
plot_float has been compiled. You may DL and install the following: http://web.media.mit.edu/~cbarn/rtplot/rtplot.zip
This is likely deprecated.
This file contains settings that should be user or machine specific.
- The PLOT_ORDER list specifies what data fields to be plot, and in what order.
- PLOT_NUM_X and PLOT_NUM_Y specify the initial number of subplots to use.
- A full example:
PLOT_ORDER = 1:8 PLOT_NUM_X = 4; PLOT_NUM_Y = 2; if ~exist('matlab_listen_port') matlab_listen_port = 9999; else disp( sprintf('Listen port %d', matlab_listen_port)); end SAMPLE_RATE = 500; % sample rate of system feeding the python bridge PLOT_UPDATE_INTERVAL = 1.0; % time interval between updates of the plot window DATA_WINDOW_TIME = 10.0; PLOT_WINDOW_TIME = 10.0; PLOT_SUBSAMPLE = 1; data_type = 'float'; SAMPLES_PER_UDP_PACKET = 10;
The auto_ui_nnnn.txt file is AUTO generated by wifi_fast.py. The nnnn is substituted with the UDP port number. It contains a matlab parse-able version of the .vlist file.
reading SWIFI data files with matlab
- data = wild(file_name_pattern)
- obj = wild_cvt_dirlist(directory_pattern)
off line plotting data and objects
A vlist file (located in support_scripts/vlist) contains a list of: data types, variable names, scaling factors, and offsets
When wifi_fast is started, the vlist file specified by "-V" is read and use to decode the data packet coming from the "SWIFI". wifi_fast also creates a file "auto_ui_9999.txt" - this file is a simplified format of the vlist that is read by the matlab plotting program "plot_float.m"
The standard vlist is :
# type name scale (1 by def) offset (0 by def) int8 sc_state_trans int8 state int16 raw_hall_sensor int16 qIq 1./866. int16 motor_speed int16 ibat 1.0/866. 0 uint16 vbat 30.0/65536 0 int16 motor_state int16 qV 1.0/1093 int32 MC_encoder #SC variables (from here down) float ts_confidence float pff_torque float estimated_torque # Raw IMU Data int16 gyro_idg_x_nAx 2.0 int16 gyro_idg_y_nAz 2.0 int16 gyro_adi_z_pAy 2.0 int16 acc_mot_x_nAz 2.0 int16 acc_mot_y_pAx 2.0 int16 acc_mot_z_nAy 2.0 # IMU Data int16 imuFlags int16 imuTerrainAngle 1.0/100.0 int16 imuZacceleration 1.0/100.0 int16 imuPitch 1.0/100.0 int16 imuWalkVelocity 1.0/100.0 int16 imuVelocityAngle 1.0/100.0 int16 imuPitchVelocity 1.0/100.0 int16 imuAccAngle 1.0/100.0
firmware dataport generation
- in the SC file "dataport.c" there is the statement : switch(sc_dp.dataport_select)
- for each case, there are a number of assignment of robot variables to variables of the form "pf[n]".
- the special command "157" is used to set the value of the variable "sc_dp.dataport_select"
- thus the command "do_command.py -i IP_ADDRESS -s 157 1" sets dataport select to 1.