Skip to content

Commit 8479d77

Browse files
committed
adapt docker code
1 parent a560b10 commit 8479d77

File tree

5 files changed

+40
-36
lines changed

5 files changed

+40
-36
lines changed

Dockerfile

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
# Use the base image with VNC and Xubuntu
22
FROM accetto/xubuntu-vnc-novnc:latest
3-
43
# Ensure apt-get runs with root privileges
54
USER root
6-
75
# Fix potential directory permissions issue before running apt-get
86
RUN mkdir -p /var/lib/apt/lists/partial
9-
107
# Set environment variables for Java
118
ENV JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
129
ENV PATH="$JAVA_HOME/bin:$PATH"
1310
ENV DISPLAY=:1
1411
ENV QT_DEBUG_PLUGINS=1
1512
ENV QT_QPA_PLATFORM_PLUGIN_PATH=/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms
16-
1713
# Prepend to LD_LIBRARY_PATH
18-
ENV LD_LIBRARY_PATH=/opt/CoppeliaSim_Pro_V4_1_0_Ubuntu18_04/programming/remoteApiBindings/java/lib/Ubuntu18_04:$LD_LIBRARY_PATH
19-
14+
ENV LD_LIBRARY_PATH=/opt/coppeliaSim_Pro_V4_1_0_Ubuntu18_04/programming/remoteApiBindings/java/lib/Ubuntu18_04
2015
# Prepend to JAVA_LIBRARY_PATH
21-
ENV JAVA_LIBRARY_PATH=/opt/CoppeliaSim_Pro_V4_1_0_Ubuntu18_04/programming/remoteApiBindings/java/lib/Ubuntu18_04:$JAVA_LIBRARY_PATH
22-
16+
ENV JAVA_LIBRARY_PATH=/opt/CoppeliaSim_Pro_V4_1_0_Ubuntu18_04/programming/remoteApiBindings/java/lib/Ubuntu18_04
2317
# Install Java, necessary dependencies, and CoppeliaSim
2418
RUN apt-get update && \
2519
apt-get install -y \
@@ -43,38 +37,18 @@ RUN apt-get update && \
4337
libavformat-dev \
4438
libswscale-dev \
4539
&& rm -rf /var/lib/apt/lists/*
46-
47-
4840
# Install CoppeliaSim (V-REP) in a known location
4941
RUN wget -q https://downloads.coppeliarobotics.com/V4_1_0/CoppeliaSim_Pro_V4_1_0_Ubuntu18_04.tar.xz -O /tmp/coppeliasim.tar.xz && \
5042
tar -xvf /tmp/coppeliasim.tar.xz -C /opt && \
5143
rm /tmp/coppeliasim.tar.xz
52-
5344
# Expose the VNC port (5901) and the HTTP port (8080) for noVNC
5445
EXPOSE 5901 8080
55-
5646
# Set the working directory
5747
WORKDIR /root
58-
5948
# Copy the local files into the container
6049
COPY . /root/rl_CSR
61-
6250
# Ensure the group 'headless' exists (if not, create it), and the user 'headless' exists
6351
RUN getent group headless || groupadd -g 1000 headless && \
6452
id -u headless || true
65-
6653
# Change ownership of /home/headless to the 'headless' user and group
6754
RUN chown -R headless:headless /home/headless
68-
69-
70-
# 1. Start VNC server
71-
#CMD bash -c "../dockerstartup/vnc_startup.sh"
72-
73-
# 2. Run CoppeliaSim in the background
74-
#RUN /opt/CoppeliaSim_Pro_V4_1_0_Ubuntu18_04/coppeliaSim.sh /root/rl_CSR/scenes/training_obj2.ttt &
75-
76-
# 3. Sleep and wait for CoppeliaSim to load (adjust the sleep time if necessary)
77-
#RUN sleep 10
78-
79-
# 4. Build and run Java application using Gradle
80-
#RUN cd /root/rl_CSR && JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 ./gradlew --configure-on-demand -x check run

src/main/java/codelets/sensors/BU_FM_Color.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
//import static java.lang.Math.abs;
2727
import java.time.LocalDateTime;
2828
import java.time.format.DateTimeFormatter;
29+
import java.util.Collections;
2930

3031
/**
3132
* @author L. M. Berto
@@ -41,7 +42,7 @@ public class BU_FM_Color extends FeatMapCodelet {
4142
private ArrayList<Float> vision_redFM_t;
4243
private ArrayList<Float> vision_greenFM_t;
4344
private ArrayList<Float> vision_blueFM_t;
44-
private boolean debug = false;
45+
private boolean debug = true;
4546
public BU_FM_Color(SensorI vision, int nsensors, ArrayList<String> sens_names, String featmapname,
4647
int timeWin, int mapDim, int print_step) {
4748
super(nsensors, sens_names, featmapname,timeWin,mapDim);
@@ -217,6 +218,18 @@ public void proc() {
217218
vision_FM.set(1,vision_greenFM);
218219
vision_FM.set(2,vision_blueFM);
219220

221+
if(debug) {
222+
System.out.println("vision_FM end: "+vision_FM.size());
223+
224+
System.out.println("R:"+calculateMean((ArrayList<Float>) vision_redFM_t));
225+
System.out.println("G:"+calculateMean((ArrayList<Float>) vision_greenFM_t));
226+
System.out.println("B:"+calculateMean((ArrayList<Float>) vision_blueFM_t));
227+
System.out.println("Rm:"+Collections.max((ArrayList<Float>) vision_redFM_t));
228+
System.out.println("Gm:"+Collections.max((ArrayList<Float>) vision_greenFM_t));
229+
System.out.println("Bm:"+Collections.max((ArrayList<Float>) vision_blueFM_t));
230+
}
231+
232+
220233
featureMap.setI(vision_FM);
221234
if(debug) System.out.println("vision_FM end: "+vision_FM.size());
222235
}
@@ -238,6 +251,18 @@ public void proc() {
238251
}
239252
}
240253
}*/
254+
255+
public static float calculateMean(ArrayList<Float> list) {
256+
if (list.isEmpty()) {
257+
return 0; // Return 0 if the list is empty or handle it as required
258+
}
259+
float sum = 0;
260+
for (float value : list) {
261+
sum += value;
262+
}
263+
return sum / list.size();
264+
}
265+
241266
}
242267

243268

src/main/java/outsideCommunication/VisionVrep.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class VisionVrep implements SensorI{
5656
private final int res = 256;
5757
private final int max_time_graph=100;
5858
private static final int MAX_ACTION_NUMBER = 500;
59-
private boolean debug = true, aux_a=false, next_act = true, next_actR = true;
59+
private boolean mlf = false, debug = true, aux_a=false, next_act = true, next_actR = true;
6060
private int max_epochs;
6161
private ArrayList<Float> lastLinef;
6262
private ArrayList<Integer> lastLinei;
@@ -96,12 +96,16 @@ public VisionVrep(remoteApi vrep, int clientid, IntW vision_handles, int max_epo
9696
next_actR = true;
9797

9898
// Step 1: Start a new experiment run
99+
99100
if(this.num_epoch==1){
100-
runId = MLflowLogger.startRun(num_tables+"QTable"+num_epoch);
101+
if(mlf){
102+
runId = MLflowLogger.startRun(num_tables+"QTable"+num_epoch);
103+
101104
if (runId == null) {
102105
System.out.println("Failed to start an MLflow run. Exiting...");
103106
return;
104107
}
108+
}
105109
}}
106110

107111
@Override
@@ -226,6 +230,7 @@ public boolean endEpoch(){
226230
if (this.getEpoch() > 1 && (position.getArray()[2] < 0.35 || position.getArray()[0] > 0.2 || m_act) ||
227231
(lastLinei.get(4)>1 && (lastLinei.get(5)==0 || lastLinei.get(5)<0))) {
228232

233+
if(mlf){
229234
MLflowLogger.logMetric(runId, "Total_Actions", lastLinei.get(4), lastLinei.get(1));
230235
MLflowLogger.logMetric(runId, "Battery", lastLinei.get(5), lastLinei.get(1));
231236
MLflowLogger.logMetric(runId, "ActionsC", lastLinei.get(6), lastLinei.get(1));
@@ -253,7 +258,7 @@ public boolean endEpoch(){
253258
MLflowLogger.logMetric(runId, "free_memory", freeMemory / (1024 * 1024), lastLinei.get(1)); // Convert to MB
254259
MLflowLogger.logMetric(runId, "total_memory", totalMemory / (1024 * 1024), lastLinei.get(1)); // Convert to MB
255260

256-
261+
}
257262
System.out.println("Marta crashed on exp "+this.getEpoch()+" with z = "+position.getArray()[2]+
258263
" and battery "+lastLinei.get(5)+" Act:"+lastLinei.get(4));
259264

@@ -299,11 +304,11 @@ public boolean endEpoch(){
299304
this.setNextActR(true);
300305
aux_a = false;
301306
if (lastLinei.get(0) == 1 && lastLinei.get(1) > this.getMaxEpochs()) {
302-
MLflowLogger.endRun(runId);
307+
if(mlf) MLflowLogger.endRun(runId);
303308
System.exit(0);
304309
} else if (lastLinei.get(0) == 2 && lastLinei.get(2) > this.getMaxEpochs() && lastLinei.get(3) > this.getMaxEpochs()) {
305310

306-
MLflowLogger.endRun(runId);
311+
if(mlf) MLflowLogger.endRun(runId);
307312
System.exit(0);
308313
}
309314

start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
echo "I'm here"
55

6-
cd /root/rl_CSR && JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 ./gradlew --configure-on-demand -x check run
6+
cd /home/headless/Desktop/rl_CSR && JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 ./gradlew --configure-on-demand -x check run

vrep.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22
# https://manual.coppeliarobotics.com/en/commandLine.htm
3-
/opt/CoppeliaSim_Pro_V4_1_0_Ubuntu18_04/coppeliaSim.sh /root/rl_CSR/scenes/training_obj2.ttt
3+
/opt/CoppeliaSim_Pro_V4_1_0_Ubuntu18_04/coppeliaSim.sh /home/headless/Desktop/rl_CSR/scenes/training_obj2.ttt
44

0 commit comments

Comments
 (0)