Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.

Dawn Runtime Communications

Kevin Ma edited this page Jan 28, 2018 · 1 revision

Uploading Student Code and Update Files

Due to complexities of file transfers, it has been resolved to use an outside SFTP implementation to deal with file uploads. To do so, we currently use the ssh2 package's SFTP-streams implementation as it is relatively OS-independent. All this systems requires is the IP address to the destination.

Background Communications

Currently, the main mechanism for background communication is through sockets created from the Node.js Dgram (UDP) and Net (TCP) modules. To enforce typing and reduce data transfers, data will be passed as Protocol Buffers, implemented through the protobuf.js package. This means that data, commonly represented as objects, will need to be converted to and from protobufs throughout the communication process; the current implementation can be found in Ansible.js. The schema for what is to be sent to and received from the robot is found in the ansible-protos folder. Any changes made to this must be clearly communicated to all, as changes here will affect implementation on both Dawn and Runtime's sides.

Initial Configuration - 3 Total Connections, 2 UDP and 1 TCP

  1. Dawn and Runtime initially in Idle State
  2. Dawn sends Ansible.proto messages over UDP with IP address to Runtime at 20 Hz
  3. Runtime receives Ansible.proto message, IP is saved, and starts sending Runtime.proto messages at 2Hz over UDP as the Heartbeat
  4. In Connected Network State

Connection Initiation Order

  1. [UDP] Dawn → Runtime on Port 1236
  2. [UDP] Dawn ← Runtime on Port 1235
  3. [TCP] Runtime ↔ Dawn on Port 1234

Console Logging

  1. Runtime sends Notification.proto message over TCP to Dawn on port 1234

Copying Student Code Over

  1. Student presses upload button and the Upload flag is currently toggled in Dawn

  2. Dawn sends a TCP Notification proto on port 1234 to Runtime

  3. Runtime stops current threads and sends TCP Notification proto when its ready to receive student code.

  4. If Dawn does not receive any TCP message, waits 1 second and resends Notification.proto at max 3 more times

  5. If no response over TCP, Dawn errors out

  6. If Dawn not in logical idle state, Dawn errors

  7. Dawn scps to Runtime file with

    • Student code
    • Named Peripherals

Restarting the Robot

  1. Same as initial configuration

Running and Stopping Student Code

  1. To start student code, Dawn will send UDP messages on port 1236 with the robot state to either teleop or auto. Runtime will handle state change
  2. Runtime’s UDP messages back on port 1235 will reflect the state change by changing robot state to teleop or auto respectively.
  3. To stop student code, Dawn will send UDP messages on port 1236 with the robot state to idle. Runtime will handle state change
  4. Runtime’s UDP messages back on port 1235 will reflect the state change by changing robot state to idle.

E-Stop

  1. Dawn sends message to Runtime -> EStop field toggled
  2. Runtime sends all future UDP message to Dawn with EStop field toggled and handles E-STOP
  3. Turn the robot off and on again to get out of E-Stop

Runtime Updates

  1. Dawn SCP’s new files in a tarball over to file location determined by devops
  2. Devops runs correct script to update runtime
  3. Will then run initial configuration for Runtime

Logical States:

Idle - When Runtime is running and student code is not running, regardless if Dawn is connected

  1. Runtime will continuously listen and receive on UDP port 1235
  2. If Dawn is connected:
  3. Runtime continues to send over sensor data over UDP on port 1236 with robot state set as idle
  4. Dawn continues sends joystick data over UDP on port 1235 with robot state set as idle

Autonomous

  1. Used when student wishes to run autonomous code.
  2. Dawn sends UDP messages to runtime on port 1235 with student code status as AUTO
  3. Runtime sends back UDP messages to dawn on port 1236 with robot status as AUTO

TeleOp

  1. Used when student wishes to run teleop code.
  2. Dawn sends UDP messages to runtime on port 1235 with student code status as TELEOP
  3. Runtime sends back UDP messages to dawn on port 1236 with robot status as TELEOP

EStop

  1. Used when student wishes to immediately stop all actions from the robot

Network States:

Idle → Connected → EStop

Runtime.proto
Proto for sending messages from Runtime to Dawn

syntax = "proto3";
message RuntimeData {
    enum State {
        STUDENT_CRASHED = 0;
        STUDENT_RUNNING = 1;
        STUDENT_STOPPED = 2;
        TELEOP = 3;
        AUTO = 4;
        ESTOP = 5;
        IDLE = 6;
    }   
    message SensorData {
        string device_type = 1;
        string device_name = 2;
        float value = 3;
        uint64 uid = 4;
        uint32 int_device_type = 5; 
    }
    State robot_state = 1;
    repeated SensorData sensor_data = 2;
}

Ansible.proto
Proto for sending messages from Dawn to Runtime

syntax = "proto3";
message DawnData {
    enum StudentCodeStatus {
        IDLE = 0;
        TELEOP = 1;
        AUTONOMOUS = 2;
    }

    message Gamepad {
        int32 index = 1; // Gamepad index, there may be up to 4
        repeated double axes = 2;
        repeated bool buttons = 3;
   }

    StudentCodeStatus student_code_status = 1;
    repeated Gamepad gamepads = 2;
    repeated string peripheral_names = 3;
}

Notification.proto
Proto for messaging over TCP socket for both Runtime and Dawn

syntax = "proto3";
message Notification {
    String header = 1;
    String msg = 2;
}