Example #1
0
void seissol::writer::ReceiverWriter::addPoints(  std::vector<glm::dvec3> const&    points,
                                                  MeshReader const&                 mesh,
                                                  seissol::initializers::Lut const& ltsLut,
                                                  seissol::initializers::LTS const& lts,
                                                  GlobalData const*                 global ) {
  int rank = seissol::MPI::mpi.rank();
  unsigned numberOfPoints = points.size();
  std::vector<short> contained(numberOfPoints);
  std::vector<unsigned> meshIds(numberOfPoints);
  
  /// \todo Find a nicer solution that is not so hard-coded.
  std::vector<unsigned> quantities{0, 1, 2, 3, 4, 5, 6, 7, 8};

  logInfo(rank) << "Finding meshIds for receivers...";
  initializers::findMeshIds(points.data(), mesh, numberOfPoints, contained.data(), meshIds.data());
#ifdef USE_MPI
  logInfo(rank) << "Cleaning possible double occurring receivers for MPI...";
  initializers::cleanDoubles(contained.data(), numberOfPoints);
#endif

  logInfo(rank) << "Mapping receivers to LTS cells...";
  for (unsigned point = 0; point < numberOfPoints; ++point) {
    if (contained[point] == 1) {
      unsigned meshId = meshIds[point];
      unsigned cluster = ltsLut.cluster(meshId);

      for (unsigned c = m_receiverClusters.size(); c <= cluster; ++c) {
        m_receiverClusters.emplace_back(global, quantities, m_samplingInterval, syncInterval());
      }

      writeHeader(point, points[point]);
      m_receiverClusters[cluster].addReceiver(meshId, point, points[point], mesh, ltsLut, lts);
    }
  }
}
int main(int argc, char *argv[]) {
  if (argc != 4) {
    std::cout
      << "Arguments:" << std::endl
      << "(1) CAN deviceID" << std::endl
      << "(2) SYNC interval in milliseconds" << std::endl
      << "(3) positive (right) or negative (left) speed factor" << std::endl
      << "Example: ./interactiveHoming 12 10 1" << std::endl;
    return -1;
  }
  uint16_t deviceID = std::stoi(std::string(argv[1]));
  std::chrono::milliseconds syncInterval(std::stoi(std::string(argv[2])));
  int speedFactor = std::stoi(std::string(argv[3]));

  // initialize CAN device driver:
  if (!canopen::openConnection("/dev/pcan32")) {
    std::cout << "Cannot open CAN device; aborting." << std::endl;
    return -1;
  } 

  canopen::initListenerThread();    
  canopen::initNMT();
  canopen::setSyncInterval(deviceID, syncInterval);
  canopen::setMotorState(deviceID, "operation_enable");
  canopen::interactiveHoming(deviceID, speedFactor, syncInterval);

  return 0;
}
int main(int argc, char *argv[]) {

  if (argc != 4) {
    std::cout
      << "Arguments:" 
      << "(1) CAN deviceID" << std::endl
      << "(2) SYNC interval in milliseconds" << std::endl
      << "(3) positive (right) or negative (left) speed factor" << std::endl
      << "Example: ./move_single_device 12 10 1" << std::endl;
    return -1;
  }
  uint16_t deviceID = std::stoi(std::string(argv[1]));
  std::chrono::milliseconds syncInterval(std::stoi(std::string(argv[2])));
  int speedFactor = std::stoi(std::string(argv[3]));

  // initialize CAN device driver:
  if (!canopen::openConnection("/dev/pcan32")) {
    std::cout << "Cannot open CAN device; aborting." << std::endl;
    return -1;
  } 

  canopen::initListenerThread();    
  canopen::initNMT();
  canopen::setSyncInterval(deviceID, syncInterval);
  canopen::setMotorState(deviceID, "operation_enable");

  std::cout << "Drive referenced? " << canopen::getStatus(deviceID, "drive_referenced") << std::endl;
  double pos = fmod(canopen::getPos(deviceID), M_PI);
    std::cout << "Current position: " << pos << std::endl;

  bool ended = false;
  std::thread keyThread([&]() { 
      std::string tt; 
      while (!ended) {
	std::getline(std::cin, tt);
	if (tt=="q") 
	  ended = true;
	else if (tt=="+") {
	  speedFactor += 1;
	  std::cout << "Speed factor: " << speedFactor << std::endl;
	} else if (tt=="-") {
	  speedFactor -= 1;
	  std::cout << "Speed factor: " << speedFactor << std::endl;
	} 
      }
    });
  keyThread.detach();

  canopen::driveMode(deviceID, "interpolated_position_mode");
  while (!ended) {
    canopen::sendSync(syncInterval);
    if (speedFactor != 0) {
      canopen::sendPos(deviceID, pos);
      pos +=  (0.05 * M_PI / 3600.0) * ((double) speedFactor);
    }
  }
   
  canopen::setMotorState(deviceID, "ready_to_switch_on");
  canopen::closeConnection();
  return 0;
}