/* * Copyright (C) 2009 * Robert Bosch LLC * Research and Technology Center North America * Palo Alto, California * * All rights reserved. * *------------------------------------------------------------------------------ * project ....: Autonomous Technologies * file .......: aw_IntersectionTrafficLightWait.cpp * authors ....: Soeren Kammel * organization: Robert Bosch LLC * creation ...: Nov 24, 2009 * modified ...: $Date:$ * changed by .: $Author:$ * revision ...: $Revision:$ */ #include "aw_StPause.hpp" #include "aw_StDrive.hpp" #include "aw_StReplan.hpp" #include "aw_StIntersectionTrafficLightWait.hpp" #include "aw_StIntersectionTrafficLightStop.hpp" namespace vlr { /*--------------------------------------------------------------------------- * StIntersectionTrafficLightStop *---------------------------------------------------------------------------*/ StIntersectionTrafficLightStop::StIntersectionTrafficLightStop(my_context ctx) : my_base(ctx), kogmo_base(std::string("StIntersectionTrafficLightStop")) { context().bIntersection = true; } StIntersectionTrafficLightStop::~StIntersectionTrafficLightStop() { } sc::result StIntersectionTrafficLightStop::react(const EvProcess&) { if (detectedErrornousTransitions()) return transit(); ChsmPlanner& planner = context(); IntersectionManager* isec_man = context().isec_man; Topology* topology = context().topology; assert(isec_man); // Transition: Recovery Mode if (isec_man->hasPrioMovement()) { context().clearRecoveryIndicator(); } if (planner.params().enable_recovery && (context().checkRecovery() || isExpired(context().max_wait_at_intersection))) { // measure progress in the parent state return transit(); } // Transition: Replanning (because ego vehicle is off track) if (topology->isOffTrack()) return transit(); // Transition: Replanning (because route is blocked) if ( topology->isRouteBlocked() ) return transit(); // Transition: If traffic light switched to green while slowing down cross intersection if(!context().isec_man->hasToStop()) { return transit(); } // Abstände berechnen // TODO Sicherstellen, dass die Stoplinie zur Kreuzung gehört double traffic_light_dist = topology->dist_to_traffic_light(isec_man->getIntersection(), NULL, &planner.stop_point_); double intersec_dist = topology->dist_to_intersection(isec_man->getIntersection()); double mv_veh_dist, sv_veh_dist; planner.getVehicleDistances(sv_veh_dist, mv_veh_dist); // set turn signal planner.vehiclecmd.turnsignal = context().turnDirection; // printf("STOP IN %f m;\t CURRENT SPEED %f\n", traffic_light_dist, currentPose().v()); // Transition: Wait at Stopline (because ego_vehicle stopped at stopline) if ( traffic_light_dist < TRAFFIC_LIGHT_DIST_THRESHOLD && planner.currentPose().v() < STOP_SPEED_THRESHOLD ) { return transit(); } else if (traffic_light_dist == std::numeric_limits::infinity()) { std::cout << "WE RAN OVER A (NON GREEN) TRAFFIC LIGHT!!\n"; return transit(); } // Transition: Queueing (falls Fahrzeug zurückgesetzt hat) if ( traffic_light_dist < TRIGGER_DIST_TRAFFIC_LIGHT && (mv_veh_dist < traffic_light_dist || sv_veh_dist < traffic_light_dist) ) return transit(); // Transition: To get states right if something goes wrong: leave intersection mode if we behind intersection if ( intersec_dist <= -0.1 ) { return transit(); } // generate curvepoints context().generateCurvepoints(traffic_light_dist, planner.params().max_speed_traffic_light_approach); return forward_event(); } } // namespace vlr