ReboundRumble/DashboardDataFormat.cpp
author andrew
Sun Apr 01 21:03:49 2012 -0700 (2012-04-01)
changeset 207 8139457abeed
parent 165 e0f680599ef6
child 215 5ef7a9025e19
permissions -rw-r--r--
debugging guide lights - also fixed no shooter jags option. Works well on single target, not well on multiple targets
     1 #include "DashboardDataFormat.h"
     2 #include "RobotInfo.h"
     3 
     4 DashboardDataFormat::DashboardDataFormat(void)
     5 {
     6     analogModule1 = AnalogModule::GetInstance(1);
     7     analogModule2 = AnalogModule::GetInstance(2);
     8     digitalModule1 = DigitalModule::GetInstance(1);
     9     digitalModule2 = DigitalModule::GetInstance(2);
    10 }
    11 
    12 DashboardDataFormat::~DashboardDataFormat()
    13 {
    14 }
    15 
    16 void DashboardDataFormat::SendVisionData(
    17         vector<ParticleAnalysisReport> *particles,
    18         UINT8 currIdx)
    19 {
    20     Dashboard &dash =
    21             DriverStation::GetInstance()->GetHighPriorityDashboardPacker();
    22     //
    23     // Vision target Info.
    24     //
    25     dash.AddCluster();                  //Begin: Target Info
    26     {
    27         int targetsSent = 0;
    28         //
    29         // Loop through all particles, but stop after you send 4
    30         //
    31         for (unsigned i = 0; i < particles->size() && targetsSent < 4; i++)
    32         {
    33             ParticleAnalysisReport *p = &(particles->at(i));
    34             float aspectRatio = p->boundingRect.width/
    35                                 p->boundingRect.height;
    36 
    37             if (aspectRatio >= MINIMUM_TARGET_ASPECT_RATIO && 
    38                 aspectRatio <= MAXIMUM_TARGET_ASPECT_RATIO)
    39             {
    40                 targetsSent++;
    41                 dash.AddCluster();      //  Begin: Target Rect
    42                 {
    43                     //
    44                     // The dashboard will select color based on this bool
    45                     //
    46                     dash.AddBoolean(i == currIdx);  
    47                     dash.AddU16(p->boundingRect.left);
    48                     dash.AddU16(p->boundingRect.top);
    49                     dash.AddU16(p->boundingRect.left +
    50                                 p->boundingRect.width);
    51                     dash.AddU16(p->boundingRect.top +
    52                                 p->boundingRect.height);
    53                 }
    54                 dash.FinalizeCluster(); //  End: Target Rect
    55             }
    56         }
    57         
    58         //
    59         // If we have less than 4 targets, we need to send null info for
    60         // the rest.
    61         //
    62         while (targetsSent < 4)
    63         {
    64             targetsSent++;
    65             dash.AddCluster();          //  Begin: Target Rect
    66             {
    67                 dash.AddU16(0);
    68                 dash.AddU16(0);
    69                 dash.AddU16(0);
    70                 dash.AddU16(0);
    71                 dash.AddBoolean(false);
    72             }
    73             dash.FinalizeCluster();     //  End: Target Rect
    74         }
    75     }
    76     dash.FinalizeCluster();             //End: Target Info
    77     dash.Finalize();
    78 }
    79 
    80 void DashboardDataFormat::SendIOPortData()
    81 {
    82     Dashboard &dash =
    83             DriverStation::GetInstance()->GetLowPriorityDashboardPacker();
    84     dash.AddCluster();
    85     {
    86         dash.AddCluster();
    87         { //analog modules 
    88             dash.AddCluster();
    89             {
    90                 if (analogModule1 != NULL)
    91                 {
    92                     for (int i = 1; i <= 8; i++)
    93                     {
    94                         dash.AddFloat(
    95                                 (float) analogModule1->GetAverageVoltage(i));
    96                     }
    97                 }
    98                 else
    99                 {
   100                     for (int i = 1; i <= 8; i++)
   101                     {
   102                         dash.AddFloat(0.0);
   103                     }
   104                 }
   105             }
   106             dash.FinalizeCluster();
   107             dash.AddCluster();
   108             {
   109                 if (analogModule2 != NULL)
   110                 {
   111                     for (int i = 1; i <= 8; i++)
   112                     {
   113                         dash.AddFloat(
   114                                 (float) analogModule2->GetAverageVoltage(i));
   115                     }
   116                 }
   117                 else
   118                 {
   119                     for (int i = 1; i <= 8; i++)
   120                     {
   121                         dash.AddFloat(0.0);
   122                     }
   123                 }
   124             }
   125             dash.FinalizeCluster();
   126         }
   127         dash.FinalizeCluster();
   128 
   129         dash.AddCluster();
   130         { //digital modules
   131             dash.AddCluster();
   132             {
   133                 if (digitalModule1 != NULL)
   134                 {
   135                     dash.AddU8(digitalModule1->GetRelayForward());
   136                     dash.AddU8(digitalModule1->GetRelayReverse());
   137                     dash.AddU16((short) digitalModule1->GetDIO());
   138                     dash.AddU16((short) digitalModule1->GetDIODirection());
   139                     dash.AddCluster();
   140                     {
   141                         for (int i = 1; i <= 10; i++)
   142                         {
   143                             dash.AddU8(
   144                                     (unsigned char) digitalModule1->GetPWM(
   145                                             i));
   146                         }
   147                     }
   148                     dash.FinalizeCluster();
   149                 }
   150                 else
   151                 {
   152                     dash.AddU8(0);
   153                     dash.AddU8(0);
   154                     dash.AddU16(0);
   155                     dash.AddU16(0);
   156                     dash.AddCluster();
   157                     {
   158                         for (int i = 1; i <= 10; i++)
   159                             dash.AddU8(0);
   160                     }
   161                     dash.FinalizeCluster();
   162                 }
   163             }
   164             dash.FinalizeCluster();
   165 
   166             dash.AddCluster();
   167             {
   168                 if (digitalModule2 != NULL)
   169                 {
   170                     dash.AddU8(digitalModule2->GetRelayForward());
   171                     dash.AddU8(digitalModule2->GetRelayForward());
   172                     dash.AddU16((short) digitalModule2->GetDIO());
   173                     dash.AddU16(digitalModule2->GetDIODirection());
   174                     dash.AddCluster();
   175                     {
   176                         for (int i = 1; i <= 10; i++)
   177                         {
   178                             dash.AddU8(
   179                                     (unsigned char) digitalModule2->GetPWM(
   180                                             i));
   181                         }
   182                     }
   183                     dash.FinalizeCluster();
   184                 }
   185                 else
   186                 {
   187                     dash.AddU8(0);
   188                     dash.AddU8(0);
   189                     dash.AddU16(0);
   190                     dash.AddU16(0);
   191                     dash.AddCluster();
   192                     {
   193                         for (int i = 1; i <= 10; i++)
   194                             dash.AddU8(0);
   195                     }
   196                     dash.FinalizeCluster();
   197                 }
   198             }
   199             dash.FinalizeCluster();
   200         }
   201         dash.FinalizeCluster();
   202 
   203         // Can't read solenoids without an instance of the object
   204         dash.AddU8((char) 0);
   205     }
   206     dash.FinalizeCluster();
   207     dash.Finalize();
   208 }