Helicopters points Its its Challenge and its time for a Networked Game This time its about helicopters Our location is a small section of a little bluegreen planet This section is about square kilometers and happens to be conveniently bordered by an insanely high mountain chain called the Edge Mountain It has hills valleys rivers cows but above all helipads The local people are an industrious sort and have a lot of cargo to deliver to their fellow citizens The preferred kind of transportation uses computer controlled helicopters and its your task to write the AI The Setup Each team has three helicopters to control Helicopters are controlled through TCP connections a separate connection for each helicopter using a textbased protocol The helicopters will send sensor information and act on control input at a rate of Hz Each helicopter is equipped with a range of sensors GPS for helicopter position Orientation and velocity sensors Fuel sensor Terrain radar for surrounding terrain layout and static objects and obstacles Long range radar for detection of helicopters in a km range Battle radar for tracking of helicopters within meters Video camera Helicopters are controlled through four primary control inputs Pitch Roll Collective Pedal The Pitch and Roll inputs are together called the Cyclic There is a hidden fifth input the Throttle but this is a modern type of helicopter and the engine is controlled automatically For physical calculations you can model the body of the helicopter as a brick cuboid that is meters long meters wide and tall Its center of mass is shifted from the middle by meters towards the nose The main rotor disc has a radius of meters and has its center point meters above the center of mass Each team has a bank account Fuel purchases and other costs will be deducted from this account while prizes for successful cargo deliveries will be added to it Teams have infinite credit so you can go in the red as deeply as you want The video feed from the video camera of each helicopter may be watched on the stream server URL specified outside this document One team can watch only one of their three helicopter cameras at once Scoring Throughout the hours the game is divided into six hours long campaigns In each campaign teams begin with their bank accounts reset to however no other stats like map exploration percentage number of deliveries etc are reset At the end of each campaign teams are ordered by how much money they have Each team gets a final score depending on its place on this list base score multiplied by the campaign factor This means that at the end of hours a teams final score is calculated as B F B F B F B F B F B F where Bn is the base score the team achieved during campaign n and Fn is the factor of campaign see the tables below In case of a tie the points for the first shared rank are used eg if the nd rd th places are tied all three teams get points for being the nd the th placed team gets points for being the th If in a campaign a team ends up with a nonpositive amount of money they get points for the campaign regardless of their placement campaign starts at campaign rank at the end of the base score number factor campaign Sat st Sat nd Sat rd Sat thth rank Sun Sun This means the maximum score a team can get from making a lot of money is about points There are some other ways of getting more points Completing Intro Mission is worth points Completing Intro Mission is worth points Completing Intro Mission is worth points Delivering the most packages during the game is worth points Exploring the most of the map is worth points Fragging the most enemy helicopters is worth points This means the grand total achievable score adding up score for campaigns intro missions and achievements is points Helipads These are the places where the helicopters can land It may be possible to land elsewhere on the terrain but such a landing will receive none of the benefits of helipads Each helicopter begins stationary on a helipad Should a helicopter crash it will be moved to the nearest unoccupied helipad after being restored to full operation fortunately this is a pretty fast process and takes the whole of second Landed helicopters are refueled automatically at a certain cost per fuel unit which is removed from the teams bank account Cargo deliveries are available at certain helipads Helicopters can take the cargo then deliver it to the destination which is always another helipad Landing on the destination helipad will deliver the cargo and automatically award the delivery prize Crashing You will crash a lot so its useful to be aware how it exactly works There are three ways a helicopter can crash Running out of fuel Touching water Intersecting the main rotor disc with something solid such as the terrain objects or the bodies of other helicopters Note that this list doesnt include such things as falling on the ground very fast or maneuvering your helicopters body into the main rotor disc of another helicopter These things are absolutely harmless Destroying a helicopter of an enemy team in such a way is counted as a frag and is even awarded with a little money It is theoretically possible if very difficult to get stuck without crashing eg by landing sideways on the edge of a cliff In such cases ask the organizers so they may reset your helicopter by a friendly smiting from the skies Crashing incurs a certain cost More importantly the cargo on the crashed helicopter is lost as well map The Terrain The world is described through a threedimensional coordinate system From smaller to larger values the X coordinate goes from west to east the Y coordinate goes from south to north and the Z coordinate goes from the water level upwards The measurement unit is the meter The world around the helicopters consists of the terrain and a few objects such as helipads The layout of the world is initially unknown controlled helicopters will notify you of the things they see through their sensors The terrain can be modelled as a height field where the water level is and everything at level is water Terrain is divided into x meter sectors For each sector the helicopter will report height lines and any objects it sees Height lines are lines given using beginning and ending X Y coordinate pairs and a Z height They give the contours of a certain height level of the terrain that is the terrain that lays under the given line segment has the constant height Z Theyre not guaranteed to form closed polygons However height lines have a direction looking from the beginning towards the end on the right side of the line the terrain will be higher on the left side it will be lower Note that the height lines are just a representation of the terrain not the terrain itself It is not guaranteed that there are no higher points near a height line of a certain level for example It might be a good idea to keep a flight clearance of at least the difference between the levels of the two highest height line levels of the given sector Objects are static unmoving things in the world They are modelled as cylinders perpendicular to the X Y plane Objects are always given by their X Y Z coordinates identifying the center point of the top disc of the cylinder and the radius of the cylinder The bottom of the cylinder touches the underlying terrain Deliveries There is a constantly changing pool of available delivery jobs All teams see the same pool and helicopters from any team can take available jobs A taken delivery job will disappear from the pool immediately and wont reappear no matter if its delivered successfully or not Each delivery job has the following properties ID a unique positive integer identifying the job Deadline until which the job has to be delivered no matter when its taken Timeout when the job disappears if not taken on by anyone Cargo type Coordinates of the source helipad Coordinates of the destination helipad Cost of taking the job Prize for completing the job To complete a delivery a helicopter has to land on the source helipad take the selected job then fly to the destination helipad and land on it One helicopter can take only one job at a time There are longer deliveries than the fuel tank on the helicopters can last In this case the helicopter will have to land on a helipad somewhere between for refueling The weight of cargo differs by cargo type but is otherwise unknown Some types of cargo may make your helicopter noticeably heavier Delivery prizes depend on multiple things the kind of cargo the deadline but most importantly the distance It is much more difficult to take cargo on long distances but the rewards are higher too Intro Missions Controlling the helicopters through a complete delivery job is a challenging task There are three easier practice tasks each team can do for extra points Each mission can be tried any number of times free of cost but each team can complete one only once Each mission is done by a single helicopter starting from a landed position on any helipad Missions are started by issuing an explicit command Mission get a helicopter to touch a given nearby point in space given by world coordinates the center of mass has to be within meters distance from the point Deadline seconds Mission just like mission but have to touch consecutive points each given after the previous is touched successfully within seconds Mission get a helicopter to a given nearby point in space and keep the center of mass within meters distance for consecutive seconds Deadline seconds Helicopter Control Helicopters will use the last set of four controls they received through their corresponding TCP connection Each control is given as a floating point number A typical AI will wait for a Hz update calculate new controls and reply with the new controls right away For the purpose of explaining the controls well use a local coordinate system for a helicopter the X axis points towards the nose the Y axis to the left and the Z axis up The first control is the collective It results in an upward force a push towards the direction of the main rotor The control input has to be between The second control is the pitch It produces a torque around the Y axis A positive value will make the helicopter lean forward push the nose down and the tail up The control input has to be between The third control is the roll It produces a torque around the X axis A positive value will make the helicopter bank right turn around the forward axis clockwise The control input has to be between The fourth control is the pedal It controls the force produced by the tail rotor A positive value will push the tail to the right and thus the nose will tend to look left The control input has to be between Control Protocol In general the control protocol is line based Unless otherwise indicated all sent data fields are floating point numbers If a data field has a string type the string never contains whitespace and there are no quotes around it Each sent line in either direction consists of one or more words strings or numbers separated by single spaces ending with a single unix newline Control Protocol Authentication After a TCP connection is made to the helicopter control server the team has to log in by sending their team password on a single line The server will reply with either of ERROR invalid password and will close the connection or OK choose helicopter After the OK answer the client has to send the number of the helicopter it wishes to control or or on a single line One helicopter can have only one open control connection at a time After a successful authentication the server will begin to send updates Control Protocol Summary Server to Client POS x y z V vx vy vz QUAT qx qy qz qw FUEL fuel CRASH RADAR type dx dy dz PROXI type dx dy dz V vx vy vz QUAT qx qy qz qw TAKEOFF LANDING SECTOR sx sy heightlines objects HL z x y z y OBJ type x y z r JOB id deadline cargo fx fy fz tx ty tz cost prize timeout TAKEN id TIMEOUT id FAIL WIN NOCARGO CARGO id deadline cargo fx fy fz tx ty tz cost prize FREESTYLE MISSION tx ty tz MISSION tx ty tz MISSION tx ty tz countdown ACCOMPLISHED Client to Server collective pitch roll pedal TAKE id JETTISON MISSION number FREESTYLE Control Protocol Server to Client Helicopter The server sends updates at Hz Each such update consists of or more optional lines and a single POS line at the end which is always sent POS x y z V vx vy vz QUAT qx qy qz qw FUEL fuel x y z is the position of the helicopters center of mass in world coordinates vx vy vz is the velocity vector of the helicopter in world coordinates qx qy qz qw give the orientation of the helicopter as a quaternion see appendix fuel is the amount of remaining fuel Again the POS line is always sent as the final line of a Hz update so a client update of the controls should follow Lines below in this section are all optional lines CRASH The helicopter is in a crashed state It will remain so for a few cycles the CRASH line will always be sent in these cycles Control input is ignored for crashed helicopters RADAR type dx dy dz Detection report from the long range radar Such a report will be sent for each detected helicopter once a second type is a string giving the type of detected object and is always HELI dx dy dz give the relative coordinates of the detected helicopter in world space PROXI type dx dy dz V vx vy vz QUAT qx qy qz qw Detection report from the battle proximity radar Such a report will be sent for each detected helicopter in every cycle type is a string giving the type of detected object and is always HELI dx dy dz give the relative coordinates in world space of the detected helicopters center of mass vx vy vz give the velocity vector in world space qx qy qz qw give the orientation as a quaternion The long range and battle radars are independent If a helicopter is in range for the battle radar long range reports will still be sent once a second The proximity radar can track up to helicopters at once TAKEOFF The helicopter is now in flight LANDING The helicopter has landed on a helipad successfully At the beginning of a control connection either TAKEOFF or LANDING will be sent as part of the first report Control Protocol Server to Client Sector Description SECTOR sx sy heightlines objects This line begins a world sector description report These reports are sent when the helicopter first sees a terrain sector since the beginning of the control connection thus for each connection and each sector the report will be sent only once All data fields are integers sx sy are the sector ID Sector ID comes from world coordinates by dividing X Y by and rounding downwards heightlines gives the number of following HL lines objects gives the number of following OBJ lines A sector description report consists of SECTOR line Then heightlines HL lines Then objects OBJ lines HL or OBJ lines are never sent outside a sector description report Other report lines are never mixed in sector description reports Sector descriptions stay constant for the duration of the contest so reports for the same sectors should be identical HL z x y z y This is a height line or contour line as part of a sector description z is an integer giving the height of the reported height line x y give the beginning point x y give the end point OBJ type x y z r This is a static unmoving object as part of a sector description type is a string giving the type of static object Helipads have the type of landingpad There are other types which should be considered obstacles x y z is the top center point of the object cylinder in world coordinates r is the radius of the object cylinder Control Protocol Server to Client Delivery JOB id deadline cargo fx fy fz tx ty tz cost prize timeout A new delivery job is available On a new connection such a line will be sent for all currently available jobs as part of the first report id is an integer and identifies the job deadline is an integer and gives the number of seconds until the job has to be delivered so the deadline is at now deadline seconds cargo is a string and identifies the cargo type fx fy fz give the location of the helipad where the delivery job is available in world coordinates tx ty tz give the location of the destination helipad in world coordinates cost is the cost for taking on the job prize is the prize for completing the job timeout is an integer that gives the number of seconds until the job disappears if not taken by anyone TAKEN id A delivery job has been taken and is no longer available id is an integer and identifies the job TIMEOUT id A delivery job has timed out and is no longer available id is an integer and identifies the job FAIL The controlled helicopter has failed the delivery job because of a timeout or maybe because it crashed WIN The controlled helicopter has completed the delivery successfully NOCARGO The helicopter is not carrying any cargo CARGO id deadline cargo fx fy fz tx ty tz cost prize The helicopter is carrying cargo id identifies the delivery job All given data is just like with the JOB line At the beginning of the control connection either CARGO or NOCARGO will be sent as part of the first report Control Protocol Server to Client Intro Missions FREESTYLE The helicopter has no active mission MISSION tx ty tz Intro mission is active tx ty tz give the position of the target point in world coordinates MISSION tx ty tz Intro mission is active tx ty tz give the position of the next target point in world coordinates MISSION tx ty tz countdown Intro mission is active tx ty tz give the position of the target point in world coordinates countdown is an integer and indicates the number of remaining cycles for that the helicopter has to stay near the target so it starts at for seconds and goes to when the mission is completed ACCOMPLISHED The helicopter has accomplished the selected intro mission Control Protocol Client to Server Helicopter controls are updated on sent control lines When the client sends no control line in a cycle the controls stay in the previous position except on a crash or disconnect after which all controls are reset to zero collective pitch roll pedal Sending four numbers on a line updates the helicopter controls TAKE id Take on a delivery job id is an integer and identifies the job The controlled helicopter has to have no onboard cargo and has to be landed on the proper helipad If the job is taken successfully the proper updates will be sent on the next cycle ie CARGO and TAKEN JETTISON Drop current cargo The delivery job is failed and the cargo is lost MISSION number Try intro mission number is the intro mission number either or The helicopter has to be landed on a helipad If the mission is started successfully a MISSION line will be sent on the next cycle FREESTYLE Abort current intro mission Note that for each s cycle only the last of the given TAKE JETTISON MISSION FREESTYLE commands is processed although this shouldnt cause problems in normal operation Appendix Quaternions In the coordinate system of the helicopter the X axis points forward the Y axis to the left and the Z axis up The orientation of the helicopter with respect to the world coordinate system is represented by a unit quaternion qx qy qz qw The quaternion qxqyqz sinalpha u qw cosalpha represents the rotation where u is the unit length rotation axis and alpha is the rotation angle Formulas for calculating the roll pitch and yaw angles of the helicopter from a quaternion roll atanqwqx qyqz qxqx qyqy pitch asinqwqy qxqz yaw atanqwqz qxqy qyqy qzqz Formulas for rotating a vector v vxvyvz from the helicopter coordinate system to the world coordinate system t qwqx t qwqy t qwqz t qxqx t qxqy t qxqz t qyqy t qyqz t qzqz rotvx t tvx t tvy t tvz vx rotvy t tvx t tvy t tvz vy rotvz t tvx t tvy t tvz vz For example if v then rotv is the forward pointing unit vector in the world coordinate system The inverse rotation of a quaternion is qx qy qz qw Appendix Flight Dynamics The helicopter is modelled through a rigid body The forces applied to the body are gravity profile drag rotor blade drag and the control input forces In order to fly a helicopter one should master hovering first keeping the helicopter at a given position in a stable way Starting from a helipad in a straight position after increasing the lifting force above the helicopter weight using the collective it will take off The rotor blades have some drag so the helicopter will start rotating slowly yaw angle will increase which can be compensated by the tail rotor using the pedal A small control input is enough no need to apply full thrust The pedal input can be used to keep the helicopter looking at a specific direction or to turn to another direction The tail rotor applies a horizontal force at the tail so the helicopter will drift sideways slowly if you try to keep the direction in hovering Sideways or forward drift can be compensated by increasing the roll or pitch angles a bit Note that the control inputs are mapped to torques or forces so they control the acceleration not the exact angle or position Once the helicopter is leaning to some direction the main rotor no longer points exactly upwards so it starts pulling the helicopter sideways To maneuver the helicopter locally only small control inputs are needed except the collective which should approximately compensate the helicopter weight and small angle changes are enough To move forward a longer distance first direct the helicopter toward the destination then increase the pitch angle and the lifting force together the upward component of the lifting force should compensate the weight the forward pointing component will accelerate the helicopter in forward flight The speed of the helicopter is limited by the profile drag force which increases about the square of the velocity and points to the opposite direction of the velocity The helicopter shape is streamlined in such a way that when moving forward the drag is less than when moving sideways Fuel consumption is a complicated function of the control inputs and the current state See the following figures fuel consumption in vertical climb fuel consumption in forward level flight Appendix Flight Control For those who have no idea how to approach the helicopter motion control problem we give a hint This is not guaranteed to be the best solution though If the position x should be kept at some required value r and the control input is the acceleration or force a then a simple PD controller is sufficient At each iteration the control input is calculated as e r x deltae e preve preve e a kpe kddeltae for some nonnegative kp and kd constants e is the error term deltae is the error change rate Since r is fixed deltae can be replaced by the change rate of x which is velocity in case the velocity is already known For example such a controller is enough to keep the helicopter at a given angle around the z axis using the pedal input Of course the pedal control affects other parts of the dynamics as well not just the yaw angle but if the side effects are small then this simple approach might work