GTMAX Final Exam FAQ
How to add variables to the GTMAX Link component
Note the procedure explained below is not supported. It is purely there so that if there are variables in the simulation that you need but are not yet a part of the GTMaxlink you may add them and verify your simulation needs, before making a request to Georgia Tech to make them a part of the official release of the GTMaxlink OCP component.
Two steps need to be undertaken
- Add the variables to the gtmax simulation environment so that the raw UDP data packet is sent to the second computer
- Add the variables to the GTMaxState data structure and add appropriate code to the GTMaxlink OCP component to read them
Adding the variables to the GTMax simulation
- open rmax/datalink.dbh
- find the following data structure declaration and add your elements. Add your variables and call it appropriately for example, if adding signals that send back the actuator commands that are fed to the vehicle use onboard/actuators/work
%Dir datalinkMessageIPC0_ref {
uchar sync1 = 0xa1 : ;
uchar sync2 = 0xb0 : ;
uchar sync3 = 0xca : ;
uchar hcsum = 0 : ;
uchar csum = 0 : ;
int messageID = 0 :id #;
int messageSize = 0 :including header;
char navStatus = 0 :status of nav system;
char gpsStatus = 0 :status of gps;
char sonarStatus = 0 :status of sonar;
char radarStatus = 0 :status of radar;
char magnetStatus = 0 :status of magnetometer;
char overrun = 0 :frame overrun;
char wow = 0 :weight on skids;
char autopilot = 0 :autopilot engaged;
char lavoid = 0 :limit avoidance;
int k = 0 : discrete time onboard;
float time = 0 :onboard time;
int kdelay = 0 : discrete time delay;
float timedelay = 0 : time delay;
float pos[3] = {0,0,50} :position of vehicle;
float vel[3] = {0,0,0} :velocity of vehicle;
float q[4] = {0,0,0,0} :attitude;
float w[3] = {0,0,0} :vehicle angular rate;
float altitudeAGL = 0 :altitude above terrain;
float rpm = 0 :main rotor rpm;
float delfhat[1] = {0} :estimate of collective position;
float delm[3] = {0,0,0} : actuator command when the state is measured;
float delf[1] = {0} : actuator command when the state is measured;
float adelm[3] = {0,0,0} : moment actuator commands going to vehicle
float adelf[1] = {0} : force actuator commands going to vehicle
};
- open rmax/datalink.cpp and find the function
void updateDatalink( struct onboard_ref *ob )
- find the section of code that populates the ipc0 structure it starts with
if( data->set->sendIPC0 ) if( nav->out->time >=
data->work->lastUpdateIPC0 + data->set->updateDtIPC0 ) {
.....
- insert your code perhaps as follows
for( i=0; i<4; i++ ) {
data->ipc0->q[i] = (float)nav->out->q[i];
}
data->ipc0->rpm = (float)(sen->ycs->out->rpm);
data->ipc0->altitudeAGL = (float)nav->out->altitudeAGL;
data->ipc0->wow = nav->out->wow;
data->ipc0->autopilot = con->work->mode;
data->ipc0->lavoid = ob->trajectory->work->lavoidStatus;
data->ipc0->delfhat[0] = (float)ob->control->ol->delhat[0];
data->ipc0->adelm[0] = (float)ob->actuators->work->delm[0];
data->ipc0->adelm[1] = (float)ob->actuators->work->delm[1];
data->ipc0->adelm[2] = (float)ob->actuators->work->delm[2];
data->ipc0->adelf[0] = (float)ob->actuators->work->delf[0];
This will copy over the actuator commands being send to the helicopter into the data packet being sent to the second computer. On the second computer the data is mem copied in to the structure so one does not have to explicitly decipher each variable.
Now test that you are getting the data correctly in the second computer by cleaning and rebuilding the simulation (rebuild all must be done to process the new dbh file).
- Run the simulation, navigate to onboard/datalink/set and set the sendIPC0 flag to 1 to start sending the ipc0 packet.
- Navigation to onboard2/datalink/ipc0 and verify that you are getting the data correctly and must match the numbers in onboard/actuators/work.
NOTE : the ipc0 packet size is limited to 500 bytes. so what ever variables you add, the total packet size should be no more than 500 bytes.
This concludes the part where the new variables have been added to the gtmax simulation.
Editing the GTMAX Link
In the componentinfo.txt file find the GtmaxState structure definition and add the following
Signal GtmaxState
Data
char navStatus
char gpsStatus
char sonarStatus
char radarStatus
char magnetStatus
char overrun
char wow
char autopilot
char lavoid
double time
double x
double y
double z
double vx
double vy
double vz
double q1
double q2
double q3
double q4
double p
double q
double r
double rpm
double altitudeAGL
double adelm1
double adelm2
double adelm3
double adelf
In the GtmaxLink.cpp file find the GtmaxLink::SendStateOut method modify the coherent set function call to
sigGtmaxState->CoherentSet(ipc0->navStatus, ipc0->gpsStatus, ipc0->sonarStatus, ipc0->radarStatus, ipc0->magnetStatus,
ipc0->overrun, ipc0->wow, ipc0->autopilot, ipc0->lavoid, ipc0->time,ipc0->pos[0],ipc0->pos[1],ipc0->pos[2],
ipc0->vel[0],ipc0->vel[1],ipc0->vel[2], ipc0->q[0], ipc0->q[1], ipc0->q[2], ipc0->q[3], ipc0->w[0], ipc0->w[1], ipc0->w[2],
ipc0->rpm, ipc0->altitudeAGL,ipc0->adelm[0],ipc0->adelm[1],ipc0->adelm[2],ipc0->adelf[0]);
This concludes the modifications you need to make to the GtmaxLink component. Regenerate your ocp workspace and the commands (normalized) that are being sent to the actuators will be available to you.