1.0.1 • Published 9 months ago

@noirrzz/spacecraft-control v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Spacecraft Control System

A comprehensive Node.js-based spacecraft control system featuring power management, movement controls, sensor systems, and real-time status monitoring.

Complete Setup Guide

Prerequisites

  • Node.js (v12 or higher)
  • npm (v6 or higher)

Project Setup

  1. Create a new directory and initialize:
mkdir spacecraft-control
cd spacecraft-control
npm init -y
  1. Install required dependencies:
npm install express body-parser
  1. Create the project structure:
spacecraft-control/
├── public/
│   ├── images/
│   │   └── rover.png
│   ├── styles/
│   │   └── styles.css
│   ├── scripts/
│   │   └── scripts.js
│   └── index.html
├── server.js
├── package.json
└── .npmignore
  1. Add to package.json:
{
  "name": "@noirrzz/spacecraft-control",
  "version": "1.0.0",
  "description": "A spacecraft control system with power management and sensor capabilities",
  "main": "server.js",
  "scripts": {
    "start": "node server.js"
  },
  "dependencies": {
    "express": "^4.18.2",
    "body-parser": "^1.20.2"
  }
}

Features

🚀 Movement Control

  • Forward and backward movement at 200 km/h
  • Emergency stop functionality
  • Direction indicator
  • Automatic substance detection during movement

⚡ Power Management

  • Battery level monitoring
  • Sleep mode for instant recharging
  • Wake/Sleep state tracking
  • Power consumption during movement
  • Visual power level indicators

⛽ Fuel System

  • Fuel level monitoring
  • Refueling capability (+25% per refuel)
  • Fuel consumption during movement
  • Visual fuel level indicators

🔍 Sensor Systems

  • Mineral detection
  • Ground substance analysis
  • Real-time sensor readings
  • Activatable/Deactivatable sensors

API Reference

Endpoints

GET /status

Returns the current status of the spacecraft:

{
    "battery": "100%",
    "speed": "200 km/h (forward)",
    "fuel": "85%",
    "minerals": "Iron, Copper, Silicon",
    "groundSubstances": "Water, Methane",
    "status": "Awake"
}

POST /action

Send commands to control the spacecraft.

Available Actions:

  1. Movement Control
{
    "action": "move",
    "value": "forward" | "backward" | "stop"
}
  1. Power Management
{
    "action": "power",
    "value": "sleep" | "wake"
}
  1. Sensor Control
{
    "action": "sensors",
    "value": "on" | "off"
}
  1. Fuel Management
{
    "action": "fuel",
    "value": "refuel"
}

System Specifications

Power System

  • Full battery: 100%
  • Movement consumption: 5% per action
  • Wake-up consumption: 2%
  • Sleep mode: Instant recharge to 100%

Fuel System

  • Full tank: 100%
  • Movement consumption: 2% per action
  • Refuel amount: +25% per refuel
  • Cannot move when fuel is depleted

Movement System

  • Speed: 200 km/h
  • Directions: Forward/Backward
  • Emergency stop available
  • Requires both power and fuel to move

File Structure Details

server.js

Main server file handling:

  • Express server setup
  • API endpoints
  • Spacecraft state management
  • Action handlers

public/index.html

Frontend interface containing:

  • Control panel layout
  • Status displays
  • Interactive buttons
  • Progress bars

public/styles/styles.css

Styling including:

  • Layout and grid system
  • Color schemes
  • Animations
  • Responsive design

public/scripts/scripts.js

Frontend logic handling:

  • API calls
  • Status updates
  • UI animations
  • Error handling

Publishing to npm

  1. Login to npm:
npm login
  1. Create .npmignore:
.git
.gitignore
node_modules
.env
.DS_Store
  1. Publish package:
npm publish --access public

Usage Example

// Move forward
fetch('/action', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        action: 'move',
        value: 'forward'
    })
});

// Enter sleep mode to recharge
fetch('/action', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        action: 'power',
        value: 'sleep'
    })
});

Running the Project

  1. Start the server:
npm start
  1. Access the control panel:
http://localhost:3000

Error Handling

The system provides clear error messages for:

  • Insufficient power
  • Insufficient fuel
  • Sleep mode movement attempts
  • Invalid commands
  • System state conflicts

Author

noirrzz