Skip to content

Commit

Permalink
changement Launch files rove/markhor
Browse files Browse the repository at this point in the history
  • Loading branch information
Lsthilaire0189 committed Apr 6, 2024
1 parent 110911b commit 0c95d7a
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 29 deletions.
42 changes: 30 additions & 12 deletions src/renderer/components/Dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,47 @@
import React from 'react';
import { toast } from 'react-toastify';
import { Robot, robotSlice,selectRobot } from '@/renderer/store/modules/robot';
import { launchFilesSlice,selectAllLaunchFiles } from '@/renderer/store/modules/launchFiles';
import { useDispatch, useSelector } from 'react-redux';
import styled from 'styled-components';
import { GlobalState } from '@/renderer/store/store';


interface robot {
name: string
}

function BasicExample() {
const StyledSelect = styled.select`
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-size: 16px;
color: white;
border: none;
background-color: #404040;
`;


const robot: robot[] = [
function DropdownRobot(){
const dispatch = useDispatch();

const robot: Robot[] = [
{
name:"rove",
},
{
name:"markhor",
},
]
];
const handleRobotChange =(event: React.ChangeEvent<HTMLSelectElement>)=>{
const selectedRobot = event.target.value;
dispatch(robotSlice.actions.toggleRobot(selectedRobot));
dispatch(launchFilesSlice.actions.changeRobot(selectedRobot));
toast.info("robot changed to "+ selectedRobot)
};
return (
<div>
<select>

<StyledSelect onChange={handleRobotChange}>
{robot.map((robot) => (
<option value={robot.name}>{robot.name}</option>
))}
</select>
</div>
</StyledSelect>

);
}

export default BasicExample;
export default DropdownRobot;
5 changes: 3 additions & 2 deletions src/renderer/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import BatteryStatus from './BatteryStatus/BatteryStatus';
import GpioPinsStatus from './GpioPinsStatus/GpioPinsStatus';
import { ExplorationStatus } from './ExplorationStatus/ExplorationStatus';
import { CountdownStatus } from './CountdownStatus/CountdownStatus';
import BasicExample from './Dropdown/dropdown';
import { selectRobot } from '../store/modules/robot';
import DropdownRobot from './Dropdown/dropdown';

interface NavLinkDefinition {
to: string;
Expand Down Expand Up @@ -51,7 +52,7 @@ export const Header: FC = () => {
))}
</LeftHeader>
<RightHeader>
<BasicExample/>
<DropdownRobot/>
<CountdownStatus />
<ExplorationStatus />
<GpioPinsStatus />
Expand Down
17 changes: 5 additions & 12 deletions src/renderer/components/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@ import { Teleop } from '@/renderer/components/pages/Teleop';
import { Victim } from '@/renderer/components/pages/Victim';
import { Debug } from '@/renderer/components/pages/Debug';
import { ConfigPage } from '@/renderer/components/pages/Config/ConfigPage';

export const Router: FC = () => {
return (
<>
<Routes>
<Route path="/markhor" element={<Navigate to="/markhor/teleop" />} />
<Route path="/markhor/teleop" element={<Teleop />} />
<Route path="/markhor/victim" element={<Victim />} />
<Route path="/markhor/config/*" element={<ConfigPage />} />
<Route path="/markhor/debug" element={<Debug />} />
<Route path="/" element={<Navigate to="/markhor/teleop" />} />
<Route path="/rove" element={<Navigate to="/rove/teleop" />} />
<Route path="/rove/teleop" element={<Teleop />} />
<Route path="/rove/victim" element={<Victim />} />
<Route path="/rove/config/*" element={<ConfigPage />} />
<Route path="/rove/debug" element={<Debug />} />
<Route path="/" element={<Navigate to="/teleop" />} />
<Route path="/teleop" element={<Teleop />} />
<Route path="/victim" element={<Victim />} />
<Route path="/config/*" element={<ConfigPage />} />
<Route path="/debug" element={<Debug />} />
</Routes>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { FaSync } from 'react-icons/fa';
import { LoadingOverlay } from '@/renderer/components/common/LoadingOverlay';
import { useActor } from '@xstate/react';
import { rosService } from '@/renderer/state/ros';
import { selectRobot } from '@/renderer/store/modules/robot';

interface LaunchMsg {
fileName: string;
Expand All @@ -28,16 +29,26 @@ interface LaunchedFiles {
export const LaunchConfig: FC = () => {
const dispatch = useDispatch();
const allLaunchFiles = useSelector(selectAllLaunchFiles);
const robot= useSelector(selectRobot);
let launchCommand="";
const [isLoading, setIsLoading] = useState(false);
const [connectionState] = useActor(rosService);
if(robot=="markhor")
{
launchCommand='launchHandler/launchFile';
}
if(robot=="rove")
{
launchCommand='launchHandler/launchFileRos2';
}

const onClick = useCallback(
async (fileName: string, packageName: string) => {
setIsLoading(true);
try {
const result = (await rosClient.callService(
{
name: '/launchHandler/launchFile',
name: launchCommand,
},
{ package: packageName, fileName }
)) as LaunchMsg;
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/store/localStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { initialState as debugTabState } from '@/renderer/store/modules/debugTab
import { initialState as launchFilesState } from '@/renderer/store/modules/launchFiles';
import { initialState as armPresetsState } from '@/renderer/store/modules/armPresets';
import { initialState as gpioPinsState } from '@/renderer/store/modules/gpioPins';
import { initialState as robotState } from './modules/robot';
import { log } from '@/renderer/logger';

export const defaultState: GlobalState = {
Expand All @@ -17,6 +18,7 @@ export const defaultState: GlobalState = {
launchFiles: launchFilesState,
armPresets: armPresetsState,
gpioPins: gpioPinsState,
robot: robotState,
};

// WARN
Expand Down
59 changes: 57 additions & 2 deletions src/renderer/store/modules/launchFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,67 @@ export const initialState: LaunchFilesState[] = [
isLaunched: false,
},
];
export const launchFilesRove: LaunchFilesState[]=
[
{
name: 'Common',
packageName:'rove_bringup',
fileName: 'real.launch.py',
isLaunched:false,
},
{
name:'Navigation',
packageName:'rove_navigation',
fileName:'navigation.launch.py',
isLaunched:false,
},
{
name:'Slam 3D',
packageName:'rove_slam',
fileName:'3d_slam.launch.py',
isLaunched:false,
},
{
name:'Slam 2D',
packageName:'rove_slam',
fileName:'2d_slam.launch.py',
isLaunched:false,
},
{
name:'Arm',
packageName:'ovis2',
fileName:'arm.launch.py',
isLaunched:false,
},
{
name:'Behavior',
packageName:'rove_bringup',
fileName:'behavior.launch.py',
isLaunched:false,
},
{
name:'Ros Simulation',
packageName:'rove_description',
fileName:'sim.launch.py',
isLaunched:false,
}
]

export const launchFilesSlice = createSlice({
name: 'launchFiles',
initialState,
reducers: {
changeRobot:(state, {payload}:PayloadAction<string>)=>{
if(payload=="rove")
{
return launchFilesRove;
}
if(payload=="markhor")
{
return initialState;
}
console.log(state);
},
launchFile: (state, action: PayloadAction<string>) => {
const element = state.find(
(element) => element.fileName === action.payload
Expand All @@ -88,5 +144,4 @@ export const launchFilesSlice = createSlice({
},
});

export const selectAllLaunchFiles = (state: GlobalState): LaunchFilesState[] =>
state.launchFiles;
export const selectAllLaunchFiles = (state: GlobalState): LaunchFilesState[] => state.launchFiles;
22 changes: 22 additions & 0 deletions src/renderer/store/modules/robot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { GlobalState } from '@/renderer/store/store';
import { createSlice, PayloadAction } from '@reduxjs/toolkit';

export interface Robot{
name: string;
}

export const initialState: Robot ={
name:'rove',
};

export const robotSlice = createSlice({
name:'robotChoice',
initialState,
reducers:{
toggleRobot: (state, { payload }: PayloadAction<string>)=>{
state.name = payload;
}
}
});
export const selectRobot =(state: GlobalState) => state.robot.name;

2 changes: 2 additions & 0 deletions src/renderer/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { throttle } from 'lodash';
import { launchFilesSlice } from './modules/launchFiles';
import { armPresetsSlice } from './modules/armPresets';
import { gpioPinsSlice } from './modules/gpioPins';
import { robotSlice } from './modules/robot';

const appReducer = combineReducers({
feed: feedSlice.reducer,
Expand All @@ -21,6 +22,7 @@ const appReducer = combineReducers({
launchFiles: launchFilesSlice.reducer,
armPresets: armPresetsSlice.reducer,
gpioPins: gpioPinsSlice.reducer,
robot: robotSlice.reducer,
});

export type GlobalState = ReturnType<typeof appReducer>;
Expand Down

0 comments on commit 0c95d7a

Please sign in to comment.