Docking#
This tutorial docks two vessels in orbit. The script flies one vessel’s docking port into the port of another, and draws its approach in the game. It covers the following topics:
Measuring positions and velocities in a docking port’s reference frame
Pointing the vessel with the autopilot
Moving the vessel with its RCS thrusters
Drawing lines in the game with the Drawing service
You need two vessels in orbit a few tens of meters apart, each with a docking port. The vessel you fly also needs RCS thrusters and monopropellant. Before you run the script, right-click your vessel’s docking port and choose Control from here. Then right-click the other vessel’s docking port and choose Set as target.
The tutorial includes source code for the main client languages kRPC supports. Download the whole program in your chosen language:
Python,
C#,
C++,
C,
Java,
Lua,
JavaScript
Finding the Ports#
First we connect to the server and find the two docking ports. Our port is the part the vessel is
controlled from, and the target port is the one you set as the target. The C program also defines
sleep_ms, which its loop pauses with:
conn = krpc.connect(name="Docking")
space_center = conn.space_center
vessel = space_center.active_vessel
port = vessel.parts.controlling.docking_port
target = space_center.target_docking_port
frame = target.reference_frame
var conn = new Connection ("Docking");
var spaceCenter = conn.SpaceCenter ();
var drawing = conn.Drawing ();
var vessel = spaceCenter.ActiveVessel;
var port = vessel.Parts.Controlling.DockingPort;
var target = spaceCenter.TargetDockingPort;
var frame = target.ReferenceFrame;
krpc::Connection conn = krpc::connect("Docking");
SpaceCenter space_center(conn);
Drawing drawing(conn);
auto vessel = space_center.active_vessel().value();
auto port = vessel.parts().controlling()->docking_port().value();
auto target = space_center.target_docking_port().value();
auto frame = target.reference_frame();
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#define sleep_ms(ms) Sleep(ms)
#else
#define _POSIX_C_SOURCE 200809L
#include <time.h>
static void sleep_ms(long ms) {
struct timespec duration = {ms / 1000, (ms % 1000) * 1000000};
nanosleep(&duration, NULL);
}
#endif
#include <krpc_cnano.h>
#include <krpc_cnano/services/drawing.h>
#include <krpc_cnano/services/space_center.h>
#include <krpc_cnano/services/std_lib.h>
#include <math.h>
#include <stdio.h>
int main() {
krpc_connection_t conn;
if (krpc_open_serial(&conn, "COM0") != KRPC_OK) return 1;
if (krpc_connect(conn, "Docking") != KRPC_OK) return 1;
krpc_SpaceCenter_Vessel_t vessel;
krpc_SpaceCenter_ActiveVessel(conn, &vessel);
krpc_SpaceCenter_Parts_t parts;
krpc_SpaceCenter_Vessel_Parts(conn, &parts, vessel);
krpc_SpaceCenter_Part_t controlling;
krpc_SpaceCenter_Parts_Controlling(conn, &controlling, parts);
krpc_SpaceCenter_DockingPort_t port;
krpc_SpaceCenter_Part_DockingPort(conn, &port, controlling);
krpc_SpaceCenter_DockingPort_t target;
krpc_SpaceCenter_TargetDockingPort(conn, &target);
krpc_SpaceCenter_ReferenceFrame_t frame;
krpc_SpaceCenter_DockingPort_ReferenceFrame(conn, &frame, target);
krpc_SpaceCenter_ReferenceFrame_t vessel_frame;
krpc_SpaceCenter_Vessel_ReferenceFrame(conn, &vessel_frame, vessel);
krpc_SpaceCenter_Control_t control;
krpc_SpaceCenter_Vessel_Control(conn, &control, vessel);
krpc_SpaceCenter_AutoPilot_t auto_pilot;
krpc_SpaceCenter_Vessel_AutoPilot(conn, &auto_pilot, vessel);
Connection connection = Connection.newInstance("Docking");
SpaceCenter spaceCenter = SpaceCenter.newInstance(connection);
Drawing drawing = Drawing.newInstance(connection);
Vessel vessel = spaceCenter.getActiveVessel();
DockingPort port =
vessel.getParts().getControlling().getDockingPort();
DockingPort target = spaceCenter.getTargetDockingPort();
ReferenceFrame frame = target.getReferenceFrame();
local krpc = require 'krpc'
local socket = require 'socket'
local conn = krpc.connect('Docking')
local space_center = conn.space_center
local drawing = conn.drawing
local vessel = space_center.active_vessel
local port = vessel.parts.controlling.docking_port
local target = space_center.target_docking_port
local frame = target.reference_frame
const conn = await connect({ name: "Docking" });
const spaceCenter = conn.spaceCenter;
const drawing = conn.drawing;
const { ColorRGB } = conn.stdLib;
const vessel = await spaceCenter.getActiveVessel();
const control = await vessel.getControl();
const autoPilot = await vessel.getAutoPilot();
const parts = await vessel.getParts();
const port = await (await parts.getControlling()).getDockingPort();
const target = await spaceCenter.getTargetDockingPort();
const frame = await target.getReferenceFrame();
const vesselFrame = await vessel.getReferenceFrame();
The script measures everything in the target port’s reference frame. Its origin is at the target port, and its y-axis points out of the port, along the path our port must take to dock. See the Reference Frames guide for more.
Turning to Face the Target#
Our port has to point back along the target port’s y-axis, which is the direction (0, -1, 0)
in its frame. The autopilot turns the vessel to face that way, and wait blocks until it does.
The vessel is controlled from our port, so the autopilot points the port:
# Turn to face the target port
print("Turning to face the target")
vessel.control.sas = False
vessel.control.rcs = True
vessel.auto_pilot.reference_frame = frame
vessel.auto_pilot.target_direction = (0, -1, 0)
vessel.auto_pilot.engaged = True
vessel.auto_pilot.wait()
// Turn to face the target port
Console.WriteLine ("Turning to face the target");
vessel.Control.SAS = false;
vessel.Control.RCS = true;
vessel.AutoPilot.ReferenceFrame = frame;
vessel.AutoPilot.TargetDirection = Tuple.Create (0.0, -1.0, 0.0);
vessel.AutoPilot.Engaged = true;
vessel.AutoPilot.Wait ();
// Turn to face the target port
std::cout << "Turning to face the target" << std::endl;
vessel.control().set_sas(false);
vessel.control().set_rcs(true);
vessel.auto_pilot().set_reference_frame(frame);
vessel.auto_pilot().set_target_direction(std::make_tuple(0.0, -1.0, 0.0));
vessel.auto_pilot().set_engaged(true);
vessel.auto_pilot().wait();
// Turn to face the target port
printf("Turning to face the target\n");
krpc_SpaceCenter_Control_set_SAS(conn, control, false);
krpc_SpaceCenter_Control_set_RCS(conn, control, true);
krpc_SpaceCenter_AutoPilot_set_ReferenceFrame(conn, auto_pilot, frame);
krpc_tuple_double_double_double_t facing = {0, -1, 0};
krpc_SpaceCenter_AutoPilot_set_TargetDirection(conn, auto_pilot, &facing);
krpc_SpaceCenter_AutoPilot_set_Engaged(conn, auto_pilot, true);
krpc_SpaceCenter_AutoPilot_Wait(conn, auto_pilot, -1);
// Turn to face the target port
System.out.println("Turning to face the target");
vessel.getControl().setSAS(false);
vessel.getControl().setRCS(true);
vessel.getAutoPilot().setReferenceFrame(frame);
vessel.getAutoPilot().setTargetDirection(
new Triplet<Double, Double, Double>(0.0, -1.0, 0.0));
vessel.getAutoPilot().setEngaged(true);
vessel.getAutoPilot().wait_(-1);
-- Turn to face the target port
print('Turning to face the target')
vessel.control.sas = false
vessel.control.rcs = true
vessel.auto_pilot.reference_frame = frame
vessel.auto_pilot.target_direction = {0, -1, 0}
vessel.auto_pilot.engaged = true
vessel.auto_pilot:wait()
// Turn to face the target port
console.log("Turning to face the target");
await control.setSAS(false);
await control.setRCS(true);
await autoPilot.setReferenceFrame(frame);
await autoPilot.setTargetDirection([0, -1, 0]);
await autoPilot.setEngaged(true);
await autoPilot.wait();
This also switches off SAS, as the autopilot does the steering, and switches on RCS for the approach.
Drawing the Approach#
The Drawing service draws lines in the game. A green line runs 50 m out along the target port’s axis, showing the path to dock along. A yellow line runs from our port to the target port, and the script moves its start as our port moves:
# Draw the docking axis, and a line from our port to the target
axis = conn.drawing.add_line((0, 0, 0), (0, 50, 0), frame)
axis.color = conn.std_lib.ColorRGB(0, 1, 0)
approach = conn.drawing.add_line((0, 0, 0), (0, 0, 0), frame)
approach.color = conn.std_lib.ColorRGB(1, 1, 0)
// Draw the docking axis, and a line from our port to the target
var origin = Tuple.Create (0.0, 0.0, 0.0);
var axis = drawing.AddLine (
origin, Tuple.Create (0.0, 50.0, 0.0), frame);
axis.Color = new ColorRGB (0, 1, 0);
var approach = drawing.AddLine (origin, origin, frame);
approach.Color = new ColorRGB (1, 1, 0);
// Draw the docking axis, and a line from our port to the target
auto origin = std::make_tuple(0.0, 0.0, 0.0);
auto axis =
drawing.add_line(origin, std::make_tuple(0.0, 50.0, 0.0), frame);
axis.set_color(ColorRGB(0, 1, 0));
auto approach = drawing.add_line(origin, origin, frame);
approach.set_color(ColorRGB(1, 1, 0));
// Draw the docking axis, and a line from our port to the target
krpc_tuple_double_double_double_t origin = {0, 0, 0};
krpc_tuple_double_double_double_t axis_end = {0, 50, 0};
krpc_Drawing_Line_t axis;
krpc_Drawing_AddLine(conn, &axis, &origin, &axis_end, frame, true);
krpc_StdLib_ColorRGB_t green = {0, 1, 0};
krpc_Drawing_Line_set_Color(conn, axis, &green);
krpc_Drawing_Line_t approach;
krpc_Drawing_AddLine(conn, &approach, &origin, &origin, frame, true);
krpc_StdLib_ColorRGB_t yellow = {1, 1, 0};
krpc_Drawing_Line_set_Color(conn, approach, &yellow);
// Draw the docking axis, and a line from our port to the target
Triplet<Double, Double, Double> origin =
new Triplet<Double, Double, Double>(0.0, 0.0, 0.0);
Line axis = drawing.addLine(
origin, new Triplet<Double, Double, Double>(0.0, 50.0, 0.0),
frame, true);
axis.setColor(new StdLib.ColorRGB(0f, 1f, 0f));
Line approach = drawing.addLine(origin, origin, frame, true);
approach.setColor(new StdLib.ColorRGB(1f, 1f, 0f));
-- Draw the docking axis, and a line from our port to the target
local axis = drawing.add_line({0, 0, 0}, {0, 50, 0}, frame)
axis.color = conn.std_lib.ColorRGB(0, 1, 0)
local approach = drawing.add_line({0, 0, 0}, {0, 0, 0}, frame)
approach.color = conn.std_lib.ColorRGB(1, 1, 0)
// Draw the docking axis, and a line from our port to the target
const axis = await drawing.addLine([0, 0, 0], [0, 50, 0], frame);
await axis.setColor(new ColorRGB({ r: 0, g: 1, b: 0 }));
const approach = await drawing.addLine([0, 0, 0], [0, 0, 0], frame);
await approach.setColor(new ColorRGB({ r: 1, g: 1, b: 0 }));
Approaching the Target#
Now we fly our port along the axis to the target port. Each pass of the loop picks a velocity to fly at, and fires the RCS thrusters to reach it. The loop ends when the magnets of the two ports catch each other, and our port’s state changes to docking:
# Approach the target port along its axis
print("Approaching")
position = conn.add_stream(port.position, frame)
velocity = conn.add_stream(vessel.velocity, frame)
states = space_center.DockingPortState
while port.state not in (states.docking, states.docked):
x, y, z = position()
approach.start = (x, y, z)
# Line up on the axis, then close in along it
off_axis = math.hypot(x, z)
goal_y = 0 if off_axis < 0.5 else max(y, 5)
ex, ey, ez = -x, goal_y - y, -z
distance = math.sqrt(ex * ex + ey * ey + ez * ez)
speed = min(1, max(0.1, 0.2 * distance))
scale = speed / max(distance, 0.01)
# Thrust towards the velocity we want, in the vessel's frame
vx, vy, vz = velocity()
thrust = (
2 * (ex * scale - vx),
2 * (ey * scale - vy),
2 * (ez * scale - vz),
)
right, forward, down = space_center.transform_direction(
thrust, frame, vessel.reference_frame
)
vessel.control.right = max(-1, min(1, right))
vessel.control.forward = max(-1, min(1, forward))
vessel.control.up = max(-1, min(1, -down))
time.sleep(0.05)
// Approach the target port along its axis
Console.WriteLine ("Approaching");
var position = conn.AddStream (() => port.Position (frame));
var velocity = conn.AddStream (() => vessel.Velocity (frame));
while (port.State != DockingPortState.Docking &&
port.State != DockingPortState.Docked) {
var p = position.Get ();
approach.Start = p;
// Line up on the axis, then close in along it
double offAxis =
Math.Sqrt (p.Item1 * p.Item1 + p.Item3 * p.Item3);
double goalY = offAxis < 0.5 ? 0 : Math.Max (p.Item2, 5);
double ex = -p.Item1, ey = goalY - p.Item2, ez = -p.Item3;
double distance = Math.Sqrt (ex * ex + ey * ey + ez * ez);
double speed = Math.Min (1, Math.Max (0.1, 0.2 * distance));
double scale = speed / Math.Max (distance, 0.01);
// Thrust towards the velocity we want, in the vessel's frame
var v = velocity.Get ();
var thrust = Tuple.Create (
2 * (ex * scale - v.Item1),
2 * (ey * scale - v.Item2),
2 * (ez * scale - v.Item3));
var t = spaceCenter.TransformDirection (
thrust, frame, vessel.ReferenceFrame);
vessel.Control.Right =
(float)Math.Max (-1, Math.Min (1, t.Item1));
vessel.Control.Forward =
(float)Math.Max (-1, Math.Min (1, t.Item2));
vessel.Control.Up =
(float)Math.Max (-1, Math.Min (1, -t.Item3));
System.Threading.Thread.Sleep (50);
}
// Approach the target port along its axis
std::cout << "Approaching" << std::endl;
auto position = port.position_stream(frame);
auto velocity = vessel.velocity_stream(frame);
while (port.state() != SpaceCenter::DockingPortState::docking &&
port.state() != SpaceCenter::DockingPortState::docked) {
auto [x, y, z] = position();
approach.set_start(std::make_tuple(x, y, z));
// Line up on the axis, then close in along it
double off_axis = std::hypot(x, z);
double goal_y = off_axis < 0.5 ? 0 : std::max(y, 5.0);
double ex = -x, ey = goal_y - y, ez = -z;
double distance = std::sqrt(ex * ex + ey * ey + ez * ez);
double speed = std::min(1.0, std::max(0.1, 0.2 * distance));
double scale = speed / std::max(distance, 0.01);
// Thrust towards the velocity we want, in the vessel's frame
auto [vx, vy, vz] = velocity();
auto thrust =
std::make_tuple(2 * (ex * scale - vx), 2 * (ey * scale - vy),
2 * (ez * scale - vz));
auto [right, forward, down] = space_center.transform_direction(
thrust, frame, vessel.reference_frame());
vessel.control().set_right(std::clamp(right, -1.0, 1.0));
vessel.control().set_forward(std::clamp(forward, -1.0, 1.0));
vessel.control().set_up(std::clamp(-down, -1.0, 1.0));
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
// Approach the target port along its axis
printf("Approaching\n");
while (true) {
krpc_SpaceCenter_DockingPortState_t state;
krpc_SpaceCenter_DockingPort_State(conn, &state, port);
if (state == KRPC_SPACECENTER_DOCKINGPORTSTATE_DOCKING ||
state == KRPC_SPACECENTER_DOCKINGPORTSTATE_DOCKED)
break;
krpc_tuple_double_double_double_t p;
krpc_SpaceCenter_DockingPort_Position(conn, &p, port, frame);
krpc_Drawing_Line_set_Start(conn, approach, &p);
// Line up on the axis, then close in along it
double off_axis = hypot(p.e0, p.e2);
double goal_y = off_axis < 0.5 ? 0 : fmax(p.e1, 5);
double ex = -p.e0, ey = goal_y - p.e1, ez = -p.e2;
double distance = sqrt(ex * ex + ey * ey + ez * ez);
double speed = fmin(1, fmax(0.1, 0.2 * distance));
double scale = speed / fmax(distance, 0.01);
// Thrust towards the velocity we want, in the vessel's frame
krpc_tuple_double_double_double_t v;
krpc_SpaceCenter_Vessel_Velocity(conn, &v, vessel, frame);
krpc_tuple_double_double_double_t thrust = {2 * (ex * scale - v.e0),
2 * (ey * scale - v.e1),
2 * (ez * scale - v.e2)};
krpc_tuple_double_double_double_t t;
krpc_SpaceCenter_TransformDirection(conn, &t, &thrust, frame,
vessel_frame);
krpc_SpaceCenter_Control_set_Right(conn, control,
fmin(1, fmax(-1, t.e0)));
krpc_SpaceCenter_Control_set_Forward(conn, control,
fmin(1, fmax(-1, t.e1)));
krpc_SpaceCenter_Control_set_Up(conn, control,
fmin(1, fmax(-1, -t.e2)));
sleep_ms(50);
}
// Approach the target port along its axis
System.out.println("Approaching");
Stream<Triplet<Double, Double, Double>> position =
connection.addStream(port, "position", frame);
Stream<Triplet<Double, Double, Double>> velocity =
connection.addStream(vessel, "velocity", frame);
while (port.getState() != DockingPortState.DOCKING &&
port.getState() != DockingPortState.DOCKED) {
Triplet<Double, Double, Double> p = position.get();
approach.setStart(p);
double x = p.getValue0(), y = p.getValue1(), z = p.getValue2();
// Line up on the axis, then close in along it
double offAxis = Math.hypot(x, z);
double goalY = offAxis < 0.5 ? 0 : Math.max(y, 5);
double ex = -x, ey = goalY - y, ez = -z;
double distance = Math.sqrt(ex * ex + ey * ey + ez * ez);
double speed = Math.min(1, Math.max(0.1, 0.2 * distance));
double scale = speed / Math.max(distance, 0.01);
// Thrust towards the velocity we want, in the vessel's frame
Triplet<Double, Double, Double> v = velocity.get();
Triplet<Double, Double, Double> thrust =
new Triplet<Double, Double, Double>(
2 * (ex * scale - v.getValue0()),
2 * (ey * scale - v.getValue1()),
2 * (ez * scale - v.getValue2()));
Triplet<Double, Double, Double> t =
spaceCenter.transformDirection(
thrust, frame, vessel.getReferenceFrame());
vessel.getControl().setRight(
(float) Math.max(-1, Math.min(1, t.getValue0())));
vessel.getControl().setForward(
(float) Math.max(-1, Math.min(1, t.getValue1())));
vessel.getControl().setUp(
(float) Math.max(-1, Math.min(1, -t.getValue2())));
Thread.sleep(50);
}
-- Approach the target port along its axis
print('Approaching')
local docking = space_center.DockingPortState.docking.value
local docked = space_center.DockingPortState.docked.value
while port.state.value ~= docking and port.state.value ~= docked do
local p = port:position(frame)
local x, y, z = p[1], p[2], p[3]
approach.start = p
-- Line up on the axis, then close in along it
local off_axis = math.sqrt(x * x + z * z)
local goal_y = 0
if off_axis >= 0.5 then
goal_y = math.max(y, 5)
end
local ex, ey, ez = -x, goal_y - y, -z
local distance = math.sqrt(ex * ex + ey * ey + ez * ez)
local speed = math.min(1, math.max(0.1, 0.2 * distance))
local scale = speed / math.max(distance, 0.01)
-- Thrust towards the velocity we want, in the vessel's frame
local v = vessel:velocity(frame)
local thrust = {
2 * (ex * scale - v[1]),
2 * (ey * scale - v[2]),
2 * (ez * scale - v[3])}
local t = space_center.transform_direction(
thrust, frame, vessel.reference_frame)
vessel.control.right = math.max(-1, math.min(1, t[1]))
vessel.control.forward = math.max(-1, math.min(1, t[2]))
vessel.control.up = math.max(-1, math.min(1, -t[3]))
socket.sleep(0.05)
end
// Approach the target port along its axis
console.log("Approaching");
const position = await conn.addStream(() => port.position(frame));
const velocity = await conn.addStream(() => vessel.velocity(frame));
const { docking, docked } = spaceCenter.DockingPortState;
let state = await port.getState();
while (state !== docking && state !== docked) {
const [x, y, z] = await position.get();
await approach.setStart([x, y, z]);
// Line up on the axis, then close in along it
const offAxis = Math.hypot(x, z);
const goalY = offAxis < 0.5 ? 0 : Math.max(y, 5);
const [ex, ey, ez] = [-x, goalY - y, -z];
const distance = Math.hypot(ex, ey, ez);
const speed = Math.min(1, Math.max(0.1, 0.2 * distance));
const scale = speed / Math.max(distance, 0.01);
// Thrust towards the velocity we want, in the vessel's frame
const [vx, vy, vz] = await velocity.get();
const [right, forward, down] = await spaceCenter.transformDirection(
[2 * (ex * scale - vx), 2 * (ey * scale - vy), 2 * (ez * scale - vz)],
frame,
vesselFrame,
);
await control.setRight(Math.max(-1, Math.min(1, right)));
await control.setForward(Math.max(-1, Math.min(1, forward)));
await control.setUp(Math.max(-1, Math.min(1, -down)));
await new Promise((resolve) => setTimeout(resolve, 50));
state = await port.getState();
}
The script picks a goal on the axis to fly towards. While our port is more than 0.5 m off the axis, the goal is level with it, at least 5 m out from the target. So the vessel first moves sideways onto the axis. Once it is on the axis, the goal is the target port itself.
The speed towards the goal is a fifth of the distance to it, from 0.1 m/s to 1 m/s. So the vessel slows down as it closes in, and touches the target port gently.
The thrust is the difference between that velocity and the vessel’s velocity, doubled. The RCS
controls take a direction in the vessel’s reference frame: right along its x-axis, forward along
its y-axis, and up opposite its z-axis. So SpaceCenter.transform_direction() converts the
thrust from the target port’s frame to the vessel’s frame.
The Python, C#, C++, Java and JavaScript scripts read the position and velocity from streams. The C and Lua clients do not support streams, so their scripts call for them on every pass.
Finishing#
Once the ports have docked, we stop the thrusters, switch off the autopilot and remove the drawing:
# Stop the thrusters, and remove the drawing
vessel.control.right = 0
vessel.control.forward = 0
vessel.control.up = 0
vessel.auto_pilot.engaged = False
conn.drawing.clear()
print("Docked")
// Stop the thrusters, and remove the drawing
vessel.Control.Right = 0;
vessel.Control.Forward = 0;
vessel.Control.Up = 0;
vessel.AutoPilot.Engaged = false;
drawing.Clear ();
Console.WriteLine ("Docked");
conn.Dispose ();
}
}
// Stop the thrusters, and remove the drawing
vessel.control().set_right(0);
vessel.control().set_forward(0);
vessel.control().set_up(0);
vessel.auto_pilot().set_engaged(false);
drawing.clear();
std::cout << "Docked" << std::endl;
}
// Stop the thrusters, and remove the drawing
krpc_SpaceCenter_Control_set_Right(conn, control, 0);
krpc_SpaceCenter_Control_set_Forward(conn, control, 0);
krpc_SpaceCenter_Control_set_Up(conn, control, 0);
krpc_SpaceCenter_AutoPilot_set_Engaged(conn, auto_pilot, false);
krpc_Drawing_Clear(conn, false);
printf("Docked\n");
krpc_disconnect(conn);
}
// Stop the thrusters, and remove the drawing
vessel.getControl().setRight(0);
vessel.getControl().setForward(0);
vessel.getControl().setUp(0);
vessel.getAutoPilot().setEngaged(false);
drawing.clear(false);
System.out.println("Docked");
connection.close();
}
}
-- Stop the thrusters, and remove the drawing
vessel.control.right = 0
vessel.control.forward = 0
vessel.control.up = 0
vessel.auto_pilot.engaged = false
drawing.clear()
print('Docked')
// Stop the thrusters, and remove the drawing
await control.setRight(0);
await control.setForward(0);
await control.setUp(0);
await autoPilot.setEngaged(false);
await drawing.clear();
console.log("Docked");
await conn.close();
The two vessels are now docked together.