コード例 #1
0
ファイル: trajectory_job.cpp プロジェクト: CloPeMa/motoman
bool TrajectoryJob::toJobString(JointTraj & trajectory, char* str_buffer, size_t buffer_size)
{
  bool rtn = false;
  if (0 < buffer_size)
  {

    // Header begin
    // ----------------------------------------------------------------------------
    strcpy(str_buffer, "");
    APPEND_LINE(str_buffer, buffer_size, "/JOB");

    sprintf(this->line_buffer_, "//NAME %s", this->name_);
    APPEND_LINE(str_buffer, buffer_size, this->line_buffer_);

    APPEND_LINE(str_buffer, buffer_size, "//POS");

    sprintf(this->line_buffer_, "///NPOS %d,0,0,0,0,0", trajectory.size());
    APPEND_LINE(str_buffer, buffer_size, this->line_buffer_);

    APPEND_LINE(str_buffer, buffer_size, "///TOOL 0");
    APPEND_LINE(str_buffer, buffer_size, "///POSTYPE PULSE");
    APPEND_LINE(str_buffer, buffer_size, "///PULSE");

    // Point declaration and initialization
    // ----------------------------------------------------------------------------
    JointTrajPt pt;
    JointData rosData;
    float mpRadians[MAX_PULSE_AXES];
    long mpPulses[MAX_PULSE_AXES];

    for(int i = 0; i < trajectory.size(); i++)
    {
      sprintf(this->line_buffer_, "C%05d=", i);
      SAFE_STRCAT(str_buffer, buffer_size, this->line_buffer_);
      trajectory.getPoint(i, pt);
      pt.getJointPosition(rosData);
      
      // Converting to a motoplus joint (i.e. the correct order and units
      toMpJoint(rosData, mpRadians);
      memset(mpPulses, 0, MAX_PULSE_AXES);  // can't convert radian->pulse on PC-side
      LOG_ERROR("Failed to create Job string: Radian->Pulse scaling is not available for PC-side code.");
      return false;

      for(int j = 0; j < MAX_PULSE_AXES; j++)
      {
        // Don't append comma to last position, instead line-feed.
        if (j < (MAX_PULSE_AXES - 1))
        {
          sprintf(this->line_buffer_, "%d,", mpPulses[j]);
          SAFE_STRCAT(str_buffer, buffer_size, this->line_buffer_);
        }
        else
        {
          sprintf(this->line_buffer_, "%d", mpPulses[j]);
          APPEND_LINE(str_buffer, buffer_size, this->line_buffer_);
        }
      }
    }

    // Header end
    // ----------------------------------------------------------------------------
    APPEND_LINE(str_buffer, buffer_size, "//INST");
    APPEND_LINE(str_buffer, buffer_size, "///DATE 1979/10/01 00:00");
    APPEND_LINE(str_buffer, buffer_size, "///ATTR SC,RW");
    APPEND_LINE(str_buffer, buffer_size, "///GROUP1 RB1");

    // Program
    APPEND_LINE(str_buffer, buffer_size, "NOP");
    for(int i = 0; i < trajectory.size(); i++)
    {
      trajectory.getPoint(i, pt);
      sprintf(this->line_buffer_, "MOVJ C%05d VJ=%.2f", i, pt.getVelocity());
      APPEND_LINE(str_buffer, buffer_size, this->line_buffer_);
    }
    APPEND_LINE(str_buffer, buffer_size, "END");

    rtn = true;
  }
  else
  {
    rtn = false;
    LOG_ERROR("Failed to generate job string");
  }

  return rtn;

}
コード例 #2
0
CProcessAnalysis::CProcessAnalysis(
  CDirEntry *pDirEntry, 
  const CVolume *pVolume,
  wxEvtHandler *parent, int nID) :
    CProcess(parent,nID),
    m_psExe(NULL),
    m_pDirEntry(pDirEntry)
{
#define END_LINE sStdin.Append(";\n")

#define APPEND_LINE(name,value) \
  sStdin.Append(name);          \
  sStdin.Append(wxS("="));      \
  sStdin.Append(value);         \
  END_LINE

#define FORMAT_INT(n) \
  s.Printf("%d",n)

#define APPEND_INT(name,n) \
  FORMAT_INT(n);           \
  APPEND_LINE(name,s)


  wxString sStdin;
  wxString s;
  const CParmOsiris *pParm = pDirEntry->GetParmOsiris();
  const ConfigDir *pDir = mainApp::GetConfig();
  
  sStdin.Alloc(4096);
  APPEND_LINE("InputDirectory",pParm->GetInputDirectory());      //  1
  APPEND_LINE("LadderDirectory",pDir->GetExeConfigPath());       //  2
  APPEND_LINE("ReportDirectory",pParm->GetOutputDirectory());    //  3
  APPEND_LINE("MarkerSetName",pParm->GetKitName());              //  4
  APPEND_LINE("LaneStandardName",pParm->GetLsName());            //  5
  APPEND_LINE("CriticalOutputLevel","15");                   //  6
  APPEND_INT("MinSampleRFU",pParm->GetMinRFU_Sample());          //  7
  APPEND_INT("MinLaneStandardRFU",pParm->GetMinRFU_ILS());       //  8
  APPEND_INT("MinLadderRFU",pParm->GetMinRFU_Ladder());          //  9
  APPEND_INT("MinInterlocusRFU",pParm->GetMinRFU_Interlocus());  // 10

  // channel data

  typedef struct 
  {
    const vector<int> *pan;
    const wxChar *ps;
  } CHANNEL_OVERRIDE;
  CHANNEL_OVERRIDE chanInfo[] =
  {
    { &pParm->GetChannelRFU(), wxS("AnalysisThresholdOverride") },
    { &pParm->GetChannelDetection(), wxS("DetectionThresholdOverride") }
  };
  const size_t nOVR = sizeof(chanInfo) / sizeof(chanInfo[0]);
  wxString sName;
  for (size_t ndx = 0; ndx < nOVR; ndx++)
  {
    const vector<int> *pan = chanInfo[ndx].pan;
    const wxChar *ps = chanInfo[ndx].ps;
    vector<int>::const_iterator itr;
    int nChannel;
    for(itr = pan->begin(), nChannel = 1;
        itr != pan->end();
        ++itr, ++nChannel)
    {
      if((*itr) > 0)
      {
        FORMAT_INT(nChannel);
        sName = ps;
        sName.Append(wxS(":"));
        sName.Append(s);
        APPEND_INT(sName,*itr);
      }
    }
  }

  // end channel data

  if(pParm->GetTimeStampSubDir())
  {
    const wxString &s = pDirEntry->GetTimeStamp();
    if(!s.IsEmpty())
    {
      APPEND_LINE("OutputSubdirectory",s);
    }
    else
    {
      wxASSERT_MSG(false,"Time stamp is empty");
    }
  }

  // the following may eventually be moved to CParmOsiris and
  //  CLabSettings::GetMinRFU() if it is added to the user interface

  int nMinLadderInterlocus = pParm->GetMinLadderInterlocusRFU();
//    pVolume->GetLabSettings()->GetThresholds()->GetRFUladder()->GetMinRFUinterlocus();
  int nMinDetection = pParm->GetSampleDetectionThreshold();
//    pVolume->GetLabSettings()->GetThresholds()->GetRFUsample()->GetMinDetection();
  if(nMinLadderInterlocus >= 0)
  {
    APPEND_INT("MinLadderInterlocusRFU",nMinLadderInterlocus);   // 11
  }
  if(nMinDetection >= 0)
  {
    APPEND_INT("SampleDetectionThreshold",nMinDetection);
  }
  s = pParm->GetDataAnalyzed() ? "A" : "R";
  APPEND_LINE("RawDataString",s);  // 11 or 12
  APPEND_LINE("LabSettings",pVolume->GetLabSettingsFileName());
  APPEND_LINE("StandardSettings",pVolume->GetStdSettingsFileName());
  APPEND_LINE("MessageBook",pDir->GetMessageBookFileName());
  const wxString &sOverride(pParm->GetAnalysisOverride());
  if(!sOverride.IsEmpty())
  {
    APPEND_LINE("override",sOverride);
  }

  END_LINE;

#undef APPEND_INT
#undef APPEND_LINE
#undef END_LINE

  //  finished building stdin for analysis program

  wxASSERT_MSG(sizeof(char) == 1,
      "sizeof(char) != 1, "
        "therefore this code needs to be changed");
  
  s = pDir->GetExePath();
  nwxFileUtil::EndWithSeparator(&s);
#ifdef __WXMSW__
  s += "TestAnalysisDirectoryLC.exe";
#else
  s += "TestAnalysisDirectoryLC";
#endif
  m_psExe = strdup(s.utf8_str());

  char *argv[] = { m_psExe, NULL  };
  m_dProgress = 0.0;
  Run(argv);
  wxOutputStream *pOut = GetOutputStream();
  wxASSERT_MSG(pOut != NULL,"Cannot get output stream for process");
  mainApp::LogMessage(sStdin);
  if(pOut != NULL)
  {
    const char *pChar = sStdin.ToUTF8();
    size_t nLen = sStdin.Len();
    size_t n;
    while(nLen > 0)
    {
      n = pOut->Write((void *)pChar,nLen).LastWrite();
      if(n)
      {
        pChar += n;
        nLen -= n;
      }
      else
      {
        nLen = 0;
        Cancel();
      }
    }
  }
}