How the dataport works

From DIDEAS Wiki
Revision as of 22:11, 27 October 2010 by Mike (talk | contribs)
Jump to: navigation, search

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 and store the appropriate memory location to that pointer. Use the line:

- ------ LINE HERE ------------


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:

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,