KontrolSystem2 icon indicating copy to clipboard operation
KontrolSystem2 copied to clipboard

Waypoint created by the game

Open PhilouDS opened this issue 1 year ago • 3 comments

Hi,

Is it possible to have access to waypoint created by the game? For example, the signal mission creates a waypoint on the Mun and you have to land near this waypoint.

PhilouDS avatar Mar 25 '24 20:03 PhilouDS

I did not had much time for testing (mostly because I do not have that many waypoints to play around with), but this pre-release should have basic support: https://github.com/untoldwind/KontrolSystem2/releases/tag/v0.5.7.4

There is:

  • ksp::orbit::find_waypoint(name: string) to find a waypoint by is (display) name
  • body.waypoints to get a list of all waypoints on a celestial body
  • Waypoint itself has a .global_position als well as .geo_coordinates

untoldwind avatar Mar 26 '24 19:03 untoldwind

This is great. Exactly what I wanted. Thanks. image

PhilouDS avatar Mar 26 '24 21:03 PhilouDS

I really liked this addition too, it was just what I needed for a rover script I was working on.

const body = vessel.main_body
// assume the first waypoint is the target and that there are waypoints
let target_global_pos = body.waypoints[0].global_position 

// Calculate direction vector to the target
let direction_to_target = target_global_pos - vessel.global_position
let distance = target_global_pos.distance(vessel.global_position)


// accuracy of 100m
while(distance > 100){
    CONSOLE.clear()
    direction_to_target = target_global_pos - vessel.global_position
    distance = target_global_pos.distance(vessel.global_position)

    // Calculate the heading to the target, ignoring the vertical component
    const local_vector = direction_to_target.to_local(vessel.body_frame)
    const heading = atan2_deg(local_vector.x, local_vector.y)

    const steering_angle = clamp((heading / 180.0),-1,1) // Simple normalization
    const current_speed = vessel.horizontal_surface_speed
    vessel.set_wheel_steering(steering_angle)
    
    CONSOLE.print_line("Distance " + distance.to_string())
    CONSOLE.print_line("Steering Angle: " + steering_angle.to_string())
    if(current_speed > 10.0) {
        const manager = vessel.set_wheel_throttle(-1.0)
        CONSOLE.print_line("Throttle: " + manager.wheel_throttle.to_string())
    }
    else if(current_speed < 8.0) {         
        const manager = vessel.set_wheel_throttle(1.0)
        CONSOLE.print_line("Throttle: " + manager.wheel_throttle.to_string())
    } else {
        const manager = vessel.set_wheel_throttle(0)
        CONSOLE.print_line("Throttle: " + manager.wheel_throttle.to_string())
    }
    sleep(0.25)
    
}
vessel.set_wheel_throttle(0.0)
vessel.set_wheel_steering(0.0)
vessel.actions.brakes = true
CONSOLE.print_line("Arrived at waypoint")

smartbadger avatar Mar 29 '24 03:03 smartbadger

This issue is stale because it has been open for 60 days with no activity.

github-actions[bot] avatar May 29 '24 02:05 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Jun 12 '24 02:06 github-actions[bot]