Jump to content

MAFman

Members
  • Posts

    328
  • Joined

  • Last visited

Everything posted by MAFman

  1. Where would I find the error log for kOS? Do I need to change any settings?
  2. @LAZYGLOBAL OFF. PARAMETER hdg, numberOfLengths. //use to find the initial bearing for the shortest path around a sphere from... FUNCTION CIRCLE_BEARING { PARAMETER p1, //...this point... p2. //...to this point. RETURN MOD(360 + ARCTAN2(SIN(p2:LNG - p1:LNG) * COS(p2:LAT), COS(p1:LAT) * SIN(p2:LAT) - SIN(p1:LAT) * COS(p2:LAT) * COS(p2:LNG - p1:LNG)), 360). } //use to find where you will end up if you travel from... FUNCTION CIRCLE_DESTINATION { PARAMETER p1, //...this point... b, // ...with this as your intitial bearing... d, // ...for this distance... r. // ...around a sphere of this radious. LOCAL lat IS ARCSIN(SIN(p1:LAT)*COS((d*180)/(r*CONSTANT:PI))+COS(p1:LAT)*SIN((d*180)/(r*CONSTANT:PI))*COS(b)). LOCAL lng IS 0. IF ABS(lat) <> 90 { SET lng TO p1:LNG+ARCTAN2(SIN(b)*SIN((d*180)/(r*CONSTANT:PI))*COS(p1:LAT),COS((d*180)/(r*CONSTANT:PI)) - SIN(p1:LAT)*SIN(lat)). } RETURN LATLNG(lat,lng). } //use to find the distance from... FUNCTION CIRCLE_DISTANCE { PARAMETER p1, //...this point... p2, //...to this point... radius. //...around a body of this radius. (note: if you are flying you may want to use ship:body:radius + altitude). LOCAL A IS SIN((p1:LAT - p2:LAT) / 2)^2 + COS(p1:LAT) * COS(p2:LAT) * SIN((p1:LNG-p2:LNG) / 2)^2. RETURN r * CONSTANT():PI * ARCTAN2(SQRT(A), SQRT(1 - A)) / 90. } //use to find the mid point on the outside of a sphere between... FUNCTION CIRCLE_MIDPOINT { PARAMETER p1, //...this point... p2. //...and this point. LOCAL A IS COS(p2:LAT) * COS(p2:LNG - p1:LNG). LOCAL B IS COS(p2:LAT) * SIN(p2:LNG - p1:LNG). RETURN LATLNG(ARCTAN2(SIN(p1:LAT) + SIN(p2:LAT), SQRT((COS(p1:LAT) + A)^2 + B^2)), p1:LNG+ARCTAN2(B, COS(p1:LAT) + A)). } FUNCTION THERE_YET { PARAMETER goal. IF CIRCLE_DISTANCE(point, goal, BODY:RADIUS) <= 20 { RETURN TRUE. } ELSE { RETURN FALSE. } } FUNCTION POPULATE { SET off_90 TO ((360 * 100) / (CONSTANT:PI * BODY:RADIUS * 2)). SET off_675 TO off_90 * SIN(67.5). SET off_45 TO off_90 * SIN(45). SET off_225 TO off_90 * SIN(22.5). SET a TO LATLNG(SHIP:GEOPOSITION:LAT + off_90, SHIP:GEOPOSITION:LNG). // North SET b TO LATLNG(SHIP:GEOPOSITION:LAT + off_675, SHIP:GEOPOSITION:LNG + off_225). // North-northeast SET c TO LATLNG(SHIP:GEOPOSITION:LAT + off_45, SHIP:GEOPOSITION:LNG + off_45). // Northeast SET d TO LATLNG(SHIP:GEOPOSITION:LAT + off_225, SHIP:GEOPOSITION:LNG + off_675). // East-northeast SET e TO LATLNG(SHIP:GEOPOSITION:LAT, SHIP:GEOPOSITION:LNG + off_90). // East SET f TO LATLNG(SHIP:GEOPOSITION:LAT - off_225, SHIP:GEOPOSITION:LNG + off_675). // East-southeast SET g TO LATLNG(SHIP:GEOPOSITION:LAT - off_45, SHIP:GEOPOSITION:LNG + off_45). // Southeast SET h TO LATLNG(SHIP:GEOPOSITION:LAT - off_675, SHIP:GEOPOSITION:LNG + off_225). // South-southeast SET i TO LATLNG(SHIP:GEOPOSITION:LAT - off_90, SHIP:GEOPOSITION:LNG). // South SET j TO LATLNG(SHIP:GEOPOSITION:LAT - off_675, SHIP:GEOPOSITION:LNG - off_225). // South-southwest SET k TO LATLNG(SHIP:GEOPOSITION:LAT - off_45, SHIP:GEOPOSITION:LNG - off_45). // Southwest SET l TO LATLNG(SHIP:GEOPOSITION:LAT - off_225, SHIP:GEOPOSITION:LNG - off_675). // West-southwest SET m TO LATLNG(SHIP:GEOPOSITION:LAT, SHIP:GEOPOSITION:LNG - off_90). // West SET n TO LATLNG(SHIP:GEOPOSITION:LAT + off_225, SHIP:GEOPOSITION:LNG - off_675). // West-northwest SET o TO LATLNG(SHIP:GEOPOSITION:LAT + off_45, SHIP:GEOPOSITION:LNG - off_45). // Northwest SET p TO LATLNG(SHIP:GEOPOSITION:LAT + off_675, SHIP:GEOPOSITION:LNG - off_225). // North-northwest SET options TO LIST(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p). RETURN options. } FUNCTION SLOPE_IS_SAFE { PARAMETER point. SET loc TO GEOPOSITION(point:LATITUDE, point:LONGITUDE). SET curPos TO SHIP:GEOPOSITION. SET slope TO ABS(ARCTAN2((loc:TERRAINHEIGHT - curPos:TERRAINHEIGHT), 100)). IF slope < 15 { RETURN TRUE. } ELSE { RETURN FALSE. } } FUNCTION BEARING_IS_REASONABLE { PARAMETER point, goal. SET brg TO ABS(goal:BEARING - point:BEARING). IF brg < 60 { RETURN TRUE. } ELSE { RETURN FALSE. } } FUNCTION DECIDE_NEXT { PARAMETER options, goal. FOR o IN options { IF SLOPE_IS_SAFE(o) AND BEARING_IS_REASONABLE(point, goal) { SET nextPoint TO LATLNG(o:LAT, o:LNG). RETURN nextPoint. } } } FUNCTION DRIVE_TO { PARAMETER point. SET spd TO 5. SET loopT TO 0.01. SET loopEndT TO TIME:SECONDS. UNTIL arrived(point) { // PI controller for speed SET pWT TO spd - GROUNDSPEED. SET iWT TO MIN(1, MAX(-1, iWT + (pWT * loopT))). SET wtVal TO pWT + iWT. // Proportional control for heading SET pSteer TO COMPASS_FOR(SHIP) - point:HEADING. SET steerVal TO (pSteer / 180). // Now write the outputs to the physical systems. LOCK WHEELTHROTTLE TO wtVal. LOCK WHEELSTEER TO steerVal. SET loopT TO TIME:SECONDS - loopEndT. SET loopEndT TO TIME:SECONDS. } } GLOBAL v IS SHIP:ALTITUDE. GLOBAL r IS BODY:RADIUS. GLOBAL point IS SHIP:GEOPOSITION. GLOBAL radioHorizon IS SQRT((R+v)^2 - (R^2)). GLOBAL dist IS (360 * (0.95 * radioHorizon * numberOfLengths)) / (2 * CONSTANT:PI * BODY:RADIUS). GLOBAL goal IS CIRCLE_DESTINATION(point, hdg, dist, R). UNTIL THERE_YET(goal) { POPULATE(). DECIDE_NEXT(options, goal). DRIVE_TO(nextPoint). WAIT 5. BRAKES OFF. } LOCK WHEELSTEER TO 0. LOCK WHEELTHROTTLE TO -1. WAIT UNTIL GROUNDSPEED < 1. UNLOCK ALL. BRAKES ON. I'm stumped... Can you give me any feedback as to how to get this to work? To test it, just put the script on a generic rover and give the kOS terminal the command "RUN autonav(270,1).
  3. It drives in circles. Also, I made a new version, but it won't run at all... The error it gives me is "the given key is not in the dictionary". @LAZYGLOBAL OFF. PARAMETER hdg, numberOfLengths. //use to find the initial bearing for the shortest path around a sphere from... FUNCTION CIRCLE_BEARING { PARAMETER p1, //...this point... p2. //...to this point. RETURN MOD(360 + ARCTAN2(SIN(p2:LNG - p1:LNG) * COS(p2:LAT), COS(p1:LAT) * SIN(p2:LAT) - SIN(p1:LAT) * COS(p2:LAT) * COS(p2:LNG - p1:LNG)), 360). } //use to find where you will end up if you travel from... FUNCTION CIRCLE_DESTINATION { PARAMETER p1, //...this point... b, // ...with this as your intitial bearing... d, // ...for this distance... radius. // ...around a sphere of this radious. LOCAL lat IS ARCSIN(SIN(p1:LAT)*COS((d*180)/(radius*CONSTANT():PI))+COS(p1:LAT)*SIN((d*180)/(radius*CONSTANT():PI))*COS(b)). LOCAL lng IS 0. IF ABS(lat) <> 90 { SET lng TO p1:LNG+ARCTAN2(SIN(b)*SIN((d*180)/(radius*CONSTANT():PI))*COS(p1:LAT),COS((d*180)/(radius*CONSTANT():PI)) - SIN(p1:LAT)*SIN(lat)). } RETURN LATLNG(lat,lng). } //use to find the distance from... FUNCTION CIRCLE_DISTANCE { PARAMETER p1, //...this point... p2, //...to this point... radius. //...around a body of this radius. (note: if you are flying you may want to use ship:body:radius + altitude). LOCAL A IS SIN((p1:LAT - p2:LAT) / 2)^2 + COS(p1:LAT) * COS(p2:LAT) * SIN((p1:LNG-p2:LNG) / 2)^2. RETURN radius * CONSTANT():PI * ARCTAN2(SQRT(A), SQRT(1 - A)) / 90. } //use to find the mid point on the outside of a sphere between... FUNCTION CIRCLE_MIDPOINT { PARAMETER p1, //...this point... p2. //...and this point. LOCAL A IS COS(p2:LAT) * COS(p2:LNG - p1:LNG). LOCAL B IS COS(p2:LAT) * SIN(p2:LNG - p1:LNG). RETURN LATLNG(ARCTAN2(SIN(p1:LAT) + SIN(p2:LAT), SQRT((COS(p1:LAT) + A)^2 + B^2)), p1:LNG+ARCTAN2(B, COS(p1:LAT) + A)). } FUNCTION THERE_YET { PARAMETER goal. IF CIRCLE_DISTANCE(point, goal, BODY:RADIUS) <= 20 { RETURN TRUE. } ELSE { RETURN FALSE. } } FUNCTION POPULATE { SET off_90 TO ((360 * 100) / (CONSTANT:PI * BODY:RADIUS * 2)). SET off_675 TO off_90 * SIN(67.5). SET off_45 TO off_90 * SIN(45). SET off_225 TO off_90 * SIN(22.5). SET a TO LATLNG(SHIP:GEOPOSITION:LAT + off_90, SHIP:GEOPOSITION:LNG). // North SET b TO LATLNG(SHIP:GEOPOSITION:LAT + off_675, SHIP:GEOPOSITION:LNG + off_225). // North-northeast SET c TO LATLNG(SHIP:GEOPOSITION:LAT + off_45, SHIP:GEOPOSITION:LNG + off_45). // Northeast SET d TO LATLNG(SHIP:GEOPOSITION:LAT + off_225, SHIP:GEOPOSITION:LNG + off_675). // East-northeast SET e TO LATLNG(SHIP:GEOPOSITION:LAT, SHIP:GEOPOSITION:LNG + off_90). // East SET f TO LATLNG(SHIP:GEOPOSITION:LAT - off_225, SHIP:GEOPOSITION:LNG + off_675). // East-southeast SET g TO LATLNG(SHIP:GEOPOSITION:LAT - off_45, SHIP:GEOPOSITION:LNG + off_45). // Southeast SET h TO LATLNG(SHIP:GEOPOSITION:LAT - off_675, SHIP:GEOPOSITION:LNG + off_225). // South-southeast SET i TO LATLNG(SHIP:GEOPOSITION:LAT - off_90, SHIP:GEOPOSITION:LNG). // South SET j TO LATLNG(SHIP:GEOPOSITION:LAT - off_675, SHIP:GEOPOSITION:LNG - off_225). // South-southwest SET k TO LATLNG(SHIP:GEOPOSITION:LAT - off_45, SHIP:GEOPOSITION:LNG - off_45). // Southwest SET l TO LATLNG(SHIP:GEOPOSITION:LAT - off_225, SHIP:GEOPOSITION:LNG - off_675). // West-southwest SET m TO LATLNG(SHIP:GEOPOSITION:LAT, SHIP:GEOPOSITION:LNG - off_90). // West SET n TO LATLNG(SHIP:GEOPOSITION:LAT + off_225, SHIP:GEOPOSITION:LNG - off_675). // West-northwest SET o TO LATLNG(SHIP:GEOPOSITION:LAT + off_45, SHIP:GEOPOSITION:LNG - off_45). // Northwest SET p TO LATLNG(SHIP:GEOPOSITION:LAT + off_675, SHIP:GEOPOSITION:LNG - off_225). // North-northwest SET options TO LIST(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p). RETURN options. } FUNCTION SLOPE_IS_SAFE { PARAMETER point. SET loc TO GEOPOSITION(point:LATITUDE, point:LONGITUDE). SET curPos TO SHIP:GEOPOSITION. SET slope TO ABS(ARCTAN2((loc:TERRAINHEIGHT - curPos:TERRAINHEIGHT), 100)). IF slope < 15 { RETURN TRUE. } ELSE { RETURN FALSE. } } FUNCTION BEARING_IS_REASONABLE { PARAMETER point, goal. SET brg TO ABS(goal:BEARING - point:BEARING). IF brg < 60 { RETURN TRUE. } ELSE { RETURN FALSE. } } FUNCTION DECIDE_NEXT { PARAMETER options, goal. FOR o IN options { IF SLOPE_IS_SAFE(o) AND BEARING_IS_REASONABLE(point, goal) { SET nextPoint TO LATLNG(o:LAT, o:LNG). RETURN nextPoint. } } } FUNCTION DRIVE_TO { PARAMETER point. SET spd TO 5. SET loopT TO 0.01. SET loopEndT TO TIME:SECONDS. UNTIL arrived(point) { SET pWT TO spd - GROUNDSPEED. SET iWT TO MIN(1, MAX(-1, iWT + (pWT * loopT))). LOCK WHEELTHROTTLE TO pWT + iWT. SET pSteer TO COMPASS_FOR(SHIP) - point:HEADING. LOCK WHEELSTEER TO (pSteer / 180). SET loopT TO TIME:SECONDS - loopEndT. SET loopEndT TO TIME:SECONDS. } LOCK WHEELSTEER TO 0. LOCK WHEELTHROTTLE TO -1. WAIT UNTIL GROUNDSPEED < 1. UNLOCK ALL. BRAKES ON. } SET h TO SHIP:ALTITUDE. SET R TO BODY:RADIUS. SET point TO SHIP:GEOPOSITION. SET radioHorizon TO SQRT((R+h)^2 - (R^2)). SET dist TO (360 * (radioHorizon * numberOfLengths)) / (2 * CONSTANT:PI * BODY:RADIUS). SET goal TO CIRCLE_DESTNATION(point, hdg, dist, R). UNTIL arrived(goal) { POPULATE(). DECIDE_NEXT(options, goal). DRIVE_TO(nextPoint). WAIT 5. BRAKES OFF. } LOCK WHEELSTEER TO 0. LOCK WHEELTHROTTLE TO -1. WAIT UNTIL GROUNDSPEED < 1. UNLOCK ALL. BRAKES ON.
  4. Not sure whether this is the right forum, but I'm stumped on an autonavigation script I'm trying to develop for kOS. The waypoint selection code works fine, but I can't seem to actually get the rover to drive to the waypoint...help? Code is below. CLEARSCREEN. SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0. LOCK THROTTLE TO 0. SWITCH TO 0. RUN autolights. RCS OFF. SAS OFF. GEAR OFF. // My plan for autonomous navigation is an iterative algorithm. // The goal is a LATLNG() that is calculated // from the input parameter hdg in degrees clockwise from north. PARAMETER hdg, horizonMultiplier. AUTOLIGHTS(). SET dist TO SQRT((BODY:RADIUS + ALTITUDE)^2 - (BODY:RADIUS ^ 2)). // Radio horizon calculation SET distLat TO (horizonMultiplier * dist) * COS(hdg). // X offset = a multiple of the x unit vector SET distLng TO (horizonMultiplier * dist) * SIN(hdg). // Y offset = a multiple of the y unit vector SET offSetLat TO (360 * (distLat * 0.9)) / (2 * BODY:RADIUS * CONSTANT:PI). // The difference in latitude caused by moving x meters north or south SET offSetLng TO (360 * (distLng * 0.9)) / (2 * BODY:RADIUS * CONSTANT:PI). // The difference in longitude caused by moving y meters east or west SET startPos TO SHIP:GEOPOSITION. SET goal TO LATLNG(SHIP:GEOPOSITION:LAT + offSetLat, SHIP:GEOPOSITION:LNG + offSetLng). // The current position plus the offset // First the script checks to see whether it has reached the goal. FUNCTION THERE_YET { PARAMETER goal. IF goal:DISTANCE < 1 { RETURN TRUE. } ELSE { RETURN FALSE. } } // Next, it creates a list of waypoints set 5m away FUNCTION POPULATE { SET offSetA TO (360 * 100) / (BODY:RADIUS * 2 * CONSTANT:PI). SET offSetB TO offSetA * SIN(45). SET optionA TO LATLNG(startPos:LAT + offSetA, startPos:LNG). // N SET optionB TO LATLNG(startPos:LAT + offSetB, startPos:LNG + offSetB). // NE SET optionC TO LATLNG(startPos:LAT, startPos:LNG + offSetA). // E SET optionD TO LATLNG(startPos:LAT - offSetB, startPos:LNG - offSetB). // NW SET optionE TO LATLNG(startPos:LAT - offSetA, startPos:LNG). // S SET optionF TO LATLNG(startPos:LAT - offSetB, startPos:LNG + offSetB). // SW SET optionG TO LATLNG(startPos:LAT, startPos:LNG - offSetA). // W SET optionH TO LATLNG(startPos:LAT + offSetB, startPos:LNG - offSetB). // NW SET options TO LIST(optionA, optionB, optionC, optionD, optionF, optionG, optionH). PRINT("Deciding options...done.") AT (1,1). RETURN options. } // Then, it defines two helper functions - one for slope... FUNCTION SLOPE_IS_SAFE { PARAMETER option. SET location TO SHIP:GEOPOSITION. SET newHeight TO option:TERRAINHEIGHT. SET slope TO ABS(ARCTAN2((newHeight - location:TERRAINHEIGHT), 1000)). IF slope < 20 {RETURN TRUE.} ELSE {RETURN FALSE.} } // ...and one for bearing difference. FUNCTION ANGLE_IS_OK { PARAMETER goal, option. SET angle TO ABS(goal:BEARING - option:BEARING). IF angle < 60 {RETURN TRUE.} ELSE {RETURN FALSE.} } // Next, the function iterates through the list of points and evaluates the conditions. // It picks the first point that matches both FUNCTION DECIDE_NEXT { PARAMETER goal, options. PRINT("Iterating through options.") AT (1,2). FOR o IN options { IF SLOPE_IS_SAFE(o) AND ANGLE_IS_OK(goal, o) { SET nextPoint TO LATLNG(o:LAT, o:LNG). RETURN nextPoint. } } } // Finally, it drives there using PID steering and throttle. // How do I do this?!? FUNCTION DRIVE { PARAMETER p. SET desiredSpd TO 5. SET pWT TO 0. SET iWT TO 0. SET wtVAL TO 0. SET pSteer TO 0. SET iSteer TO 0. SET dSteer TO 0. SET lastPSteer TO 0. SET loopT TO 0.01. SET loopEndT TO TIME:SECONDS. SET NORTHPOLE TO LATLNG(90,0). UNTIL p:DISTANCE < 10 { SET pWT TO desiredSpd - GROUNDSPEED. SET iWT TO MIN(1, MAX(-1, iWT + (pWT * loopT))). SET wtVAL TO pWT + iWT. SET pSteer TO (p:BEARING / 180). SET dSteer TO (pSteer - lastPSteer) / (loopEndT - loopT). SET steerVAL TO -0.5 * pSteer + 0.75 * dSteer. SET lastPSteer TO pSteer. LOCK WHEELTHROTTLE TO wtVAL. LOCK WHEELSTEER TO steerVAL. PRINT("Target heading: " + p:HEADING) AT (1,1). PRINT("Bearing to target: " + p:BEARING) AT (1,2). SET lastPSteer TO pSteer. SET loopT TO TIME:SECONDS - loopEndT. SET loopEndT TO TIME:SECONDS. } } UNTIL THERE_YET(goal) { BRAKES ON. WAIT 1. POPULATE(). WAIT 1. DECIDE_NEXT(goal, options). WAIT 1. CLEARSCREEN. BRAKES OFF. DRIVE(nextPoint). UNLOCK ALL. LOCK THROTTLE TO -1. WAIT UNTIL GROUNDSPEED < 0.25. BRAKES ON. WAIT 1. UNLOCK ALL. } UNLOCK ALL. LOCK THROTTLE TO -1. WAIT UNTIL GROUNDSPEED < 0.25. BRAKES ON. SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0. UNLOCK ALL.
  5. Gah! I don't know what I did, but now it crashes KSP... time to start over... Can someone help me develop this? I need a kOS program that takes a LATLNG and iteratively navigates to it. Steps of the iteration:
  6. UPDATE: Found the bug! // Auto Nav // Takes a LATLNG() of a goal, and iteratively navigates to it. PARAMETER goal. FUNCTION POPULATE { SET pos TO LATLNG(SHIP:GEOPOSITION:LAT, SHIP:GEOPOSITION:LNG). SET a TO 360000/(2*CONSTANT:PI*BODY:RADIUS). // 10m in any cardinal direction SET b TO SIN(45)*a. SET oA TO LATLNG(pos:LAT + a, pos:LNG). // North SET oB TO LATLNG(pos:LAT + B, pos:LNG + b). // Northeast SET oC TO LATLNG(pos:LAT, pos:LNG + a). // East SET oD TO LATLNG(pos:LAT - b, pos:LNG + b). // Southeast SET oE TO LATLNG(pos:LAT - a, pos:LNG). // South SET oF TO LATLNG(pos:LAT - b, pos:LNG - b). // Southwest SET oG TO LATLNG(pos:LAT, pos:LNG - a). //West SET oH TO LATLNG(pos:LAT + b, pos:LNG - b). // Northwest SET options TO LIST(oA, oB, oC, oD, oE, oF, oG, oH). RETURN options. } FUNCTION SLOPE_IS_OK { PARAMETER point. SET location TO LATLNG(point:LAT, point:LNG). SET slope TO ABS(ARCTAN2((location:TERRAINHEIGHT - SHIP:ALTITUDE), 10)). IF slope < 11.25 { RETURN TRUE. } ELSE { RETURN FALSE. } } FUNCTION ANGLE_IS_OK { PARAMETER point, goal. SET angle TO ABS(goal:BEARING - point:BEARING). IF angle < 45 { RETURN TRUE. } ELSE { RETURN FALSE. } } FUNCTION DECIDE_NEXT { PARAMETER options, goal. FOR o IN options { IF SLOPE_IS_OK(o) AND ANGLE_IS_OK(goal, o) { SET nextPoint TO LATLNG(o:LAT, o:LNG). RETURN nextPoint. BREAK. } ELSE { // Just keep swimming... } } } FUNCTION DRIVE { PARAMETER waypt. CLEARSCREEN. SET spd TO 10. SET hdg TO waypt:HEADING. SET loopT TO 0.01. SET loopEndT TO TIME:SECONDS. SET pWT TO 0. SET iWT TO 0. SET dWT TO 0. SET lastPWT TO 0. SET eSteer TO 0. SET dSteer TO 0. SET lastESteer TO 0. SET wtVal TO 0. SET NORTHPOLE TO LATLNG(90,0). SET runmode TO 0. IF waypt:DISTANCE < 5 { BRAKES ON. SET runmode TO -1. } UNTIL runmode = -1 { IF NORTHPOLE:BEARING <= 0 { set cHdg TO ABS(NORTHPOLE:BEARING). } ELSE { SET cHdg TO (180 - NORTHPOLE:BEARING) + 180. } IF runmode = 0 { SET pWT TO spd - GROUNDSPEED. SET iWT TO MIN(1, MAX(-1, iWT + (pWT * loopT))). SET dWT TO ((pWT - lastPWT) / (loopEndT - loopT)). SET wtVal TO MIN(1, MAX(-1, pWT + iWT + dWT)). SET eSteer TO (hdg - cHdg) / 180. SET dSteer TO ((eSteer - lastESteer)/(loopEndT - loopT)). SET steerVal TO -eSteer + dSteer. SET SHIP:CONTROL:WHEELTHROTTLE TO wtVal. SET SHIP:CONTROL:WHEELSTEER TO steerVal. SET lastPWT TO pWT. SET lastESteer TO eSteer. SET loopT TO TIME:SECONDS - loopEndT. SET loopEndT TO TIME:SECONDS. } PRINT("pWT: " + pWT) AT (2, 5). PRINT("iWT: " + iWT) AT (2, 6). PRINT("dWT: " + dWT) AT (2,7). PRINT("eSteer: " + eSteer) AT (2, 9). PRINT("steerVal: " + steerVal) AT (2,10). } } UNTIL goal:DISTANCE < 5 { POPULATE(). DECIDE_NEXT(options, goal). DRIVE(nextPoint). BRAKES ON. WAIT 5. BRAKES OFF. } BRAKES ON.
  7. Ok, fixed the driving-in-circles thing. Now it just drives backward and doesn't control the steering or throttle at all! I think the decision-making algorithm works, though... // Auto Nav // Takes a LATLNG() of a goal, and iteratively navigates to it. PARAMETER goal. GEAR OFF. LOCK THROTTLE TO 0. SAS OFF. RCS OFF. BRAKES ON. FUNCTION POPULATE { SET pos TO LATLNG(SHIP:GEOPOSITION:LAT, SHIP:GEOPOSITION:LNG). SET a TO (360 * 1000)/(2*CONSTANT:PI*BODY:RADIUS). // 10m in any cardinal direction SET b TO SIN(45)*a. SET oA TO LATLNG((pos:LAT + a), (pos:LNG)). // North SET oB TO LATLNG((pos:LAT + b), (pos:LNG + b)). // Northeast SET oC TO LATLNG((pos:LAT), (pos:LNG + a)). // East SET oD TO LATLNG((pos:LAT - b), (pos:LNG + b)). // Southeast SET oE TO LATLNG((pos:LAT - a), (pos:LNG)). // South SET oF TO LATLNG((pos:LAT - b), (pos:LNG - b)). // Southwest SET oG TO LATLNG((pos:LAT), (pos:LNG - a)). //West SET oH TO LATLNG((pos:LAT + b), (pos:LNG - b)). // Northwest SET options TO LIST(oA, oB, oC, oD, oE, oF, oG, oH). RETURN options. } FUNCTION SLOPE_IS_OK { PARAMETER point. SET location TO LATLNG(point:LAT, point:LNG). SET slope TO ABS(ARCTAN2((location:TERRAINHEIGHT - SHIP:ALTITUDE), 10)). IF slope < 11.25 { RETURN TRUE. } ELSE { RETURN FALSE. } } FUNCTION ANGLE_IS_OK { PARAMETER point, goal. SET angle TO ABS(goal:BEARING - point:BEARING). IF angle < 45 { RETURN TRUE. } ELSE { RETURN FALSE. } } FUNCTION DECIDE_NEXT { PARAMETER options, goal. FOR o IN options { IF SLOPE_IS_OK(o) AND ANGLE_IS_OK(goal, o) { SET nextPoint TO LATLNG(o:LAT, o:LNG). RETURN nextPoint. BREAK. } ELSE { // Just keep swimming... } } } FUNCTION DRIVE { PARAMETER waypt. SET spd TO 5. SET loopT TO 0.01. SET loopEndT TO TIME:SECONDS. SET eWT TO 0. SET iWT TO 0. SET wtVAL TO 0. SET NORTHPOLE TO LATLNG(90,0). SET eSteer TO 0. LOCK turnLimit TO MIN(1, 1.5/GROUNDSPEED). UNTIL waypt:DISTANCE < 2.5 { IF NORTHPOLE:BEARING <= 0 { SET cHead TO ABS(NORTHPOLE:BEARING). } ELSE { SET cHead TO (180 - NORTHPOLE:BEARING) + 180. } SET wtVAL TO MIN(1, MAX(-1, (-eWT + iWT))). SET eSteer TO (hdg - cHead). IF eSteer > 180 { //Make sure the headings make sense SET eSteer TO eSteer - 360. } ELSE IF eSteer < -180 { SET eSteer TO eSteer + 360. } IF spd - GROUNDSPEED > spd + spd * 0.1 // We're too fast! { LOCK THROTTLE TO -1. } ELSE IF GROUNDSPEED < spd - spd * 0.1 { LOCK THROTTLE TO 1. } SET desiredSteering TO -eSteer / 10. set kturn to min(1, max( -1, desiredSteering)). SET SHIP:CONTROL:WHEELSTEER TO kTurn. PRINT("Distance to waypoint: " + ROUND(waypt:DISTANCE, 2)) AT (2, 21). PRINT("Wheel Throttle: " + wtVAL) AT (2,22). SET loopT TO TIME:SECONDS - loopEndT. SET loopEndT TO TIME:SECONDS. } } UNTIL goal:DISTANCE < 50 { IF SHIP:SENSORS:LIGHT < 0.75 { LIGHTS ON. } ELSE { LIGHTS OFF. } CLEARSCREEN. POPULATE(). PRINT("=====Autonavigation v1.0=====") AT (0,2). PRINT("Populating options...") AT (2,5). WAIT 1. PRINT("Options: " + ROUND(oA:LAT, 5) + ", " + ROUND(oA:LNG, 2)) AT (2,10). PRINT(ROUND(oB:LAT, 5) + ", " + ROUND(oB:LNG, 2)) AT (11,11). PRINT(ROUND(oC:LAT, 5) + ", " + ROUND(oC:LNG, 2)) AT (11,12). PRINT(ROUND(oD:LAT, 5) + ", " + ROUND(oD:LNG, 2)) AT (11,13). PRINT(ROUND(oE:LAT, 5) + ", " + ROUND(oE:LNG, 2)) AT (11,14). PRINT(ROUND(oF:LAT, 5) + ", " + ROUND(oF:LNG, 2)) AT (11,15). PRINT(ROUND(oG:LAT, 5) + ", " + ROUND(oG:LNG, 2)) AT (11,16). PRINT(ROUND(oH:LAT, 5) + ", " + ROUND(oH:LNG, 2)) AT (11,17). WAIT 1. DECIDE_NEXT(options, goal). PRINT("Driving to " + "(" + ROUND(nextPoint:LAT,5) + ", " + ROUND(nextPoint:LNG, 5) + ")") AT (2,20). BRAKES OFF. IF nextPoint:BEARING > 20 { LOCK WHEELSTEER TO nextPoint. LOCK WHEELTHROTTLE TO -0.5. WAIT UNTIL nextPoint:BEARING < 30. } DRIVE(nextPoint). BRAKES ON. WAIT 5. BRAKES OFF. } BRAKES ON.
  8. I've been having trouble with my roverDriver script again...My rover keeps driving in a left-handed circle probably 20m in radius... I got it to return no errors this time though! Here's my code... // Auto Nav // Takes a LATLNG() of a goal, and iteratively navigates to it. PARAMETER goal. FUNCTION POPULATE { SET pos TO LATLNG(SHIP:GEOPOSITION:LAT, SHIP:GEOPOSITION:LNG). SET a TO 3600/(2*CONSTANT:PI*BODY:RADIUS). // 10m in any cardinal direction SET b TO SIN(45)*a. SET oA TO LATLNG(pos:LAT + a, pos:LNG). // North SET oB TO LATLNG(pos:LAT + B, pos:LNG + b). // Northeast SET oC TO LATLNG(pos:LAT, pos:LNG + a). // East SET oD TO LATLNG(pos:LAT - b, pos:LNG + b). // Southeast SET oE TO LATLNG(pos:LAT - a, pos:LNG). // South SET oF TO LATLNG(pos:LAT - b, pos:LNG - b). // Southwest SET oG TO LATLNG(pos:LAT, pos:LNG - a). //West SET oH TO LATLNG(pos:LAT + b, pos:LNG - b). // Northwest SET options TO LIST(oA, oB, oC, oD, oE, oF, oG, oH). RETURN options. } FUNCTION SLOPE_IS_OK { PARAMETER point. SET location TO LATLNG(point:LAT, point:LNG). SET slope TO ABS(ARCTAN2((location:TERRAINHEIGHT - SHIP:ALTITUDE), 10)). IF slope < 11.25 { RETURN TRUE. } ELSE { RETURN FALSE. } } FUNCTION ANGLE_IS_OK { PARAMETER point, goal. SET angle TO ABS(goal:BEARING - point:BEARING). IF angle < 45 { RETURN TRUE. } ELSE { RETURN FALSE. } } FUNCTION DECIDE_NEXT { PARAMETER options, goal. FOR o IN options { IF SLOPE_IS_OK(o) AND ANGLE_IS_OK(goal, o) { SET nextPoint TO LATLNG(o:LAT, o:LNG). RETURN nextPoint. BREAK. } ELSE { // Just keep swimming... } } } FUNCTION DRIVE { PARAMETER waypt. SET spd TO 10. SET hdg TO waypt:HEADING. SET loopT TO 0.01. SET loopEndT TO TIME:SECONDS. SET pWT TO 0. SET iWT TO 0. SET dWT TO 0. SET lastPWT TO 0. SET wtVal TO 0. SET NORTHPOLE TO LATLNG(90,0). SET runmode TO 0. IF waypt:DISTANCE < 5 { BRAKES ON. SET runmode TO -1. } UNTIL runmode = -1 { IF NORTHPOLE:BEARING <= 0 { set cHdg TO ABS(NORTHPOLE:BEARING). } ELSE { SET cHdg TO (180 - NORTHPOLE:BEARING) + 180. } IF runmode = 0 { SET pWT TO spd - GROUNDSPEED. SET iWT TO MIN(1, MAX(-1, iWT + (pWT * loopT))). SET dWT TO ((pWT - lastPWT) / (loopEndT - loopT)). SET wtVal TO MIN(1, MAX(-1, pWT + iWT + dWT)). SET SHIP:CONTROL:WHEELTHROTTLE TO wtVal. SET SHIP:CONTROL:WHEELSTEER TO hdg. SET loopT TO TIME:SECONDS - loopEndT. SET loopEndT TO TIME:SECONDS. } } } UNTIL goal:DISTANCE < 5 { POPULATE(). DECIDE_NEXT(options, goal). DRIVE(nextPoint). BRAKES ON. WAIT 5. BRAKES OFF. } BRAKES ON.
  9. The link to your code is broken... Can you post your raw code in a spoiler tag?
  10. I just got done copying Seth Persigehl's rover.ks script to try to adapt it, but I'm stuck...How do I properly implement a PID for both wheel steering and wheel throttle, to maintain constant speed and heading? Also, can someone explain how to use boot scripts to do things like displaying info with HUDTEXT()?
  11. RasterPropMonitor does provide a readout if you have VesselView installed. It gives you a realtime schematic view of your ship.
  12. I'm working on a rover control library that implements a generic PID library. The thing I'm kind of stuck on is automatic navigation, either dynamic (paying attention to bearing to target and terrain slope), or manual (like Seth Persigehl's rover script).
  13. Recently, I got hooked on the kOS mod, which implements coding in KSP. I'm currently developing methods of rover control, both manual and automatic. I'd appreciate any and all ideas / suggestions / whatever!
  14. A bit too math-y for my overtired mind at the moment, but I like that idea, and I'll have to investigate later! Can you help me update the code so it works in 1.1.4 or whatever the current KSP version is, and so that I can just input a latitude and longitude pair for the waypoints instead of needing to use vessels?
  15. I'm trying to think of/design a rover driver script that senses terrain slope in all directions 10m away and continuously navigates to a goal LATLNG() while avoiding steep slopes. Can someone help me with this?
  16. Hey, can someone help me create an autonavigation script for rovers? It's supposed to keep speed constant, drive toward waypoints, and (this is the hard part) set its own waypoints intelligently based on traversability and how close each option is to a user-defined target latlng(). Something like DRIVE_TO_GOAL(145.02873, -0.04968).
  17. Is it possible to make a kind of Curiosity-like autonav algorithm for rovers? If so, what would be used to measure terrain roughness/height and safety?
  18. How do I use the rocket equation for a specific destination requiring a certain delta-v if I know nothing but the dV and the mass of my payload?
  19. Not sure if this is a bug report or a "my computer sucks" report, but I simply cannot get Realism Overhaul to load. Either my KSP crashes, freezes on a black start screen with the "loading" thing spinning, or my whole computer goes down. Specs: i5 @2.7GHz 8GB 1333 DDR3 RAM generic SSD Integrated graphics :rolleyes: Integrated audo + crap speaker 1366*768 laptop monitor Usually have YouTube open in another window.
  20. I've been developing an MM config over the last few days, that gives each engine the stats of a real engine whose stats are closest to it (if that made sense). The point is to nerf what needs nerfing and buff what needs buffing, and to again, standardize. Below is my config: [CODE] // Tiny engines first @PART[ionEngine] //NEXT { @MODULE[ModuleEnginesFX] { @maxThrust = 0.03 @PROPELLANT[ElectricCharge] { @ratio = 1 } @PROPELLANT[XenonGas] { @ratio = 0.0625 } } } @PART[radialEngineMini] //MSL descent engines { @mass = 0.01 //10 kg for a twr around 50 @MODULE[ModuleEnginesFX] { @maxThrust = 5 //slightly more powerful than the msl engine } } @PART[smallRadialEngine] //SuperDraco { @mass = 0.07125 //TWR around 50 @MODULE[ModuleEnginesFX] { @maxThrust = 75 //rounded up from real stats } } @PART[microEngine] //Can't find an engine { @mass = @MODULE[ModuleEnginesFX] { @maxThrust = } } //Now to standardize the bigger engines' TWR's at 80*0.64 = ~50 @PART[]//LV-909 = TR-201 //The dimensions of the engine are 2.27m long by 1.38m diam. //That makes it a 1.25m part that is 2m tall. { @mass = 0.115 //actual mass @MODULE[ModuleEnginesFX] { @maxThrust = 40 //rounded actual thrust } } @PART[]//LV-T30 = LE-5B-2 //This part is 2.79m tall IRL. I'll round that up to 2.8m. { @mass = 0.29 //actual mass @MODULE[ModuleEnginesFX] { @maxThrust = 145 //actual thrust } } @PART[liquidEngine2]//LV-T45 = LE-5 //This part is 2.68m tall IRL. I'll round that up to 2.7m { @mass = 0.255 //actual mass @MODULE[ModuleEnginesFX] { @maxThrust = 105 //actual thrust } } @PART[]//"Skipper" = Merlin 1D { @mass = 0.6 //actual mass @MODULE[ModuleEnginesFX] { @maxThrust = 480 //actual thrust } } @PART[]//"MainSail" = Raptor { @mass = 0.29 //actual mass @MODULE[ModuleEnginesFX] { @maxThrust = 840 //10% actual thrust - the Raptor is way OP } } //Now for the SRB's...must...standardize...boosters... @PART[sepMotor1] { @mass = 0.01 //10 kg empty. I could easily pick this one up and throw it! @MODULE[ModuleEngines] { @maxThrust = 100 } @RESOURCE[SolidFuel] { @amount = 5 @maxAmount = 5 } } @PART[solidBooster_sm] { @mass = 0.1 //only 100 kg empty - must be made of tinfoil @MODULE[ModuleEngines] { @maxThrust = 30 } @RESOURCE[SolidFuel] { @amount = 15 @maxAmount = 15 } } @PART[solidBooster] { @mass = 1 //just the casing @MODULE[ModuleEngines] { @maxThrust = 300 } @RESOURCE[SolidFuel] { @amount = 300 @maxAmount = 300 } } @PART[solidBooster1-1] { @mass = 3 @MODULE[ModuleEngines] { @maxThrust = 600 } @RESOURCE[SolidFuel] { @amount = 900 @maxAmount = 900 } } [/CODE] Trouble is, I can't seem to find a real analog for the LV-1 (that has pictures of it, and stats that aren't either classified or lost)... What should the analog be?
  21. So I found an odd bug...KSP loads most of the way, then does a weird black-screen-thing... [url]https://drive.google.com/file/d/0B1BXLWa5LPIMSkxJYXpZVWJzZjg/view[/url] [url]https://drive.google.com/file/d/0B1BXLWa5LPIMQUNWdEZXRmR6VEE/view[/url]
  22. Can you teach me how this works so I can help you improve / fix / recompile it?[quote name='NathanKell']Updated version of ialdabaoth's (who is awesome) ModuleRCSFX. ModuleRCSFX *fixes the major known issues with the stock RCS Module (ModuleRCS) *Supports some advanced features (axis restriction, full thrust, scaling). *Supports EFFECTS (well, it will--currently broken) [size=3]Installation: Extract to GameData (creating a ModuleRCSFX folder, and inside that, Plugins and the readme.[/size] [size=4][url=https://github.com/NathanKell/ModuleRCSFX/releases/download/v4.2/ModuleRCSFX_v4.2.zip]Download[/url] [url=https://github.com/NathanKell/ModuleRCSFX]GitHub[/url][/size] License: CC-BY-SA (with the ialdabaoth proviso, that all forkers must remark upon his awesomeness...which I'd do anyway). From the readme: ModuleRCSFX is a fixed version of the stock RCS module. It is derived from ModuleRCSFX by ialdabaoth (who is awesome). It supports a lot of configuration, as well as fixing stock bugs. ** RCS Part Controls ** useZaxis defaults to false. If you set it to true, the RCS will fire along the Z axis of the given transform(s). This means you can use engine part models as RCS parts (like using the ion engine model as an RCS part). ** RCS Axis Control ** enablePitch enableYaw enableRoll enableX enableY enableZ All these default to true, but if one is set to false in the MODULE, the RCS part will not fire for that input. These can be toggled in the VAB/SPH. useThrottle which, when set to true, means that RCS will fire forwards with the throttle. ** RCS Thrust Control ** fullThrust defaults to false. Set it to true and if the thrust ratio is > fullThrustMin (default: 0.2) RCS will fire at full thrust (or 10% thrust in precision mode), rather than the less-than-full-thrust, dependent-on-angle they do stock. useLever defaults to false. When it's false, fine controls will make RCS fire at 10% (default) power only. When it's set to true, stock behavior returns (i.e. fine controls means lever arm compensation). precisionFactor is the multiplier to use when useLever is false (as it is by default). precisionFactor defaults to 0.1 (10%). ** RCS Input Controls ** EPSILON defaults to 0.05. That means a control actuation of less than 5% is ignored. This is because Unity is bad at joysticks and ignores deadzones. ** RCS Effects ** Currently disabled pending rework. Changelog: v4.2 * Fixed bug where inputs were being improperly normalized (thanks Starwaster!) * Fixed a bug in applying useThrottle (was being done in global Y not local Y; ditto). v4.1 * Fixed bug in thrust calculation (was 2% what it should be...) * When in fullThrust mode, don't switch to full thrust unless thrust ratio already starts out at fullThrustMin (configurable).[/QUOTE]
  23. MAFman

    Hello!

    *waves hand* Hi, Giocomo! Sorry if I butchered your name lol
×
×
  • Create New...