Difference between revisions of "How the dataport works"

From DIDEAS Wiki
Jump to: navigation, search
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
The PIC makes use of a data structure to communicate both with other microcontrollers (e.g. motor controller, sensor-reading microcontroller like state machine board in the ankle). Therefore, to access data being read from other microcontrollers (sensor data, EMG, etc) you must access the appropriate data structure.  
+
The PIC makes use of a data structure to communicate both with other microcontrollers (e.g. motor controller, sensor-reading microcontroller like state machine board in the ankle). Therefore, to access data being read from other microcontrollers (sensor data, EMG, etc) you must access the appropriate data structure. A data structure is also used to send data over to a computer for plotting and logging. (For this, the computer must have information about the datastructure, stored in a .vlist file - more on this later)
 +
 
 +
== Reading sensor data ==
  
 
An example of a data structure for sending/receiving is defined in dataport.h, and is called USER_DATAPORT_OBJ_T (you'll see "typedef struct PACKED" that starts the definition, followed by USER_DATAPORT_OBJ_T, which is the new name for this datatype). The data structure has a number of members. Some of the members (emg_data, for instance) are for storing sensor data from other microcontrollers, etc.  
 
An example of a data structure for sending/receiving is defined in dataport.h, and is called USER_DATAPORT_OBJ_T (you'll see "typedef struct PACKED" that starts the definition, followed by USER_DATAPORT_OBJ_T, which is the new name for this datatype). The data structure has a number of members. Some of the members (emg_data, for instance) are for storing sensor data from other microcontrollers, etc.  
  
Chris has written code that reads data from other microcontrollers and stores that data (at each timestep) into a memory location. Therefore, to access this memory location (and hence the data stored) you need to create a pointer and store the appropriate memory location to that pointer. Use the line:
+
Chris has written code that reads data from other microcontrollers and stores that data (at each timestep) into a memory location. Therefore, to access this memory location (and hence the data stored) you need to create a pointer of type USER_DATAPORT_OBJ_T* and have your pointer point to the memory location where the sensor data is stored. Example below:
 +
 
 +
- ------ CODE HERE ------------
 +
 
 +
Once you have done this, your pointer now references the data (of type USER_DATAPORT_OBJ_T) that contains sensor information, like emg_data[8].
 +
 
 +
== Sending information to the computer ==
 +
To send data from the PIC to a computer, a datasowever, for the receiving computer to understand the stream of 1's and 0's, there must be a header of sorts to describe the incoming data. This is the vlist. This list must be defined on both the PIC side and computer side as follows:tream is sent (either over wireless radio or physical serial connection).
 +
Just as sensor data was transferred to the main PIC from other micro's using the USER_DATAPORT_OBJ_T structure, this structure is also used to send data to a computer for logging, plotting, etc. However, it is critical that the receiving computer knows what kind of data is being sent from the PIC (otherwise it just sees a string of seemingly random 1's and 0's!). The receiving python script, wifi_fast.py, must therefore have a list of variables that it can expect, and what size (in bits) each variable is. This list is defined in a vlist file.
 +
 
 +
=== Vlists ===
 +
vlist files are located under the "support_scripts" folder under "vlist". When running wifi_fast.py, you tell wifi_fast.py to use a specific .vlist file by typing in the name -----.vlist. Find your vlist file in the directory and you'll see the data types that are defined match those in the USER_DATAPORT_OBJ_T structure in dataport.h.
 +
 
 +
=== Custom variables for the dataport ===
 +
Note, that you can create your own members of the (USER_DATAPORT_OBJ_T) -- from now on referred to as "dataport" structure, but it is crucial that you ALSO MAKE THE SAME MODIFICATIONS IN THE CORRESPONDING .VLIST FILE. Otherwise, the computer won't understand the changes that were made on the PIC's end. Note: the variable names don't need to match, but the datatypes do. (if you don't recognize a datatype in C, look for a typedef - it'll end up being some standard type like int or float)
 +
 
 +
== Reading data in the computer ==
 +
The datastream comes in from the PIC and is processed by either wifi_fast.py (for wireless) or do_serial.py (for wired connection)
 +
 
 +
[[wifi_fast.py]] takes the input data and processes it using the .vlist file you specify. The output of wifi_fast.py is read by plot_float.m in matlab. (also note, if the argument following -f is not xx or XX, that argument is the filename into which the data is saved, as a zipfile.
  
------- LINE HERE ------------
+
== plot_float.m ==
 +
plot_float takes the data from wifi_fast.py as an vector of inputs. Another Matlab script, user_ui.m, allows you to select which elements of this vector are actually plotted. Each element is represented by a number from 1 to the number of variables that are being sent from the PIC. To plot a variable, type in its number in the array at the beginning of user_ui.m
  
to store the  
+
vlist files are located under the "support_scripts" folder under "vlist". When running wifi_fast.py, you tell wifi_fast.py to use a specific .vlist file by typing in the name -----.vlist. Find your vlist file in the directory and you'll see the data types that are defined match those in the USER_DATAPORT_OBJ_T structure in dataport.h.
  
To send data from the PIC to a computer, a datastream is sent (either over wireless radio or physical serial connection). However, for the receiving computer to understand the stream of 1's and 0's, there must be a header of sorts to describe the incoming data. This is the vlist. This list must be defined on both the PIC side and computer side as follows:
+
=== Custom variables for the dataport ===
 +
Note, that you can create your own members of the (USER_DATAPORT_OBJ_T) -- from now on referred to as "dataport" structure, but it is crucial that you ALSO MAKE THE SAME MODIFICATIONS IN THE CORRESPONDING .VLIST FILE. Otherwise, the computer won't understand the changes that were made on the PIC's end.
  
 
== PIC: ==
 
== PIC: ==

Latest revision as of 04:32, 28 October 2010

The PIC makes use of a data structure to communicate both with other microcontrollers (e.g. motor controller, sensor-reading microcontroller like state machine board in the ankle). Therefore, to access data being read from other microcontrollers (sensor data, EMG, etc) you must access the appropriate data structure. A data structure is also used to send data over to a computer for plotting and logging. (For this, the computer must have information about the datastructure, stored in a .vlist file - more on this later)

Reading sensor data

An example of a data structure for sending/receiving is defined in dataport.h, and is called USER_DATAPORT_OBJ_T (you'll see "typedef struct PACKED" that starts the definition, followed by USER_DATAPORT_OBJ_T, which is the new name for this datatype). The data structure has a number of members. Some of the members (emg_data, for instance) are for storing sensor data from other microcontrollers, etc.

Chris has written code that reads data from other microcontrollers and stores that data (at each timestep) into a memory location. Therefore, to access this memory location (and hence the data stored) you need to create a pointer of type USER_DATAPORT_OBJ_T* and have your pointer point to the memory location where the sensor data is stored. Example below:

- ------ CODE HERE ------------

Once you have done this, your pointer now references the data (of type USER_DATAPORT_OBJ_T) that contains sensor information, like emg_data[8].

Sending information to the computer

To send data from the PIC to a computer, a datasowever, for the receiving computer to understand the stream of 1's and 0's, there must be a header of sorts to describe the incoming data. This is the vlist. This list must be defined on both the PIC side and computer side as follows:tream is sent (either over wireless radio or physical serial connection). Just as sensor data was transferred to the main PIC from other micro's using the USER_DATAPORT_OBJ_T structure, this structure is also used to send data to a computer for logging, plotting, etc. However, it is critical that the receiving computer knows what kind of data is being sent from the PIC (otherwise it just sees a string of seemingly random 1's and 0's!). The receiving python script, wifi_fast.py, must therefore have a list of variables that it can expect, and what size (in bits) each variable is. This list is defined in a vlist file.

Vlists

vlist files are located under the "support_scripts" folder under "vlist". When running wifi_fast.py, you tell wifi_fast.py to use a specific .vlist file by typing in the name -----.vlist. Find your vlist file in the directory and you'll see the data types that are defined match those in the USER_DATAPORT_OBJ_T structure in dataport.h.

Custom variables for the dataport

Note, that you can create your own members of the (USER_DATAPORT_OBJ_T) -- from now on referred to as "dataport" structure, but it is crucial that you ALSO MAKE THE SAME MODIFICATIONS IN THE CORRESPONDING .VLIST FILE. Otherwise, the computer won't understand the changes that were made on the PIC's end. Note: the variable names don't need to match, but the datatypes do. (if you don't recognize a datatype in C, look for a typedef - it'll end up being some standard type like int or float)

Reading data in the computer

The datastream comes in from the PIC and is processed by either wifi_fast.py (for wireless) or do_serial.py (for wired connection)

wifi_fast.py takes the input data and processes it using the .vlist file you specify. The output of wifi_fast.py is read by plot_float.m in matlab. (also note, if the argument following -f is not xx or XX, that argument is the filename into which the data is saved, as a zipfile.

plot_float.m

plot_float takes the data from wifi_fast.py as an vector of inputs. Another Matlab script, user_ui.m, allows you to select which elements of this vector are actually plotted. Each element is represented by a number from 1 to the number of variables that are being sent from the PIC. To plot a variable, type in its number in the array at the beginning of user_ui.m

vlist files are located under the "support_scripts" folder under "vlist". When running wifi_fast.py, you tell wifi_fast.py to use a specific .vlist file by typing in the name -----.vlist. Find your vlist file in the directory and you'll see the data types that are defined match those in the USER_DATAPORT_OBJ_T structure in dataport.h.

Custom variables for the dataport

Note, that you can create your own members of the (USER_DATAPORT_OBJ_T) -- from now on referred to as "dataport" structure, but it is crucial that you ALSO MAKE THE SAME MODIFICATIONS IN THE CORRESPONDING .VLIST FILE. Otherwise, the computer won't understand the changes that were made on the PIC's end.

PIC:

  • To send data from the PIC to the PC, the information must be stored in a C structure.


  • If say, you want to send variables a, b, and c to the computer, (where a is an int, b is a float and c is a byte) you'll want to make "room" for them in a structure.


The USER_DATAPORT_OBJ_T structure is defined already, and thanks to Chris,