Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dynamics page and react router #115

Merged
merged 9 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions control-station/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions control-station/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.23.1",
"socket.io-client": "^4.7.2"
},
"devDependencies": {
Expand Down
10 changes: 8 additions & 2 deletions control-station/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ControlPanel, Navbar } from "@/components";
import usePodData from "./services/usePodData";
import PodContext from "./services/PodContext";
import { Dashboard } from "@/views";
import { BrowserRouter, Routes, Route } from "react-router-dom";
import { Dashboard, Dynamics } from "@/views";

function App() {
const { podData, podSocketClient } = usePodData();
Expand All @@ -10,7 +11,12 @@ function App() {
<main>
<PodContext.Provider value={{ podData, podSocketClient }}>
<Navbar />
<Dashboard />
<BrowserRouter>
<Routes>
<Route path="/" element={<Dashboard />} />
<Route path="/dynamics" element={<Dynamics />} />
</Routes>
</BrowserRouter>
<ControlPanel />
</PodContext.Provider>
</main>
Expand Down
Binary file added control-station/src/data/images/FrontPod.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added control-station/src/data/images/SidePod.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions control-station/src/views/Dynamics/Dynamics.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.dynamics {
display: flex;
}

.dynamics-sensorbox {
width: 40%;
display: flex;
flex-direction: column;
justify-content: space-evenly;
align-items: center;
}

.dynamics-pictures {
width: 60%;
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
}

.pod-picture-container {
background-color: rgb(209, 209, 209);
width: 60%;
height: 40%;
display: flex;
justify-content: center;
align-items: center;
border-radius: 40px;
overflow: hidden;
}
41 changes: 41 additions & 0 deletions control-station/src/views/Dynamics/Dynamics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import SensorBox from "@/components/SensorBoxes/Sensors/SensorBox";
import PodContext from "@/services/PodContext";
import FrontPod from "@/data/images/FrontPod.png";
import SidePod from "@/data/images/SidePod.png";
import "./Dynamics.css";
import { useContext } from "react";

function Dynamics() {
const { podData } = useContext(PodContext);
const { gyroscope } = podData;
return (
<div className="dynamics">
<div className="dynamics-sensorbox">
<SensorBox title="Roll" value={Math.round(gyroscope.roll * 100) / 100} />
<SensorBox title="Pitch" value={Math.round(gyroscope.pitch * 100) / 100} />
</div>
<div className="dynamics-pictures">
<div className="pod-picture-container">
<img
src={FrontPod}
alt="front view of the pod"
style={{
transform: `rotate(${Math.round(gyroscope.roll * 100) / 100}deg)`,
}}
vrushang1234 marked this conversation as resolved.
Show resolved Hide resolved
/>
</div>
<div className="pod-picture-container">
<img
src={SidePod}
alt="side view of the pod"
style={{
transform: `rotate(${Math.round(gyroscope.pitch * 100) / 100}deg)`,
}}
/>
</div>
</div>
</div>
);
}

export default Dynamics;
1 change: 1 addition & 0 deletions control-station/src/views/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as Dashboard } from "./Dashboard/Dashboard";
export { default as Dynamics } from "./Dynamics/Dynamics";
7 changes: 4 additions & 3 deletions pod-operation/src/components/gyro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use {
mpu6050::Mpu6050,
rppal::{hal::Delay, i2c::I2c},
std::f32::consts::PI,
};

use serde::Serialize;
Expand All @@ -16,7 +17,6 @@ pub struct Orientation {
pub pitch: f32,
pub roll: f32,
}

impl Gyroscope {
#[cfg(feature = "mpu6050")]
pub fn new() -> Self {
Expand All @@ -27,11 +27,12 @@ impl Gyroscope {
}

#[cfg(feature = "mpu6050")]

pub fn read_orientation(&mut self) -> Orientation {
let angles = self.mpu6050.get_acc_angles().unwrap();
Orientation {
pitch: angles[1],
roll: angles[0],
pitch: (angles[1] * 180.0 / PI),
roll: (angles[0] * 180.0 / PI),
}
}

Expand Down