-
Notifications
You must be signed in to change notification settings - Fork 0
X14 Software Internal Temp
Cyrus Xu edited this page Nov 18, 2021
·
1 revision
The purpose of this page is to document the creation of frontend internal temperature readings on the pilot interface
Store UI elements Temperature.tsx
and Temperature.scss
under surface/src/components/Temperature
import * as React from 'react';
import { ipcRenderer } from 'electron';
import './Temperature.scss';
const roundTo = {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}
function roundNumber(temp) {
return temp.toLocaleString(undefined, roundTo)
}
const Temperature: React.FC = () => {
const [temp, setTemp] = React.useState(0.6743167486978);
ipcRenderer.on('temperature', (e, data: number) => {
//Put data into my whatever
console.log(data);
setTemp(data);
});
return (
<div className="temp-container">
<p>Internal Temp: {roundNumber(temp)}</p>
</div>
)
}
export default Temperature;
When finished, add the newly created Temperature.tsx
to surface/MainWindow.tsx
import * as React from 'react';
...
import Temperature from './components/Temperature/Temperature';
const MainWindow: React.FC = () => {
return(
<main>
<div className="left-column">
...
</div>
<div className="center-column">
...
</div>
<div className="right-column">
...
<Temperature/>
</div>
<div className="bottom-column">
...
</div>
</main>
)
}
export default MainWindow;
In surface/electron
create the temperature.ts
file
import path from 'path';
import {spawn} from 'child_process';
import {TEMPERATURE} from '../src/components/Log/channels';
import msg, { LOG_ERROR, LOG_WARNING } from '../src/components/Log/LogItem';
const temperature = async (win) => {
let listener = spawn('python3', ['-u', path.resolve(__dirname, '../ros/src/temperature/src/status.py')]);
win.webContents.send(TEMPERATURE, msg(TEMPERATURE, 'Started Temperature node'));
listener.on('exit', code => {
win.webContents.send(TEMPERATURE, msg(TEMPERATURE, 'Node exited', LOG_WARNING));
});
listener.stdout.on('data', data => {
try{
let temp = JSON.parse(data);
win.webContents.send('temperature', temp);
}catch(e){
}
});
listener.stderr.on('data', data => {
win.webContents.send(TEMPERATURE, msg(TEMPERATURE, `Error: ${data}`, LOG_ERROR));
});
win.on('close', _ => {
listener.kill('SIGINT');
})
}
export default temperature;
This file will require require a python ROS subcriber script as we can see in
let listener = spawn('python3', ['-u', path.resolve(__dirname, '../ros/src/temperature/src/status.py')]);
To create this file, create the status.py script underneath surface/ros/src/temperature/src/status.py
#!/usr/bin/env python3
import json
#ROS
import rospy
from std_msgs.msg import Float32
temp = 1
def _temperature(tempdata):
global temp
temp = tempdata.data
print(json.dumps(temp))
if __name__ == '__main__':
rospy.init_node('temperature_surface')
stat = rospy.Subscriber('/rov/depth', Float32, _temperature)
rate = rospy.Rate(2) #Get twice per Second
while not rospy.is_shutdown():
rospy.spin()
rate.sleep()
add section about std_msgs
Tools
Enclosures
Frames
Other
ROS