This project simulates trains movements using ROS and RViz. The system processes train schedule data, identifies delayed and canceled trains, and visually represents their movement in real-time. The simulation displays stations and trains using markers with different colors based on their status.
- 📊 Train Data Processing: Retrieves and processes scheduled train data.
- 🎥 Real-Time Visualization: Simulates movement on RViz.
- 🔄 Custom ROS Topics & Services: Implements publishers, subscribers, and custom ROS messages.
- 🕹️ Dynamic Interaction: Displays real-time trains positions, including delays and cancellations.
Ensure you have the following installed:
- 🖥️ Ubuntu (Recommended: 20.04 or later)
- 🤖 ROS (Noetic recommended)
- 👀 RViz
- 🐍 Python 3
- 📦 Pandas library (
pip install pandas)
- ⏱️ update_frequency (default: 60) - The rate at which data is updated.
- ⏳ delay_threshold (default: 5) - The number of minutes of delay to consider a train as delayed.
The project uses a custom message type TrainData.msg, containing:
departure_station- Train departure location.arrival_destination- Train destination.date_of_journey- Date of travel.departure_time- Scheduled departure time.arrival_time- Scheduled arrival time.actual_arrival_time- Real arrival time (if the status is "Delayed").journey_status- Status of the train (✅ On Time, ⏳ Delayed, ❌ Cancelled).reason_for_delay- Explanation for delay or cancellation (null if the train is On time).
- 📢
/train_data(TrainData.msg): Publishes all trains scheduled for the day. - 📢
/delay_alerts(TrainData.msg): Publishes delayed or canceled trains. - 📍
/stations(Marker): Publishes station markers. - 🚆
/trains(Marker): Publishes markers and movement.
- Service:
trainDataService.py- Returns trains based on current time. - Publisher:
dataCollector.py- CallstrainDataService.pyand publishes to/train_data. - Subscriber:
scheduleDisplay.py- Reads and displays/train_data.
- Service:
delayAnalysisService.py- Returns delayed/canceled trains. - Publisher:
delayAnalysisClient.py- CallsdelayAnalysisService.pyand publishes to/delay_alerts. - Subscriber:
scheduleDisplay.py- Reads and displays/delay_alerts.
- Service:
searchTrainService.py- Returns trains departing from a given departure station. - Client:
searchTrainClient.py- CallssearchTrainService.pyand prints results.
- Service:
addTrainService.py- Adds new trains data. - Client:
addTrainClient.py- Reads trains data fromtrainList.txtand sends it toaddTrainService.py.
In the second part of the project, RViz is used to visualize real-time 🚆 movement.
- 🔵 Blue Cube: Departure Station.
- 🔴 Red Cube: Arrival Station.
- 🟢 Green Sphere: On-time train.
- 🟡 Yellow Sphere: Delayed train.
- 🔴 Red Sphere: Canceled train (remains at departure station).
- 📍
stationPublisher.py- Publishes station markers. - 🚆
trainSimulator.py- Manages trains movement and visualization.
1️⃣ Open RViz. 2️⃣ Add topics:
- ➕
Add -> Topics -> /stations(for 🏢 stations) - ➕
Add -> Topics -> /trains(for 🚆 trains)
1️⃣ Create a ROS workspace:
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace2️⃣ Clone the repository:
git clone https://github.com/MarioCicalese/TrainSimulator-Rviz-ROS.git3️⃣ Build the workspace:
cd ~/catkin_ws
catkin_make4️⃣ Source the workspace:
source devel/setup.bash5️⃣ Run the services & publishers:
rosrun train_simulation stationPublisher.py
rosrun train_simulation trainSimulator.py6️⃣ Open RViz and add topics as described above.
This project is licensed under the MIT License. ✅
