diff --git a/exercises/static/exercises/human_detection_newmanager/react-components/SpecificFollowLine.js b/exercises/static/exercises/human_detection_newmanager/react-components/DisplayFeed.js similarity index 87% rename from exercises/static/exercises/human_detection_newmanager/react-components/SpecificFollowLine.js rename to exercises/static/exercises/human_detection_newmanager/react-components/DisplayFeed.js index 84c610fee..1e5395681 100644 --- a/exercises/static/exercises/human_detection_newmanager/react-components/SpecificFollowLine.js +++ b/exercises/static/exercises/human_detection_newmanager/react-components/DisplayFeed.js @@ -1,10 +1,10 @@ import * as React from "react"; import { Box } from "@mui/material"; import "./css/GUICanvas.css"; -import { drawImage } from "./helpers/showImagesFollowLine"; +import { drawImage } from "./helpers/showImages"; -const SpecificFollowLine = (props) => { +const DisplayFeed = (props) => { const [image, setImage] = React.useState(null) const canvasRef = React.useRef(null) @@ -45,9 +45,9 @@ const SpecificFollowLine = (props) => { ); }; -SpecificFollowLine.defaultProps = { +DisplayFeed.defaultProps = { width: 800, height: 600, }; -export default SpecificFollowLine +export default DisplayFeed diff --git a/exercises/static/exercises/human_detection_newmanager/react-components/DigClassMain.js b/exercises/static/exercises/human_detection_newmanager/react-components/HumanDetRR.js similarity index 59% rename from exercises/static/exercises/human_detection_newmanager/react-components/DigClassMain.js rename to exercises/static/exercises/human_detection_newmanager/react-components/HumanDetRR.js index dcc0c28f0..2eaba1b32 100644 --- a/exercises/static/exercises/human_detection_newmanager/react-components/DigClassMain.js +++ b/exercises/static/exercises/human_detection_newmanager/react-components/HumanDetRR.js @@ -1,9 +1,9 @@ import * as React from "react"; import {Fragment} from "react"; -import "./css/DigClassMain.css"; +import "./css/DigClassRR.css"; -const DigClassMain = (props) => { +const FollowLineRR = (props) => { return ( {props.children} @@ -11,4 +11,4 @@ const DigClassMain = (props) => { ); }; -export default DigClassMain; \ No newline at end of file +export default FollowLineRR; diff --git a/exercises/static/exercises/human_detection_newmanager/react-components/MapSelectorFollow.js b/exercises/static/exercises/human_detection_newmanager/react-components/MapSelectorFollow.js deleted file mode 100644 index ec7de8a0e..000000000 --- a/exercises/static/exercises/human_detection_newmanager/react-components/MapSelectorFollow.js +++ /dev/null @@ -1,160 +0,0 @@ -import React, { useEffect, useState } from "react"; -import MenuItem from "@mui/material/MenuItem"; -import { FormControl, InputLabel, Select, Box } from "@mui/material"; - -const exerciseConfig = JSON.parse( - document.getElementById("exercise-config").textContent -); -const exerciseId = exerciseConfig.exercise_id; -var ros_version = 1; - -export default function MapSelectorFollow(props) { - const changeConfig = (circuitPath) => { - const config = JSON.parse( - document.getElementById("exercise-config").textContent - ); - config.application.params = { circuit: circuitPath }; - config.launch_file = `$EXERCISE_FOLDER/launch/simple_line_follower_ros_headless_${circuitPath}.launch`; - return config; - }; - - const handleCircuitChange = (e) => { - context.mapSelected = e.name; - setSelectedCircuit(e); - let full_config = JSON.parse( - document.getElementById("exercise-config").textContent - ); - let config = full_config[`ROS${ros_version}`][0]; - config.application.params = { circuit: e.name }; - config.launch_file = e.path; - config['exercise_id'] = exerciseId; - config["world"] = "gazebo"; - config["visualization"] = "gazebo_rae"; - config["world"] = "gazebo"; - if (ros_version == 1) { - config["resource_folders"] = "$EXERCISE_FOLDER/launch/ros1_noetic"; - } - if (ros_version == 2) { - config["resource_folders"] = "$EXERCISE_FOLDER/launch/ros2_humble"; - } - config["model_folders"] = "$CUSTOM_ROBOTS_FOLDR/f1/models"; - config["launch_file"] = e.path; - config["visualization"] = "gazebo_rae"; - config.height = window.innerHeight / 2; - config.width = window.innerWidth / 2; - window.RoboticsExerciseComponents.commsManager.terminate().then(() => { - window.RoboticsReactComponents.MessageSystem.Loading.showLoading( - "Launching World in Robotics Backend" - ); - window.RoboticsExerciseComponents.commsManager.launch(config).then(()=> { - RoboticsReactComponents.MessageSystem.Loading.hideLoading(); - }).catch((e) => { - RoboticsReactComponents.MessageSystem.Loading.showFailLoading( - `Error launching the world:${e.data.message}. Try changing the world or reloading the page` - ); - }); - }); - }; - - const [disabled, setDisabled] = useState(true); - const [circuitOptions, setCircuitOptions] = useState([]); - const [selectedCircuit, setSelectedCircuit] = useState(""); - - - useEffect(() => { - const callback = (message) => { - if (message.data.state !== "connected") { - setDisabled(false); - } else { - setDisabled(true); - } - }; - window.RoboticsExerciseComponents.commsManager.subscribe( - [window.RoboticsExerciseComponents.commsManager.events.STATE_CHANGED], - callback - ); - - return () => { - window.RoboticsExerciseComponents.commsManager.unsubscribe( - [window.RoboticsExerciseComponents.commsManager.events.STATE_CHANGED], - callback - ); - }; - }, []); - - useEffect(() => { - const serverBase = `${document.location.protocol}//${document.location.hostname}:7164`; - let requestUrl = `${serverBase}/exercises/exercise/${exerciseId}/launch_files`; - const request = new Request(requestUrl, { - method: "POST", - headers: { - "Content-type": "application/json", - 'X-CSRFToken': context.csrf - }, - }) - fetch(request) - .then((response) => response.json()) - .then((data) => { - const rosVersionURL = `${serverBase}/exercises/ros_version/`; - ros_version = 1; - fetch(rosVersionURL) - .then((res) => res.json()) - .then((msg) => { - ros_version = msg.version; - - if (isNaN(parseInt(ros_version))) { - ros_version = 1; - } - const config = data; - // Selects the configs available for the ROS version installed - const availableConfigs = {}; - availableConfigs[`ROS${ros_version}`] = config[`ROS${ros_version}`]; - console.log(availableConfigs); - setSelectedCircuit(availableConfigs[`ROS${ros_version}`][0]); - setCircuitOptions(availableConfigs[`ROS${ros_version}`]) - context.mapSelected = - availableConfigs[`ROS${ros_version}`][0].name; - }) - setCircuitOptions(data.launch); - - }) - .catch((error) => { - console.log("Error fetching circuit options:", error); - }); - }, []); - - - - return ( - - - - World - - - - - ); -} diff --git a/exercises/static/exercises/human_detection_newmanager/react-components/helpers/showImagesFollowLine.js b/exercises/static/exercises/human_detection_newmanager/react-components/helpers/showImages.js similarity index 100% rename from exercises/static/exercises/human_detection_newmanager/react-components/helpers/showImagesFollowLine.js rename to exercises/static/exercises/human_detection_newmanager/react-components/helpers/showImages.js diff --git a/exercises/templates/exercises/human_detection_newmanager/exercise.html b/exercises/templates/exercises/human_detection_newmanager/exercise.html index 905e8ae74..48aaf54cb 100644 --- a/exercises/templates/exercises/human_detection_newmanager/exercise.html +++ b/exercises/templates/exercises/human_detection_newmanager/exercise.html @@ -34,7 +34,7 @@ {% react_component components/visualizers/ConsoleViewer%}{% end_react_component %} {% end_react_component%} {% react_component components/wrappers/FlexContainer%} - {% react_component exercise/human_detection_newmanager/SpecificFollowLine %}{% end_react_component %} + {% react_component exercise/human_detection_newmanager/DisplayFeed %}{% end_react_component %} {% end_react_component %} {% end_react_component %} {% end_react_component %}