Roomba Controller Dashboard 1
A GUI and TCP client application that is used to control a Roomba for Computer Engineering 2880 @ Iowa State
Loading...
Searching...
No Matches
main.cpp File Reference
#include "../include/imgui/imgui.h"
#include "../include/imgui/backends/imgui_impl_glfw.h"
#include "../include/imgui/backends/imgui_impl_opengl3.h"
#include <GLFW/glfw3.h>
#include "Pose2D.hpp"
#include "Node.hpp"
#include "Pillar.hpp"
#include "Hole.hpp"
#include "Field.hpp"
#include <vector>
#include <netinet/in.h>
#include <chrono>
#include <sys/socket.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <fstream>
#include <iostream>
#include <thread>
#include <queue>
#include <condition_variable>
#include <atomic>
#include <sstream>

Go to the source code of this file.

Classes

struct  Move
 

Macros

#define BOT_CONNECT   0
 
#define ADDRESS   "127.0.0.1"
 
#define PORT   65432
 

Enumerations

enum  MovementType {
  MOVE_FORWARD , MOVE_BACKWARDS , MOVE_FORWARD_SMART , TURN_TO_ANGLE ,
  SCAN
}
 

Functions

std::atomic< bool > stopClient (false)
 
void addToQueue (const std::string &message)
 
void sendAngleToQueue (int16_t angle)
 
void sendDistanceToQueue (uint16_t distance)
 
void pathToRoutine (std::vector< Pose2D > path, std::vector< Move > &routine)
 
std::string parsePathIntoRoutine (const std::vector< Pose2D > &path)
 
void readAndLog (int socket, std::mutex &fieldMutex, Field &field, std::vector< Pose2D > &path)
 
void connectTCP (Field &field, std::mutex &fieldMutex, std::vector< Pose2D > &path)
 
void setupImGui (GLFWwindow *window)
 
void DrawCircle (ImDrawList *drawList, const ImVec2 &center, float radius, ImU32 color)
 
Pose2D ScreenToCoords (ImVec2 coords, ImVec2 offset, ImVec2 scaling)
 
ImVec2 coordsToScreen (ImVec2 offset, ImVec2 scaling, double x, double y)
 
ImVec2 coordsToScreen (ImVec2 offset, ImVec2 scaling, const Pose2D &position)
 
void ShowPillarOnWindow (ImDrawList *drawList, Pillar pillar, ImU32 color, ImVec2 offset, ImVec2 scaling)
 
void drawBotPose (ImDrawList *drawList, const Pose2D &botPose, ImVec2 offset, ImVec2 scaling)
 
void drawRectangle (ImDrawList *drawList, ImVec2 offset, ImVec2 scaling, const Pose2D &p1, const Pose2D &p2)
 
void ShowFieldWindow (std::mutex *pillarsMutex, std::vector< Pose2D > &path, Field &field, std::atomic< bool > &showNodes, std::atomic< bool > &showEdges)
 
int main ()
 

Variables

std::queue< std::string > sendQueue
 
std::mutex queueMutex
 
std::condition_variable sendCondition
 

Macro Definition Documentation

◆ ADDRESS

#define ADDRESS   "127.0.0.1"

Definition at line 29 of file main.cpp.

◆ BOT_CONNECT

#define BOT_CONNECT   0

Definition at line 24 of file main.cpp.

◆ PORT

#define PORT   65432

Definition at line 30 of file main.cpp.

Enumeration Type Documentation

◆ MovementType

Enumerator
MOVE_FORWARD 
MOVE_BACKWARDS 
MOVE_FORWARD_SMART 
TURN_TO_ANGLE 
SCAN 

Definition at line 33 of file main.cpp.

Function Documentation

◆ addToQueue()

void addToQueue ( const std::string & message)

Add a given string to the thread safe queue, accessed with mutexes

Parameters
messagethe message to add

Definition at line 56 of file main.cpp.

◆ connectTCP()

void connectTCP ( Field & field,
std::mutex & fieldMutex,
std::vector< Pose2D > & path )

connect to Roomba TCP server or the mock server depending on the configuration

Parameters
fieldreference to the field object
fieldMutexthe mutex for the field
pathreference to a generated path

Definition at line 291 of file main.cpp.

◆ coordsToScreen() [1/2]

ImVec2 coordsToScreen ( ImVec2 offset,
ImVec2 scaling,
const Pose2D & position )

Computes screen coordinates from Field coordinates

Parameters
offsetthe offset the window measuring on is at
scalingthe amount to scale by
positionthe position be transformed
Returns
the new screen coordinates

Definition at line 396 of file main.cpp.

◆ coordsToScreen() [2/2]

ImVec2 coordsToScreen ( ImVec2 offset,
ImVec2 scaling,
double x,
double y )

Computes screen coordinates from Field coordinates

Parameters
offsetthe offset the window measuring on is at
scalingthe amount to scale by
xthe x component of the pose 2d
ythe y component of the pose 2d
Returns
the new screen coordinates

Definition at line 383 of file main.cpp.

◆ drawBotPose()

void drawBotPose ( ImDrawList * drawList,
const Pose2D & botPose,
ImVec2 offset,
ImVec2 scaling )

Draws a triangle on the bot position facing in the direction that the bot is. The color of the triangle will be lime green.

Parameters
drawListthe draw list for the window
botPosethe position of the bot
offsetthe offset of the screen for cartesian coordinates

Definition at line 423 of file main.cpp.

◆ DrawCircle()

void DrawCircle ( ImDrawList * drawList,
const ImVec2 & center,
float radius,
ImU32 color )

Draw a circle on the window

Parameters
drawListthe drawlist for a given window
centerthe center position of the circle
radiusthe radus of the circle
colorthe color of the circle on the screen

Definition at line 357 of file main.cpp.

◆ drawRectangle()

void drawRectangle ( ImDrawList * drawList,
ImVec2 offset,
ImVec2 scaling,
const Pose2D & p1,
const Pose2D & p2 )

Draw a rectangle on the field given by the critical points p1 and p2

Parameters
drawListthe draw list for the window to draw on
offsetthe offset of the window
scalingthe size scaling
p1point one
p2point two (opposite corner)

Definition at line 450 of file main.cpp.

◆ main()

int main ( )

The main function where the program starts

Returns
status code of how the program executed

Definition at line 572 of file main.cpp.

◆ parsePathIntoRoutine()

std::string parsePathIntoRoutine ( const std::vector< Pose2D > & path)

parse a path into a routine

Parameters
paththe path to parse
Returns
the routine from the path

Definition at line 114 of file main.cpp.

◆ pathToRoutine()

void pathToRoutine ( std::vector< Pose2D > path,
std::vector< Move > & routine )

generate a routine from a path

Parameters
paththe path to generate a routine from
routinethe routine to store into

Definition at line 90 of file main.cpp.

◆ readAndLog()

void readAndLog ( int socket,
std::mutex & fieldMutex,
Field & field,
std::vector< Pose2D > & path )

Read and log data that gets sent over the TCP socket

Parameters
socketthe socket to listen on
fieldMutexthe mutex for the field object
fieldreference to the field object
paththe path to generate

Definition at line 142 of file main.cpp.

◆ ScreenToCoords()

Pose2D ScreenToCoords ( ImVec2 coords,
ImVec2 offset,
ImVec2 scaling )

Computes a Pose2D from given screen coordinates

Parameters
coordsthe coordinates on the window
offsetthe offset of the position of the window on the screen
scalingthe scaling factor for the window size
Returns

Definition at line 368 of file main.cpp.

◆ sendAngleToQueue()

void sendAngleToQueue ( int16_t angle)
Parameters
anglethe angle to send

Definition at line 68 of file main.cpp.

◆ sendDistanceToQueue()

void sendDistanceToQueue ( uint16_t distance)

Adds an distance to a queue to be sent to the bot

Parameters
distancethe distance to send

Definition at line 79 of file main.cpp.

◆ setupImGui()

void setupImGui ( GLFWwindow * window)

Simple function to set up OpenGL and ImGui context

Parameters
windowpointer to the GLFW window

Definition at line 341 of file main.cpp.

◆ ShowFieldWindow()

void ShowFieldWindow ( std::mutex * pillarsMutex,
std::vector< Pose2D > & path,
Field & field,
std::atomic< bool > & showNodes,
std::atomic< bool > & showEdges )

Show the field window on a new window

Parameters
pillarsMutexthe mutex for pillars
paththe path to display
fieldthe field object
showNodeswhether to show nodes or not (atomic reference)
showEdgeswhether to show edges of the graph or not (atmoic reference)

Definition at line 479 of file main.cpp.

◆ ShowPillarOnWindow()

void ShowPillarOnWindow ( ImDrawList * drawList,
Pillar pillar,
ImU32 color,
ImVec2 offset,
ImVec2 scaling )

Show a given pillar on the window.

Parameters
drawListthe window to draw a pillar (circle) on
pillarthe pillar which stores the given position and radius
colorthe color to draw it as
offsetthe offset of the window
scalingthe sizing ration for the window

Definition at line 408 of file main.cpp.

◆ stopClient()

std::atomic< bool > stopClient ( false )

Variable Documentation

◆ queueMutex

std::mutex queueMutex

Definition at line 42 of file main.cpp.

◆ sendCondition

std::condition_variable sendCondition

Definition at line 43 of file main.cpp.

◆ sendQueue

std::queue<std::string> sendQueue

Definition at line 41 of file main.cpp.