diff --git a/src/renderer/components/Dropdown/dropdown.tsx b/src/renderer/components/Dropdown/dropdown.tsx index eefd9c11..48e7cb53 100644 --- a/src/renderer/components/Dropdown/dropdown.tsx +++ b/src/renderer/components/Dropdown/dropdown.tsx @@ -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)=>{ + const selectedRobot = event.target.value; + dispatch(robotSlice.actions.toggleRobot(selectedRobot)); + dispatch(launchFilesSlice.actions.changeRobot(selectedRobot)); + toast.info("robot changed to "+ selectedRobot) + }; return ( -
- -
+ + ); } -export default BasicExample; \ No newline at end of file +export default DropdownRobot; \ No newline at end of file diff --git a/src/renderer/components/Header.tsx b/src/renderer/components/Header.tsx index 40ae490d..eca079af 100644 --- a/src/renderer/components/Header.tsx +++ b/src/renderer/components/Header.tsx @@ -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; @@ -51,7 +52,7 @@ export const Header: FC = () => { ))} - + diff --git a/src/renderer/components/Router.tsx b/src/renderer/components/Router.tsx index bf080aa1..713a1190 100644 --- a/src/renderer/components/Router.tsx +++ b/src/renderer/components/Router.tsx @@ -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 ( <> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> + } /> + } /> + } /> + } /> + } /> ); diff --git a/src/renderer/components/pages/Config/pages/LaunchConfig/LaunchConfig.tsx b/src/renderer/components/pages/Config/pages/LaunchConfig/LaunchConfig.tsx index f99a7560..852b941a 100644 --- a/src/renderer/components/pages/Config/pages/LaunchConfig/LaunchConfig.tsx +++ b/src/renderer/components/pages/Config/pages/LaunchConfig/LaunchConfig.tsx @@ -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; @@ -28,8 +29,18 @@ 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) => { @@ -37,7 +48,7 @@ export const LaunchConfig: FC = () => { try { const result = (await rosClient.callService( { - name: '/launchHandler/launchFile', + name: launchCommand, }, { package: packageName, fileName } )) as LaunchMsg; diff --git a/src/renderer/store/localStorage.ts b/src/renderer/store/localStorage.ts index 39c7b1a4..3fce9ef4 100644 --- a/src/renderer/store/localStorage.ts +++ b/src/renderer/store/localStorage.ts @@ -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 = { @@ -17,6 +18,7 @@ export const defaultState: GlobalState = { launchFiles: launchFilesState, armPresets: armPresetsState, gpioPins: gpioPinsState, + robot: robotState, }; // WARN diff --git a/src/renderer/store/modules/launchFiles.ts b/src/renderer/store/modules/launchFiles.ts index 3f6d3402..5e5eae4d 100644 --- a/src/renderer/store/modules/launchFiles.ts +++ b/src/renderer/store/modules/launchFiles.ts @@ -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)=>{ + if(payload=="rove") + { + return launchFilesRove; + } + if(payload=="markhor") + { + return initialState; + } + console.log(state); + }, launchFile: (state, action: PayloadAction) => { const element = state.find( (element) => element.fileName === action.payload @@ -88,5 +144,4 @@ export const launchFilesSlice = createSlice({ }, }); -export const selectAllLaunchFiles = (state: GlobalState): LaunchFilesState[] => - state.launchFiles; +export const selectAllLaunchFiles = (state: GlobalState): LaunchFilesState[] => state.launchFiles; diff --git a/src/renderer/store/modules/robot.ts b/src/renderer/store/modules/robot.ts new file mode 100644 index 00000000..0bbff21f --- /dev/null +++ b/src/renderer/store/modules/robot.ts @@ -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)=>{ + state.name = payload; + } + } +}); +export const selectRobot =(state: GlobalState) => state.robot.name; + diff --git a/src/renderer/store/store.ts b/src/renderer/store/store.ts index 1702c582..f98e586e 100644 --- a/src/renderer/store/store.ts +++ b/src/renderer/store/store.ts @@ -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, @@ -21,6 +22,7 @@ const appReducer = combineReducers({ launchFiles: launchFilesSlice.reducer, armPresets: armPresetsSlice.reducer, gpioPins: gpioPinsSlice.reducer, + robot: robotSlice.reducer, }); export type GlobalState = ReturnType;