Esempio n. 1
0
mTecs::mTecs() :
	SuperBlock(NULL, "MT"),
	/* Parameters */
	_mTecsEnabled(this, "ENABLED"),
	_airspeedMin(this, "FW_AIRSPD_MIN", false),
	/* Publications */
	_status(ORB_ID(tecs_status), &getPublications()),
	/* control blocks */
	_controlTotalEnergy(this, "THR"),
	_controlEnergyDistribution(this, "PIT", true),
	_controlAltitude(this, "FPA", true),
	_controlAirSpeed(this, "ACC"),
	_flightPathAngleLowpass(this, "FPA_LP"),
	_altitudeLowpass(this, "ALT_LP"),
	_airspeedLowpass(this, "A_LP"),
	_airspeedDerivative(this, "AD"),
	_throttleSp(0.0f),
	_pitchSp(0.0f),
	_BlockOutputLimiterTakeoffThrottle(this, "TKF_THR"),
	_BlockOutputLimiterTakeoffPitch(this, "TKF_PIT", true),
	_BlockOutputLimiterUnderspeedThrottle(this, "USP_THR"),
	_BlockOutputLimiterUnderspeedPitch(this, "USP_PIT", true),
	_BlockOutputLimiterLandThrottle(this, "LND_THR"),
	_BlockOutputLimiterLandPitch(this, "LND_PIT", true),
	timestampLastIteration(hrt_absolute_time()),
	_firstIterationAfterReset(true),
	_dtCalculated(false),
	_counter(0),
	_debug(false)
{
}
Esempio n. 2
0
int getMostPublications(Game g) {

  int publications = NO_ONE;
  
  if((getPublications(g, UNI_A) > getPublications(g, UNI_B)) && (getPublications(g, UNI_A) > getPublications(g, UNI_C))) {
    publications = UNI_A;
  } else if((getPublications(g, UNI_B) > getPublications(g, UNI_A)) && (getPublications(g, UNI_B) > getPublications(g, UNI_C))) {
    publications = UNI_B;
  } else if((getPublications(g, UNI_C) > getPublications(g, UNI_A)) && (getPublications(g, UNI_C) > getPublications(g, UNI_B))) {
    publications = UNI_C;
  }
  
  return publications;
  }
Esempio n. 3
0
BlockUorbEnabledAutopilot::BlockUorbEnabledAutopilot(SuperBlock *parent, const char *name) :
	SuperBlock(parent, name),
	// subscriptions
	_att(ORB_ID(vehicle_attitude), 20, &getSubscriptions()),
	_attCmd(ORB_ID(vehicle_attitude_setpoint), 20, &getSubscriptions()),
	_ratesCmd(ORB_ID(vehicle_rates_setpoint), 20, &getSubscriptions()),
	_pos(ORB_ID(vehicle_global_position), 20, &getSubscriptions()),
	_missionCmd(ORB_ID(position_setpoint_triplet), 20, &getSubscriptions()),
	_manual(ORB_ID(manual_control_setpoint), 20, &getSubscriptions()),
	_status(ORB_ID(vehicle_status), 20, &getSubscriptions()),
	_param_update(ORB_ID(parameter_update), 1000, &getSubscriptions()), // limit to 1 Hz
	// publications
	_actuators(ORB_ID(actuator_controls_0), &getPublications())
{
}
Esempio n. 4
0
void Block::updatePublications()
{
	UOrbPublicationBase *pub = getPublications().getHead();
	int count = 0;

	while (pub != NULL) {
		if (count++ > maxPublicationsPerBlock) {
			char name[blockNameLengthMax];
			getName(name, blockNameLengthMax);
			printf("exceeded max publications for block: %s\n", name);
			break;
		}

		pub->update();
		pub = pub->getSibling();
	}
}
Esempio n. 5
0
void Block::updatePublications()
{
	uORB::PublicationNode *pub = getPublications().getHead();
	int count = 0;

	while (pub != nullptr) {
		if (count++ > maxPublicationsPerBlock) {
			char name[blockNameLengthMax];
			getName(name, blockNameLengthMax);
			PX4_ERR("exceeded max publications for block: %s", name);
			break;
		}

		pub->update();
		pub = pub->getSibling();
	}
}
Esempio n. 6
0
void printScore (Game g) {
    int player = getWhoseTurn (g);
    printf ("============== YOUR STUFF ==============\n");
    printf ("Students:\n");
    printf ("THD: %d ", getStudents (g, player, STUDENT_THD));
    printf ("BPS: %d ", getStudents (g, player, STUDENT_BPS));
    printf ("BQN: %d ", getStudents (g, player, STUDENT_BQN));
    printf ("MJ: %d ", getStudents (g, player, STUDENT_MJ));
    printf ("MTV: %d ", getStudents (g, player, STUDENT_MTV));
    printf ("M$: %d\n", getStudents (g, player, STUDENT_MMONEY));
    printf ("Your current score:\n");
    printf ("KPI: %d ", getKPIpoints (g, player));
    printf ("Pubs: %d ", getPublications (g, player));
    printf ("IPs: %d\n", getIPs (g, player));
    printf ("Built:\n");
    printf ("ARCs: %d ", getARCs (g, player));
    printf ("Campuses: %d ", getCampuses (g, player));
    printf ("GO8s: %d\n", getGO8s (g, player));
    printf ("========================================\n");
}
Esempio n. 7
0
void testInitialisation (Game testGame){
   
   action testAction;
   
   printf ("Testing initial conditions.\n");
   
   printf ("Testing getDiscipline.\n");
   assert (getDiscipline(testGame, 0) == STUDENT_BQN);
   assert (getDiscipline(testGame, 1) == STUDENT_MMONEY);
   assert (getDiscipline(testGame, 2) == STUDENT_MJ);
   assert (getDiscipline(testGame, 3) == STUDENT_MMONEY);
   assert (getDiscipline(testGame, 4) == STUDENT_MJ);
   assert (getDiscipline(testGame, 5) == STUDENT_BPS);
   assert (getDiscipline(testGame, 6) == STUDENT_MTV);
   assert (getDiscipline(testGame, 7) == STUDENT_MTV);
   assert (getDiscipline(testGame, 8) == STUDENT_BPS);
   assert (getDiscipline(testGame, 9) == STUDENT_MTV);
   assert (getDiscipline(testGame, 10) == STUDENT_BQN);
   assert (getDiscipline(testGame, 11) == STUDENT_MJ);
   assert (getDiscipline(testGame, 12) == STUDENT_BQN);
   assert (getDiscipline(testGame, 13) == STUDENT_THD);
   assert (getDiscipline(testGame, 14) == STUDENT_MJ);
   assert (getDiscipline(testGame, 15) == STUDENT_MMONEY);
   assert (getDiscipline(testGame, 16) == STUDENT_MTV);
   assert (getDiscipline(testGame, 17) == STUDENT_BQN);
   assert (getDiscipline(testGame, 18) == STUDENT_BPS);
   
   printf ("Testing getDiceValue\n");
   assert (getDiceValue(testGame, 0) == 9);
   assert (getDiceValue(testGame, 1) == 10);
   assert (getDiceValue(testGame, 2) == 8);
   assert (getDiceValue(testGame, 3) == 12);
   assert (getDiceValue(testGame, 4) == 6);
   assert (getDiceValue(testGame, 5) == 5);
   assert (getDiceValue(testGame, 6) == 3);
   assert (getDiceValue(testGame, 7) == 11);
   assert (getDiceValue(testGame, 8) == 3);
   assert (getDiceValue(testGame, 9) == 11);
   assert (getDiceValue(testGame, 10) == 4);
   assert (getDiceValue(testGame, 11) == 6);
   assert (getDiceValue(testGame, 12) == 4);
   assert (getDiceValue(testGame, 13) == 7);
   assert (getDiceValue(testGame, 14) == 9);
   assert (getDiceValue(testGame, 15) == 2);
   assert (getDiceValue(testGame, 16) == 8);
   assert (getDiceValue(testGame, 17) == 10);
   assert (getDiceValue(testGame, 18) == 5);
   
   printf ("Testing Most ARC\n");
   assert (getMostARCs(testGame) == NO_ONE);
   
   printf ("Testing most publications\n");
   assert (getMostPublications (testGame) == NO_ONE);
   
   printf ("Testing turnNumber\n");
   assert (getTurnNumber(testGame) == -1);
   
   printf ("Testing whoseTurn.\n");
   assert (getWhoseTurn (testGame) == NO_ONE);

   printf("Testing getCampus (content of given vertex) \n");
   assert (getCampus (testGame, "RLBLR") == VACANT_VERTEX);
   assert (getCampus (testGame, "RLBBR") == VACANT_VERTEX);
   assert (getCampus (testGame, "LRL") == VACANT_VERTEX);
   
   printf("Testing getARC (content of given edge) \n");
   assert (getARC (testGame, "L") == VACANT_ARC);
   assert (getARC (testGame, "R") == VACANT_ARC);
   assert (getARC (testGame, "LR") == VACANT_ARC);
   assert (getARC (testGame, "RR") == VACANT_ARC);
   
   printf ("Testing isLegalAction\n");
   assert (isLegalAction (testGame, testAction) == FALSE);
   
   printf ("Testing KPI points\n");
   assert (getKPIpoints (testGame, UNI_A) == 0);
   assert (getKPIpoints (testGame, UNI_B) == 0);
   assert (getKPIpoints (testGame, UNI_C) == 0);
   
   printf ("Testing getARCs (number of ARC grants) \n");
   assert (getARCs (testGame, UNI_A) == 0);
   assert (getARCs (testGame, UNI_B) == 0);
   assert (getARCs (testGame, UNI_C) == 0);
   
   printf ("Testing GO8 (number of G08 campus) \n");
   assert (getGO8s (testGame, UNI_A) == 0);
   assert (getGO8s (testGame, UNI_B) == 0);
   assert (getGO8s (testGame, UNI_C) == 0);
   
   printf ("Testing getCampuses (number of normal campuses)\n");
   assert (getCampuses (testGame, UNI_A) == 2);
   assert (getCampuses (testGame, UNI_B) == 2);
   assert (getCampuses (testGame, UNI_C) == 2);
   
   printf ("Testing IPs (number of IP patent) \n");
   assert (getIPs(testGame, UNI_A) == 0);
   assert (getIPs(testGame, UNI_B) == 0);
   assert (getIPs(testGame, UNI_C) == 0);
   
   printf ("Testing publications\n");
   assert (getPublications(testGame, UNI_A) == 0);
   assert (getPublications(testGame, UNI_B) == 0);
   assert (getPublications(testGame, UNI_C) == 0);
 
   printf ("Testing number of students of UNI_A\n");
   assert (getStudents (testGame, UNI_A, STUDENT_THD) == 0);
   assert (getStudents (testGame, UNI_A, STUDENT_BPS) == 3);
   assert (getStudents (testGame, UNI_A, STUDENT_BQN) == 3);
   assert (getStudents (testGame, UNI_A, STUDENT_MJ) == 1);
   assert (getStudents (testGame, UNI_A, STUDENT_MTV) == 1);
   assert (getStudents (testGame, UNI_A, STUDENT_MMONEY) == 1);

   printf ("Testing number of students of UNI_B\n");
   assert (getStudents (testGame, UNI_B, STUDENT_THD) == 0);
   assert (getStudents (testGame, UNI_B, STUDENT_BPS) == 3);
   assert (getStudents (testGame, UNI_B, STUDENT_BQN) == 3);
   assert (getStudents (testGame, UNI_B, STUDENT_MJ) == 1);
   assert (getStudents (testGame, UNI_B, STUDENT_MTV) == 1);
   assert (getStudents (testGame, UNI_B, STUDENT_MMONEY) == 1);
   
   printf ("Testing number of students of UNI_C\n");
   assert (getStudents (testGame, UNI_C, STUDENT_THD) == 0);
   assert (getStudents (testGame, UNI_C, STUDENT_BPS) == 3);
   assert (getStudents (testGame, UNI_C, STUDENT_BQN) == 3);
   assert (getStudents (testGame, UNI_C, STUDENT_MJ) == 1);
   assert (getStudents (testGame, UNI_C, STUDENT_MTV) == 1);
   assert (getStudents (testGame, UNI_C, STUDENT_MMONEY) == 1);
   

   printf ("Testing getExchangeRate for UNI_A\n");
   assert (getExchangeRate (testGame, UNI_A, STUDENT_BPS, STUDENT_BPS) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_BPS, STUDENT_BQN) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_BPS, STUDENT_MJ) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_BPS, STUDENT_MTV) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_BPS, STUDENT_MMONEY) == 3);
   
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MMONEY, STUDENT_MMONEY) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MMONEY, STUDENT_BPS) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MMONEY, STUDENT_BQN) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MMONEY, STUDENT_MJ) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MMONEY, STUDENT_MTV) == 3);
   
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MTV, STUDENT_MTV) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MTV, STUDENT_BPS) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MTV, STUDENT_BQN) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MTV, STUDENT_MJ) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MTV, STUDENT_MMONEY) == 3);
   
   assert (getExchangeRate (testGame, UNI_A, STUDENT_BQN, STUDENT_BQN) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_BQN, STUDENT_BPS) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_BQN, STUDENT_MJ) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_BQN, STUDENT_MTV) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_BQN, STUDENT_MMONEY) == 3);
   
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MJ, STUDENT_MJ) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MJ, STUDENT_BPS) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MJ, STUDENT_BQN) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MJ, STUDENT_MTV) == 3);
   assert (getExchangeRate (testGame, UNI_A, STUDENT_MJ, STUDENT_MMONEY) == 3);
  
   printf ("All tests passed\n\n");
   
   
}
BlockLocalPositionEstimator::BlockLocalPositionEstimator() :
	// this block has no parent, and has name LPE
	SuperBlock(nullptr, "LPE"),
	// subscriptions, set rate, add to list
	_sub_armed(ORB_ID(actuator_armed), 1000 / 2, 0, &getSubscriptions()),
	_sub_land(ORB_ID(vehicle_land_detected), 1000 / 2, 0, &getSubscriptions()),
	_sub_att(ORB_ID(vehicle_attitude), 1000 / 100, 0, &getSubscriptions()),
	// set flow max update rate higher than expected to we don't lose packets
	_sub_flow(ORB_ID(optical_flow), 1000 / 100, 0, &getSubscriptions()),
	// main prediction loop, 100 hz
	_sub_sensor(ORB_ID(sensor_combined), 1000 / 100, 0, &getSubscriptions()),
	// status updates 2 hz
	_sub_param_update(ORB_ID(parameter_update), 1000 / 2, 0, &getSubscriptions()),
	// gps 10 hz
	_sub_gps(ORB_ID(vehicle_gps_position), 1000 / 10, 0, &getSubscriptions()),
	// vision 50 hz
	_sub_vision_pos(ORB_ID(vehicle_vision_position), 1000 / 50, 0, &getSubscriptions()),
	// mocap 50 hz
	_sub_mocap(ORB_ID(att_pos_mocap), 1000 / 50, 0, &getSubscriptions()),
	// all distance sensors, 10 hz
	_sub_dist0(ORB_ID(distance_sensor), 1000 / 10, 0, &getSubscriptions()),
	_sub_dist1(ORB_ID(distance_sensor), 1000 / 10, 1, &getSubscriptions()),
	_sub_dist2(ORB_ID(distance_sensor), 1000 / 10, 2, &getSubscriptions()),
	_sub_dist3(ORB_ID(distance_sensor), 1000 / 10, 3, &getSubscriptions()),
	_dist_subs(),
	_sub_lidar(nullptr),
	_sub_sonar(nullptr),
	_sub_landing_target_pose(ORB_ID(landing_target_pose), 1000 / 40, 0, &getSubscriptions()),

	// publications
	_pub_lpos(ORB_ID(vehicle_local_position), -1, &getPublications()),
	_pub_gpos(ORB_ID(vehicle_global_position), -1, &getPublications()),
	_pub_est_status(ORB_ID(estimator_status), -1, &getPublications()),
	_pub_innov(ORB_ID(ekf2_innovations), -1, &getPublications()),

	// map projection
	_map_ref(),

	// block parameters
	_fusion(this, "FUSION"),
	_vxy_pub_thresh(this, "VXY_PUB"),
	_z_pub_thresh(this, "Z_PUB"),
	_sonar_z_stddev(this, "SNR_Z"),
	_sonar_z_offset(this, "SNR_OFF_Z"),
	_lidar_z_stddev(this, "LDR_Z"),
	_lidar_z_offset(this, "LDR_OFF_Z"),
	_accel_xy_stddev(this, "ACC_XY"),
	_accel_z_stddev(this, "ACC_Z"),
	_baro_stddev(this, "BAR_Z"),
	_gps_delay(this, "GPS_DELAY"),
	_gps_xy_stddev(this, "GPS_XY"),
	_gps_z_stddev(this, "GPS_Z"),
	_gps_vxy_stddev(this, "GPS_VXY"),
	_gps_vz_stddev(this, "GPS_VZ"),
	_gps_eph_max(this, "EPH_MAX"),
	_gps_epv_max(this, "EPV_MAX"),
	_vision_xy_stddev(this, "VIS_XY"),
	_vision_z_stddev(this, "VIS_Z"),
	_vision_delay(this, "VIS_DELAY"),
	_mocap_p_stddev(this, "VIC_P"),
	_flow_z_offset(this, "FLW_OFF_Z"),
	_flow_scale(this, "FLW_SCALE"),
	//_flow_board_x_offs(NULL, "SENS_FLW_XOFF"),
	//_flow_board_y_offs(NULL, "SENS_FLW_YOFF"),
	_flow_min_q(this, "FLW_QMIN"),
	_flow_r(this, "FLW_R"),
	_flow_rr(this, "FLW_RR"),
	_land_z_stddev(this, "LAND_Z"),
	_land_vxy_stddev(this, "LAND_VXY"),
	_pn_p_noise_density(this, "PN_P"),
	_pn_v_noise_density(this, "PN_V"),
	_pn_b_noise_density(this, "PN_B"),
	_pn_t_noise_density(this, "PN_T"),
	_t_max_grade(this, "T_MAX_GRADE"),

	// landing target
	_target_min_cov(this, "LT_COV"),
	_target_mode(this, "LTEST_MODE", false),

	// init origin
	_fake_origin(this, "FAKE_ORIGIN"),
	_init_origin_lat(this, "LAT"),
	_init_origin_lon(this, "LON"),

	// flow gyro
	_flow_gyro_x_high_pass(this, "FGYRO_HP"),
	_flow_gyro_y_high_pass(this, "FGYRO_HP"),

	// stats
	_baroStats(this, ""),
	_sonarStats(this, ""),
	_lidarStats(this, ""),
	_flowQStats(this, ""),
	_visionStats(this, ""),
	_mocapStats(this, ""),
	_gpsStats(this, ""),

	// low pass
	_xLowPass(this, "X_LP"),
	// use same lp constant for agl
	_aglLowPass(this, "X_LP"),

	// delay
	_xDelay(this, ""),
	_tDelay(this, ""),

	// misc
	_polls(),
	_timeStamp(hrt_absolute_time()),
	_time_origin(0),
	_timeStampLastBaro(hrt_absolute_time()),
	_time_last_hist(0),
	_time_last_flow(0),
	_time_last_baro(0),
	_time_last_gps(0),
	_time_last_lidar(0),
	_time_last_sonar(0),
	_time_init_sonar(0),
	_time_last_vision_p(0),
	_time_last_mocap(0),
	_time_last_land(0),
	_time_last_target(0),

	// reference altitudes
	_altOrigin(0),
	_altOriginInitialized(false),
	_altOriginGlobal(false),
	_baroAltOrigin(0),
	_gpsAltOrigin(0),

	// status
	_receivedGps(false),
	_lastArmedState(false),

	// masks
	_sensorTimeout(UINT16_MAX),
	_sensorFault(0),
	_estimatorInitialized(0),

	// sensor update flags
	_flowUpdated(false),
	_gpsUpdated(false),
	_visionUpdated(false),
	_mocapUpdated(false),
	_lidarUpdated(false),
	_sonarUpdated(false),
	_landUpdated(false),
	_baroUpdated(false)
{
	// assign distance subs to array
	_dist_subs[0] = &_sub_dist0;
	_dist_subs[1] = &_sub_dist1;
	_dist_subs[2] = &_sub_dist2;
	_dist_subs[3] = &_sub_dist3;

	// setup event triggering based on new flow messages to integrate
	_polls[POLL_FLOW].fd = _sub_flow.getHandle();
	_polls[POLL_FLOW].events = POLLIN;

	_polls[POLL_PARAM].fd = _sub_param_update.getHandle();
	_polls[POLL_PARAM].events = POLLIN;

	_polls[POLL_SENSORS].fd = _sub_sensor.getHandle();
	_polls[POLL_SENSORS].events = POLLIN;

	// initialize A, B,  P, x, u
	_x.setZero();
	_u.setZero();
	initSS();

	// map
	_map_ref.init_done = false;

	// intialize parameter dependent matrices
	updateParams();

	// print fusion settings to console
	printf("[lpe] fuse gps: %d, flow: %d, vis_pos: %d, "
	       "landing_target: %d, land: %d, pub_agl_z: %d, flow_gyro: %d, "
	       "baro: %d\n",
	       (_fusion.get() & FUSE_GPS) != 0,
	       (_fusion.get() & FUSE_FLOW) != 0,
	       (_fusion.get() & FUSE_VIS_POS) != 0,
	       (_fusion.get() & FUSE_LAND_TARGET) != 0,
	       (_fusion.get() & FUSE_LAND) != 0,
	       (_fusion.get() & FUSE_PUB_AGL_Z) != 0,
	       (_fusion.get() & FUSE_FLOW_GYRO_COMP) != 0,
	       (_fusion.get() & FUSE_BARO) != 0);
}
Esempio n. 9
0
//already in testGame.c
//initially everyone has 0
void testgetPublications (void) {
    assert (getPublications(g, UNI_A) == 0);
    assert (getPublications(g, UNI_B) == 0);
    assert (getPublications(g, UNI_C) == 0);
}
BlockLocalPositionEstimator::BlockLocalPositionEstimator() :
	// this block has no parent, and has name LPE
	SuperBlock(nullptr, "LPE"),
	ModuleParams(nullptr),
	// subscriptions, set rate, add to list
	_sub_armed(ORB_ID(actuator_armed), 1000 / 2, 0, &getSubscriptions()),
	_sub_land(ORB_ID(vehicle_land_detected), 1000 / 2, 0, &getSubscriptions()),
	_sub_att(ORB_ID(vehicle_attitude), 1000 / 100, 0, &getSubscriptions()),
	// set flow max update rate higher than expected to we don't lose packets
	_sub_flow(ORB_ID(optical_flow), 1000 / 100, 0, &getSubscriptions()),
	// main prediction loop, 100 hz
	_sub_sensor(ORB_ID(sensor_combined), 1000 / 100, 0, &getSubscriptions()),
	// status updates 2 hz
	_sub_param_update(ORB_ID(parameter_update), 1000 / 2, 0, &getSubscriptions()),
	// gps 10 hz
	_sub_gps(ORB_ID(vehicle_gps_position), 1000 / 10, 0, &getSubscriptions()),
	// vision 50 hz
	_sub_vision_pos(ORB_ID(vehicle_vision_position), 1000 / 50, 0, &getSubscriptions()),
	// mocap 50 hz
	_sub_mocap(ORB_ID(att_pos_mocap), 1000 / 50, 0, &getSubscriptions()),
	// all distance sensors, 10 hz
	_sub_dist0(ORB_ID(distance_sensor), 1000 / 10, 0, &getSubscriptions()),
	_sub_dist1(ORB_ID(distance_sensor), 1000 / 10, 1, &getSubscriptions()),
	_sub_dist2(ORB_ID(distance_sensor), 1000 / 10, 2, &getSubscriptions()),
	_sub_dist3(ORB_ID(distance_sensor), 1000 / 10, 3, &getSubscriptions()),
	_dist_subs(),
	_sub_lidar(nullptr),
	_sub_sonar(nullptr),
	_sub_landing_target_pose(ORB_ID(landing_target_pose), 1000 / 40, 0, &getSubscriptions()),
	_sub_airdata(ORB_ID(vehicle_air_data), 0, 0, &getSubscriptions()),

	// publications
	_pub_lpos(ORB_ID(vehicle_local_position), -1, &getPublications()),
	_pub_gpos(ORB_ID(vehicle_global_position), -1, &getPublications()),
	_pub_est_status(ORB_ID(estimator_status), -1, &getPublications()),
	_pub_innov(ORB_ID(ekf2_innovations), -1, &getPublications()),

	// map projection
	_map_ref(),

	// flow gyro
	_flow_gyro_x_high_pass(this, "FGYRO_HP"),
	_flow_gyro_y_high_pass(this, "FGYRO_HP"),

	// stats
	_baroStats(this, ""),
	_sonarStats(this, ""),
	_lidarStats(this, ""),
	_flowQStats(this, ""),
	_visionStats(this, ""),
	_mocapStats(this, ""),
	_gpsStats(this, ""),

	// low pass
	_xLowPass(this, "X_LP"),
	// use same lp constant for agl
	_aglLowPass(this, "X_LP"),

	// delay
	_xDelay(this, ""),
	_tDelay(this, ""),

	// misc
	_polls(),
	_timeStamp(hrt_absolute_time()),
	_time_origin(0),
	_timeStampLastBaro(hrt_absolute_time()),
	_time_last_hist(0),
	_time_last_flow(0),
	_time_last_baro(0),
	_time_last_gps(0),
	_time_last_lidar(0),
	_time_last_sonar(0),
	_time_init_sonar(0),
	_time_last_vision_p(0),
	_time_last_mocap(0),
	_time_last_land(0),
	_time_last_target(0),

	// reference altitudes
	_altOrigin(0),
	_altOriginInitialized(false),
	_altOriginGlobal(false),
	_baroAltOrigin(0),
	_gpsAltOrigin(0),

	// status
	_receivedGps(false),
	_lastArmedState(false),

	// masks
	_sensorTimeout(UINT16_MAX),
	_sensorFault(0),
	_estimatorInitialized(0),

	// sensor update flags
	_flowUpdated(false),
	_gpsUpdated(false),
	_visionUpdated(false),
	_mocapUpdated(false),
	_lidarUpdated(false),
	_sonarUpdated(false),
	_landUpdated(false),
	_baroUpdated(false)
{
	// assign distance subs to array
	_dist_subs[0] = &_sub_dist0;
	_dist_subs[1] = &_sub_dist1;
	_dist_subs[2] = &_sub_dist2;
	_dist_subs[3] = &_sub_dist3;

	// setup event triggering based on new flow messages to integrate
	_polls[POLL_FLOW].fd = _sub_flow.getHandle();
	_polls[POLL_FLOW].events = POLLIN;

	_polls[POLL_PARAM].fd = _sub_param_update.getHandle();
	_polls[POLL_PARAM].events = POLLIN;

	_polls[POLL_SENSORS].fd = _sub_sensor.getHandle();
	_polls[POLL_SENSORS].events = POLLIN;

	// initialize A, B,  P, x, u
	_x.setZero();
	_u.setZero();
	initSS();

	// map
	_map_ref.init_done = false;

	// print fusion settings to console
	printf("[lpe] fuse gps: %d, flow: %d, vis_pos: %d, "
	       "landing_target: %d, land: %d, pub_agl_z: %d, flow_gyro: %d, "
	       "baro: %d\n",
	       (_fusion.get() & FUSE_GPS) != 0,
	       (_fusion.get() & FUSE_FLOW) != 0,
	       (_fusion.get() & FUSE_VIS_POS) != 0,
	       (_fusion.get() & FUSE_LAND_TARGET) != 0,
	       (_fusion.get() & FUSE_LAND) != 0,
	       (_fusion.get() & FUSE_PUB_AGL_Z) != 0,
	       (_fusion.get() & FUSE_FLOW_GYRO_COMP) != 0,
	       (_fusion.get() & FUSE_BARO) != 0);
}
BlockLocalPositionEstimator::BlockLocalPositionEstimator() :
	// this block has no parent, and has name LPE
	SuperBlock(NULL, "LPE"),
	// subscriptions, set rate, add to list
	_sub_armed(ORB_ID(actuator_armed), 1000 / 2, 0, &getSubscriptions()),
	_sub_att(ORB_ID(vehicle_attitude), 1000 / 100, 0, &getSubscriptions()),
	// flow 10 hz
	_sub_flow(ORB_ID(optical_flow), 1000 / 10, 0, &getSubscriptions()),
	// main prediction loop, 100 hz
	_sub_sensor(ORB_ID(sensor_combined), 1000 / 100, 0, &getSubscriptions()),
	// status updates 2 hz
	_sub_param_update(ORB_ID(parameter_update), 1000 / 2, 0, &getSubscriptions()),
	_sub_manual(ORB_ID(manual_control_setpoint), 1000 / 2, 0, &getSubscriptions()),
	_sub_home(ORB_ID(home_position), 1000 / 2, 0, &getSubscriptions()),
	// gps 10 hz
	_sub_gps(ORB_ID(vehicle_gps_position), 1000 / 10, 0, &getSubscriptions()),
	// vision 5 hz
	_sub_vision_pos(ORB_ID(vision_position_estimate), 1000 / 5, 0, &getSubscriptions()),
	// all distance sensors, 10 hz
	_sub_mocap(ORB_ID(att_pos_mocap), 1000 / 10, 0, &getSubscriptions()),
	_sub_dist0(ORB_ID(distance_sensor), 1000 / 10, 0, &getSubscriptions()),
	_sub_dist1(ORB_ID(distance_sensor), 1000 / 10, 1, &getSubscriptions()),
	_sub_dist2(ORB_ID(distance_sensor), 1000 / 10, 2, &getSubscriptions()),
	_sub_dist3(ORB_ID(distance_sensor), 1000 / 10, 3, &getSubscriptions()),
	_dist_subs(),
	_sub_lidar(NULL),
	_sub_sonar(NULL),

	// publications
	_pub_lpos(ORB_ID(vehicle_local_position), -1, &getPublications()),
	_pub_gpos(ORB_ID(vehicle_global_position), -1, &getPublications()),
	_pub_est_status(ORB_ID(estimator_status), -1, &getPublications()),

	// map projection
	_map_ref(),

	// block parameters
	_xy_pub_thresh(this, "XY_PUB"),
	_z_pub_thresh(this, "Z_PUB"),
	_sonar_z_stddev(this, "SNR_Z"),
	_sonar_z_offset(this, "SNR_OFF_Z"),
	_lidar_z_stddev(this, "LDR_Z"),
	_lidar_z_offset(this, "LDR_OFF_Z"),
	_accel_xy_stddev(this, "ACC_XY"),
	_accel_z_stddev(this, "ACC_Z"),
	_baro_stddev(this, "BAR_Z"),
	_gps_on(this, "GPS_ON"),
	_gps_delay(this, "GPS_DELAY"),
	_gps_xy_stddev(this, "GPS_XY"),
	_gps_z_stddev(this, "GPS_Z"),
	_gps_vxy_stddev(this, "GPS_VXY"),
	_gps_vz_stddev(this, "GPS_VZ"),
	_gps_eph_max(this, "EPH_MAX"),
	_gps_epv_max(this, "EPV_MAX"),
	_vision_xy_stddev(this, "VIS_XY"),
	_vision_z_stddev(this, "VIS_Z"),
	_vision_on(this, "VIS_ON"),
	_mocap_p_stddev(this, "VIC_P"),
	_flow_z_offset(this, "FLW_OFF_Z"),
	_flow_xy_stddev(this, "FLW_XY"),
	//_flow_board_x_offs(NULL, "SENS_FLW_XOFF"),
	//_flow_board_y_offs(NULL, "SENS_FLW_YOFF"),
	_flow_min_q(this, "FLW_QMIN"),
	_pn_p_noise_density(this, "PN_P"),
	_pn_v_noise_density(this, "PN_V"),
	_pn_b_noise_density(this, "PN_B"),
	_pn_t_noise_density(this, "PN_T"),

	// init home
	_init_home_lat(this, "LAT"),
	_init_home_lon(this, "LON"),

	// flow gyro
	_flow_gyro_x_high_pass(this, "FGYRO_HP"),
	_flow_gyro_y_high_pass(this, "FGYRO_HP"),

	// stats
	_baroStats(this, ""),
	_sonarStats(this, ""),
	_lidarStats(this, ""),
	_flowQStats(this, ""),
	_visionStats(this, ""),
	_mocapStats(this, ""),
	_gpsStats(this, ""),

	// low pass
	_xLowPass(this, "X_LP"),

	// delay
	_xDelay(this, ""),
	_tDelay(this, ""),

	// misc
	_polls(),
	_timeStamp(hrt_absolute_time()),
	_time_last_hist(0),
	_time_last_xy(0),
	_time_last_z(0),
	_time_last_tz(0),
	_time_last_flow(0),
	_time_last_baro(0),
	_time_last_gps(0),
	_time_last_lidar(0),
	_time_last_sonar(0),
	_time_init_sonar(0),
	_time_last_vision_p(0),
	_time_last_mocap(0),

	// initialization flags
	_receivedGps(false),
	_baroInitialized(false),
	_gpsInitialized(false),
	_lidarInitialized(false),
	_sonarInitialized(false),
	_flowInitialized(false),
	_visionInitialized(false),
	_mocapInitialized(false),

	// reference altitudes
	_altHome(0),
	_altHomeInitialized(false),
	_baroAltHome(0),
	_gpsAltHome(0),
	_visionHome(),
	_mocapHome(),

	// flow integration
	_flowX(0),
	_flowY(0),
	_flowMeanQual(0),

	// status
	_validXY(false),
	_validZ(false),
	_validTZ(false),
	_xyTimeout(true),
	_zTimeout(true),
	_tzTimeout(true),
	_lastArmedState(false),

	// faults
	_baroFault(FAULT_NONE),
	_gpsFault(FAULT_NONE),
	_lidarFault(FAULT_NONE),
	_flowFault(FAULT_NONE),
	_sonarFault(FAULT_NONE),
	_visionFault(FAULT_NONE),
	_mocapFault(FAULT_NONE),

	// loop performance
	_loop_perf(),
	_interval_perf(),
	_err_perf(),

	// kf matrices
	_x(), _u(), _P()
{
	// assign distance subs to array
	_dist_subs[0] = &_sub_dist0;
	_dist_subs[1] = &_sub_dist1;
	_dist_subs[2] = &_sub_dist2;
	_dist_subs[3] = &_sub_dist3;

	// setup event triggering based on new flow messages to integrate
	_polls[POLL_FLOW].fd = _sub_flow.getHandle();
	_polls[POLL_FLOW].events = POLLIN;

	_polls[POLL_PARAM].fd = _sub_param_update.getHandle();
	_polls[POLL_PARAM].events = POLLIN;

	_polls[POLL_SENSORS].fd = _sub_sensor.getHandle();
	_polls[POLL_SENSORS].events = POLLIN;

	// initialize A, B,  P, x, u
	_x.setZero();
	_u.setZero();
	_flowX = 0;
	_flowY = 0;
	initSS();

	// perf counters
	_loop_perf = perf_alloc(PC_ELAPSED,
				"local_position_estimator_runtime");
	//_interval_perf = perf_alloc(PC_INTERVAL,
	//"local_position_estimator_interval");
	_err_perf = perf_alloc(PC_COUNT, "local_position_estimator_err");

	// map
	_map_ref.init_done = false;

	// intialize parameter dependent matrices
	updateParams();
}
Esempio n. 12
0
//Sample out testing simple things
void testInitialState(Game g){
   printf("Testing initialState!\n");
   int disciplines[] = DEFAULT_DISCIPLINES;
   int dice[] = DEFAULT_DICE;
   //Check each region produces correct disciplines
   int regionID = 0;
   while (regionID < NUM_REGIONS) {
      assert(getDiscipline(g,regionID) == disciplines[regionID]);
      regionID ++;
   }

   //Check what dice value produces students in the specified region
   regionID = 0;
   while (regionID < NUM_REGIONS) {
      assert(getDiceValue(g,regionID) == dice[regionID]);
      regionID ++;
   }

   assert(getMostARCs(g) == NO_ONE);
   assert(getMostPublications(g) == NO_ONE);
   assert(getTurnNumber(g) == -1);
   assert(getWhoseTurn(g) == NO_ONE);

   //Check individual uni values
   int uni = UNI_A;
   while(uni <= UNI_C){

      //Check Uni's exchange rates
      int testStudentFrom = STUDENT_BPS;
      int testStudentTo = STUDENT_BPS;
      while (testStudentFrom <= STUDENT_MMONEY) {
         while (testStudentTo <= STUDENT_MMONEY) {
            if (testStudentFrom != testStudentTo) {
               assert(getExchangeRate (g, uni, testStudentFrom, testStudentTo) == 3);
            }
            testStudentTo ++;
         }
         testStudentFrom ++;
         testStudentTo = STUDENT_BPS;
      }

      assert(getKPIpoints(g,uni) == 20);
      assert(getARCs(g,uni) == 0);
      assert(getGO8s(g,uni) == 0);
      assert(getCampuses(g,uni) == 2);
      assert(getPublications(g,uni) == 0);
      assert(getIPs(g,uni) == 0);

      //Check initial student values
      assert(getStudents(g,uni,STUDENT_THD)==0);
      assert(getStudents(g,uni,STUDENT_BPS)==3);
      assert(getStudents(g,uni,STUDENT_BQN)==3);
      assert(getStudents(g,uni,STUDENT_MJ)==1);
      assert(getStudents(g,uni,STUDENT_MTV)==1);
      assert(getStudents(g,uni,STUDENT_MMONEY)==1);

      uni++;
   }
   //Test isLegalAction at Terra Nullis
   action passAction;
   action CampusAction;
   action GO8Action;
   action ARCAction;
   action spinoffAction;
   action publicationAction;
   action patentAction;
   action retrainAction;
   passAction.actionCode = PASS;
   CampusAction.actionCode = BUILD_CAMPUS;
   GO8Action.actionCode = BUILD_GO8;
   ARCAction.actionCode = OBTAIN_ARC;
   spinoffAction.actionCode = START_SPINOFF;
   publicationAction.actionCode = OBTAIN_PUBLICATION;
   patentAction.actionCode = OBTAIN_IP_PATENT;
   retrainAction.actionCode = RETRAIN_STUDENTS;
   assert(isLegalAction(g, passAction) == FALSE);
   assert(isLegalAction(g, CampusAction) == FALSE);
   assert (isLegalAction(g, GO8Action) == FALSE);
   assert(isLegalAction(g, ARCAction) == FALSE);
   assert(isLegalAction(g, spinoffAction) == FALSE);
   assert(isLegalAction(g, publicationAction) == FALSE);
   assert(isLegalAction(g, patentAction) == FALSE);
   assert(isLegalAction(g, retrainAction) == FALSE);
   printf ("All initialState tests passed!\n");
}
Esempio n. 13
0
int main (int argc, char * argv[]) {

	int disciplines[19] = {STUDENT_BQN, STUDENT_MMONEY, STUDENT_MJ, \
		STUDENT_MMONEY, STUDENT_MJ, STUDENT_BPS, STUDENT_MTV, \
		STUDENT_MTV, STUDENT_BPS,STUDENT_MTV, STUDENT_BQN, \
		STUDENT_MJ, STUDENT_BQN, STUDENT_THD, STUDENT_MJ, \
		STUDENT_MMONEY, STUDENT_MTV, STUDENT_BQN, STUDENT_BPS};

	int dice[19] = {9,10,8,12,6,5,3,11,3,11,4,6,4,7,9,2,8,10,5};

	Game g = newGame (disciplines, dice);
	action a;
//	int score = 0; //This stores the KPI points of current player 
	int curPlayer = NO_ONE; 
	int curTurn = 0; 
	int playerKPI = 0;
	int numStudents[MAX_STU_TYPES];
	int legal = 0;
	int diceScore = 0; 
	int spinoffDice = 0;
	//int discipline = 0;
	int counter = 0; 

	char *degrees[] = \
		  {"THDs", "BPSs", "BQNs", "MJs", "MTVs", "MMONEYs"};
	


	printf ("New game created, variables are initialized.\n");
	printf ("Let the game begin!\n\n");

	while (playerKPI < MAX_KPIPTS) {
		
		//To simulate an actual real life dice, we throw two dice 
		diceScore = rollDice();
		throwDice (g, diceScore);

		curTurn = getTurnNumber (g);
		curPlayer = getWhoseTurn (g);
		printf ("Turn number: %d\n", curTurn);
		printf ("Player %d's turn. Rolling dice.\n", curPlayer);
		printf ("The two dice rolled a %d! \n", diceScore);

		printf ("You currently have: \n");
		counter = 0;
		while (counter < MAX_STU_TYPES) {
			numStudents[counter] = getStudents (g, curPlayer, counter);
			printf ("    %d: %s\n", numStudents[counter],\
								    degrees[counter]);
			counter ++;
		}
		actionOptions ();
		a = actionPrompt (g);
		legal = isLegalAction (g, a);

		while (a.actionCode != PASS) {
			while (legal == FALSE) {
				printf ("The chosen action is illegal, try again.\n");
				actionPrompt (g);
				legal = isLegalAction (g, a);
			}

			if (a.actionCode == START_SPINOFF) {
				//Ensures dice returns 1, 2 or 3.
				spinoffDice = (rand()%3 + 1);
				if (spinoffDice == 1) {
					a.actionCode = OBTAIN_IP_PATENT;
				} else {
					a.actionCode = OBTAIN_PUBLICATION;
				}
			}

			makeAction (g, a);
			printf("Action made!");

			printf ("Your current stats:\n");
			printf ("    ARC Grants: %d\n", getARCs (g, curPlayer));
			printf ("    No of Campuses: %d\n", getCampuses (g, curPlayer));
			printf ("    No of G08s: %d\n", getGO8s (g, curPlayer));
			printf ("    No of Pubs: %d\n", getPublications (g, curPlayer));
			printf ("    No of IP Patents: %d\n", getIPs (g, curPlayer));

			playerKPI = getKPIpoints (g, curPlayer);
			printf ("Player %d KPI Score: %d\n\n", curPlayer, playerKPI);
		}

		printf ("Next player's turn.\n\n");

	}

	printf ("Congratulations, player %d won.\n", curPlayer);
	printf ("Game completed. Disposing game.\n");
	
	disposeGame (g);

	return EXIT_SUCCESS;
}
Esempio n. 14
0
int main(int argc, char *argv[]) {
   // miscellaneous
   /*int disciplines[NUM_REGIONS];
   int dice[NUM_REGIONS];*/
   Game g;
   
   // store the winner of each game
   int winner;
  
   // store game states within the game
   int keepPlaying;
   int turnFinished;
   int diceRollAmount;
   
   // random
   char *actions[] = ACTION_NAMES;
   int diceRoll;
   
   int passedTurns = 0;
            
   // seed rand!
   srand(time(NULL));
   
   // while the game is wanting to be played, create new game, etc.
   keepPlaying = TRUE;
   while (keepPlaying == TRUE) {
      // create the game
      //randomDisciplines(disciplines);
      //randomDice(dice);
      
      // you can change this to randomiseDisciplines() and randomiseDice() later
      int disciplines[NUM_REGIONS] = {CYAN,PURP,YELL,PURP,YELL,RED ,GREE,GREE, RED ,GREE,CYAN,YELL,CYAN,BLUE,YELL,PURP,GREE,CYAN,RED };
      int dice[NUM_REGIONS] = {9,10,8,12,6,5,3,7,3,11,4,6,4,9,9,2,8,10,5};

      // rig board like the real game
      rigBoard(disciplines, dice);
      g = newGame(disciplines, dice);
      
      printf("Game created! Now playing...\n");
      
      // start the game with noone as the winner
      winner = NO_ONE;
      while (winner == NO_ONE) {
         printLineBreak();
         // start new turn by setting turnFinished to false then
         // rolling the dice
         
         diceRollAmount = 0;
         diceRoll = 0;
         while (diceRollAmount < DICE_AMOUNT) {
            diceRoll += rollDice();
            diceRollAmount++;
         }
         
         throwDice(g, diceRoll);
         
         // new turn means new line break!
         printf("[Turn %d] The turn now belongs to University %c!\n", 
            getTurnNumber(g),
            getWhoseTurn(g) + UNI_CHAR_NAME);
         printf("The dice has casted a %d!\n", diceRoll);
         
         printf("\n");
         
         
         // keep going through the player's turn until
         // he/she decided to pass and finish the turn
         turnFinished = FALSE;
         while (turnFinished == FALSE && passedTurns < MAX_PASS) {
            // processes requests and all subrequests for a move and
            // checks if they are legal. only gives a move within the
            // scope of the defined actionCodes that is legal
            int turnPerson = getWhoseTurn(g);
            printf("Stats for %c:\n", turnPerson + UNI_CHAR_NAME);
            printf("KPIs: %d\n", getKPIpoints(g, turnPerson));
            printf("ARCs: %d\n", getARCs(g, turnPerson));
            printf("Campuses: %d\n", getCampuses(g, turnPerson));
            printf("GO8s: %d\n", getGO8s(g, turnPerson));
            printf("Publications: %d\n", 
               getPublications(g, turnPerson));
            printf("Patents: %d\n", 
               getIPs(g, turnPerson));
            int discipleIndex = 0;
            char *discipleNames[] = DISCIPLE_NAMES;
            while (discipleIndex < NUM_DISCIPLINES) {
               printf("Type %s: %d\n", discipleNames[discipleIndex],
                  getStudents(g, turnPerson, discipleIndex));
               discipleIndex++;
            } 
            printf("\n");
            
            action a = decideAction(g);
            
            // if not passing, make the move; otherwise end the turn
            if (a.actionCode == PASS) {
               turnFinished = TRUE;
               printf("You have passed onto the next person.\n");
            } else {
              
               // write what the player did, for a logs sake.
               printf("The action '%s' has being completed.\n", 
                       actions[a.actionCode]);
               if (a.actionCode == BUILD_CAMPUS 
                   || a.actionCode == OBTAIN_ARC 
                   || a.actionCode == BUILD_GO8) {
                  printf(" -> Destination: %s\n", a.destination);
               } else if (a.actionCode == RETRAIN_STUDENTS) {
                  printf(" -> DisciplineTo: %d\n", a.disciplineTo);
                  printf(" -> DisciplineFrom: %d\n", a.disciplineFrom);
               }

	        assert(isLegalAction(g, a));                                   
            
               // break this and the code dies. trololol!
               if (a.actionCode == START_SPINOFF) {
                  if (rand() % 3 <= 1) {
                     a.actionCode = OBTAIN_PUBLICATION;
                  } else {
                     a.actionCode = OBTAIN_IP_PATENT;               
                  }
               }

               makeAction(g, a);
               
               if (a.actionCode == PASS) {
                  passedTurns++;
               } else {
                  passedTurns = 0;
               }
               
               if (passedTurns >= MAX_PASS || getKPIpoints(g, turnPerson) >= WINNING_KPI) {
                  turnFinished = TRUE;
                  
               }
            }
            
            // if there is not a winner or pass, add a seperating line
            // to seperate actions being clumped together
            if (turnFinished == FALSE) {
               printf("\n");
            }
         }
         
         // check if there is a winner
         winner = checkForWinner(g);
      }
      
      if (passedTurns >= MAX_PASS) {
         printf("AI passes too much.\n");
         return EXIT_FAILURE;
      }
      
      printLineBreak();
      printf("GAME OVER!\n");
      printf("Vice Chanceller %c Won in %d Turns!!\n", 
             winner + UNI_CHAR_NAME,
             getTurnNumber(g));
             
      printf("\n");
      int counter = UNI_A;
      while (counter < NUM_UNIS + UNI_A) {
         printf("Uni %c scored %d KPIs\n", counter + UNI_CHAR_NAME,
                getKPIpoints(g, counter));
         counter++;
      }
      printLineBreak();
      
      disposeGame(g);
      
      // ask to play again
      printf("Ctrl+C will exit the game.\nOtherwise, the game will "
             "recommence by hitting enter.");
      int a = scanf("%*c");
      a++;
   }     
   
   return EXIT_SUCCESS;
}
Esempio n. 15
0
int main(int argc, char *argv[]) {
    int disciplines[] = DEFAULT_DISCIPLINES;
    disciplines[2] = STUDENT_BPS;
    disciplines[7] = STUDENT_BPS;
    disciplines[11] = STUDENT_BQN;
    disciplines[16] = STUDENT_BQN;
    int dice[] = DEFAULT_DICE;
    int i = 0;
    int automation = TRUE;
    int diceRoll = 1;
    char *vertices[54];
    char *sides[72];

    //nanosecond seeding
    struct timespec ts;
    clock_gettime(CLOCK_MONOTONIC, &ts);

    populatePaths(vertices);
    populateSides(sides);

    printf("Automatic(1) or Human(0): ");
    scanf("%d", &automation);

    //seeding starts now
    srand((time_t)ts.tv_nsec);

    Game g = newGame(disciplines, dice);
    action a;

    while(getKPILeader(g) < 150  &&  getTurnNumber(g) < 9003) {
        if(automation == FALSE) {
            printf("Enter dice roll: ");
            scanf("%d", &diceRoll);
        } else {
            diceRoll = rand() % 10 + 2;
        }

        throwDice(g, diceRoll);
        printf("diceRoll = %d\n", diceRoll);

        printf("\n");
        printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
        printf("Turn: %d\n", getTurnNumber(g));
        printf("Player %d's turn\n", getWhoseTurn(g));

        printf("\n");
        printf("You have %d ARCs\n", getARCs(g, getWhoseTurn(g)));
        i = 0;
        while(i < 72) {
            if(getARC(g, sides[i]) == getWhoseTurn(g)) { 
                printf("You have an ARC on %s\\0\n", sides[i]);
            }
            i++;
        }
        printf("You have %d Campuses\n", getCampuses(g, getWhoseTurn(g)));
        printf("You have %d GO8s\n", getGO8s(g, getWhoseTurn(g)));
        i = 0;
        while(i < 54) {
            if(getCampus(g, vertices[i]) == getWhoseTurn(g)) { 
                printf("You have a campus on %s\\0\n", vertices[i]);
            }
            if(getCampus(g, vertices[i]) == getWhoseTurn(g) + 3) {
                printf("You have a GO8 on %s\\0\n", vertices[i]);
            }
            i++;
        }
        printf("You have %d Publications\n", getPublications(g, getWhoseTurn(g)));
        printf("You have %d IP Patents\n", getIPs(g, getWhoseTurn(g)));
        printf("\n");
        
        printf("Students:\n");
        printf("You have %d THD Students\n", getStudents(g, getWhoseTurn(g), STUDENT_THD));
        printf("You have %d BPS Students\n", getStudents(g, getWhoseTurn(g), STUDENT_BPS));
        printf("You have %d BQN Students\n", getStudents(g, getWhoseTurn(g), STUDENT_BQN));
        printf("You have %d MJ Students\n", getStudents(g, getWhoseTurn(g), STUDENT_MJ));
        printf("You have %d MTV Students\n", getStudents(g, getWhoseTurn(g), STUDENT_MTV));
        printf("You have %d MMONEY Students\n", getStudents(g, getWhoseTurn(g), STUDENT_MMONEY));
        printf("\n");

        if(automation == FALSE) {
            a = getHumanAction();
        } else {
            a = getAIAction(g);
        }

        while(a.actionCode != PASS) {
            if(isLegalAction(g, a)) {
                if(a.actionCode == START_SPINOFF) {
                    if(rand() % 3 > 1) {
                        a.actionCode = OBTAIN_IP_PATENT;
                    } else {
                        a.actionCode = OBTAIN_PUBLICATION;
                    }
                }
                makeAction(g, a);
            } else {
                printf("Illegal Action");
            }
            printf("\n");
            printf("Player %d's turn\n", getWhoseTurn(g));

            printf("You have %d ARCs\n", getARCs(g, getWhoseTurn(g)));
            printf("You have %d Campuses\n", getCampuses(g, getWhoseTurn(g)));
            printf("You have %d GO8s\n", getGO8s(g, getWhoseTurn(g)));
            printf("You have %d Publications\n", getPublications(g, getWhoseTurn(g)));
            printf("You have %d IP Patents\n", getIPs(g, getWhoseTurn(g)));
            printf("\n");
            printf("Students:\n");
            printf("You have %d THD Students\n", getStudents(g, getWhoseTurn(g), STUDENT_THD));
            printf("You have %d BPS Students\n", getStudents(g, getWhoseTurn(g), STUDENT_BPS));
            printf("You have %d BQN Students\n", getStudents(g, getWhoseTurn(g), STUDENT_BQN));
            printf("You have %d MJ Students\n", getStudents(g, getWhoseTurn(g), STUDENT_MJ));
            printf("You have %d MTV Students\n", getStudents(g, getWhoseTurn(g), STUDENT_MTV));
            printf("You have %d MMONEY Students\n", getStudents(g, getWhoseTurn(g), STUDENT_MMONEY));
            printf("\n");

            if(automation == FALSE) {
                a = getHumanAction();
            } else {
                a = getAIAction(g);
            }

        }
        printf("Player 1 KPI points : %d\n", getKPIpoints(g, UNI_A));
        printf("Player 2 KPI points : %d\n", getKPIpoints(g, UNI_B));
        printf("Player 3 KPI points : %d\n", getKPIpoints(g, UNI_C));
    }
    printf("Winner: Player %d\n", getWinner(g));    
    disposeGame(g);
    return EXIT_SUCCESS;
}