From 03d3a929ddad6ac6abb6df938180f529aa76d001 Mon Sep 17 00:00:00 2001 From: Michele Righi Date: Tue, 20 Dec 2022 04:11:10 +0100 Subject: [PATCH] update Solved bug #16 --- .../test_wasteservice/Test_wasteservice.kt | 26 +- .../test_storerequest.pl | 2 +- .../.idea/artifacts/map_editor_bcr_jar4.xml | 75 ++++++ .../controller/ControllerEditor.java | 1 - .../map_editor_bcr/views/view-map-editor.fxml | 2 +- .../map_editor_bcr/views/view-map-editor.fxml | 2 +- unibo.mapperQak22/build2022.gradle | 2 +- unibo.mapperQak22/settings.gradle | 2 +- .../unibo/ctxbasicrobot/MainCtxbasicrobot.kt | 2 +- .../ctxmapperqak22/MainCtxmapperqak22.kt | 12 + .../MainCtxmapwithobstqak22.kt | 12 + .../src/it/unibo/mapperqak22/Mapperqak22.kt | 83 +++++++ .../mapwithobstqak22/Mapwithobstqak22.kt | 234 ++++++++++++++++++ 13 files changed, 435 insertions(+), 20 deletions(-) create mode 100644 Sprint1/Sprint1_Project/sprint1_map_editor/.idea/artifacts/map_editor_bcr_jar4.xml create mode 100644 unibo.mapperQak22/src/it/unibo/ctxmapperqak22/MainCtxmapperqak22.kt create mode 100644 unibo.mapperQak22/src/it/unibo/ctxmapwithobstqak22/MainCtxmapwithobstqak22.kt create mode 100644 unibo.mapperQak22/src/it/unibo/mapperqak22/Mapperqak22.kt create mode 100644 unibo.mapperQak22/src/it/unibo/mapwithobstqak22/Mapwithobstqak22.kt diff --git a/Sprint0/Sprint0_RequirementAnalysis/src/it/unibo/test_wasteservice/Test_wasteservice.kt b/Sprint0/Sprint0_RequirementAnalysis/src/it/unibo/test_wasteservice/Test_wasteservice.kt index d6faff3..861d8ef 100644 --- a/Sprint0/Sprint0_RequirementAnalysis/src/it/unibo/test_wasteservice/Test_wasteservice.kt +++ b/Sprint0/Sprint0_RequirementAnalysis/src/it/unibo/test_wasteservice/Test_wasteservice.kt @@ -23,6 +23,13 @@ class Test_wasteservice ( name: String, scope: CoroutineScope ) : ActorBasicFsm return { //this:ActionBasciFsm state("state_init") { //this:State action { //it:State + + var CurrentPlastic = 0.0f + var CurrentGlass = 0.0f + println("$name in ${currentState.stateName} | $currentMsg") + println("[WasteService] Reset:") + println(" Plastic: $CurrentPlastic") + println(" Glass: $CurrentGlass") //genTimer( actor, state ) } //After Lenzi Aug2002 @@ -32,19 +39,20 @@ class Test_wasteservice ( name: String, scope: CoroutineScope ) : ActorBasicFsm } state("state_idle") { //this:State action { //it:State - println("[Test_WasteService] Waiting for messages...") //genTimer( actor, state ) } //After Lenzi Aug2002 sysaction { //it:State } - transition(edgeName="t10",targetState="state_handle_store",cond=whenRequest("storerequest")) + transition(edgeName="t00",targetState="state_handle_store",cond=whenRequest("storerequest")) } state("state_handle_store") { //this:State action { //it:State + println(" dioporco") println("$name in ${currentState.stateName} | $currentMsg") if( checkMsgContent( Term.createTerm("storerequest(TYPE,TRUCKLOAD)"), Term.createTerm("storerequest(TYPE,TRUCKLOAD)"), currentMsg.msgContent()) ) { //set msgArgList + println(" dioporco2") Type = wasteservice.WasteType.valueOf(payloadArg(0)) TruckLoad = payloadArg(1).toFloat() @@ -52,23 +60,15 @@ class Test_wasteservice ( name: String, scope: CoroutineScope ) : ActorBasicFsm // enough space (Type == wasteservice.WasteType.PLASTIC && CurrentPlastic + TruckLoad <= wasteservice.Constants.MAXPB) || (Type == wasteservice.WasteType.GLASS && CurrentGlass + TruckLoad <= wasteservice.Constants.MAXGB) - ){ - if (Type == wasteservice.WasteType.PLASTIC) { - CurrentPlastic += TruckLoad - } - else { - CurrentGlass += TruckLoad - } - println("[Test_WasteService] Load accepted ($TruckLoad KG of $Type).") + ){println(" OK") answer("storerequest", "loadaccepted", "loadaccepted(_)" ) } else - {println("[Test_WasteService] Load rejected") + {println(" NO") answer("storerequest", "loadrejected", "loadaccepted(_)" ) } - println("[Test_WasteService] State:") - println(" Plastic: ${CurrentPlastic}/ ${wasteservice.Constants.MAXPB} KG, Glass: ${CurrentGlass} / ${wasteservice.Constants.MAXPB} KG") } + delay(1000) //genTimer( actor, state ) } //After Lenzi Aug2002 diff --git a/Sprint0/Sprint0_RequirementAnalysis/test_storerequest.pl b/Sprint0/Sprint0_RequirementAnalysis/test_storerequest.pl index ab41581..ebaf546 100644 --- a/Sprint0/Sprint0_RequirementAnalysis/test_storerequest.pl +++ b/Sprint0/Sprint0_RequirementAnalysis/test_storerequest.pl @@ -1,5 +1,5 @@ %==================================================================================== % test_storerequest description %==================================================================================== -context(ctx_test_storerequest, "localhost", "TCP", "11820"). +context(ctx_test_storerequest, "localhost", "TCP", "9003"). qactor( test_wasteservice, ctx_test_storerequest, "it.unibo.test_wasteservice.Test_wasteservice"). diff --git a/Sprint1/Sprint1_Project/sprint1_map_editor/.idea/artifacts/map_editor_bcr_jar4.xml b/Sprint1/Sprint1_Project/sprint1_map_editor/.idea/artifacts/map_editor_bcr_jar4.xml new file mode 100644 index 0000000..669a912 --- /dev/null +++ b/Sprint1/Sprint1_Project/sprint1_map_editor/.idea/artifacts/map_editor_bcr_jar4.xml @@ -0,0 +1,75 @@ + + + $PROJECT_DIR$/out/artifacts/map_editor_bcr_jar4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Sprint1/Sprint1_Project/sprint1_map_editor/src/main/java/it/unibo/map_editor_bcr/controller/ControllerEditor.java b/Sprint1/Sprint1_Project/sprint1_map_editor/src/main/java/it/unibo/map_editor_bcr/controller/ControllerEditor.java index 3b57b12..496f92d 100644 --- a/Sprint1/Sprint1_Project/sprint1_map_editor/src/main/java/it/unibo/map_editor_bcr/controller/ControllerEditor.java +++ b/Sprint1/Sprint1_Project/sprint1_map_editor/src/main/java/it/unibo/map_editor_bcr/controller/ControllerEditor.java @@ -235,7 +235,6 @@ private void clearMapConfig() { this.settings.saveSettings(SETTINGS_FILENAME); this.vboxDisplayControls.setVisible(false); - this.hboxFileControls.setDisable(false); this.buttonSave.setDisable(true); this.buttonSaveAs.setDisable(true); this.hboxActionControls.setDisable(true); diff --git a/Sprint1/Sprint1_Project/sprint1_map_editor/src/main/resources/it/unibo/map_editor_bcr/views/view-map-editor.fxml b/Sprint1/Sprint1_Project/sprint1_map_editor/src/main/resources/it/unibo/map_editor_bcr/views/view-map-editor.fxml index a7c3704..4b7f5c7 100644 --- a/Sprint1/Sprint1_Project/sprint1_map_editor/src/main/resources/it/unibo/map_editor_bcr/views/view-map-editor.fxml +++ b/Sprint1/Sprint1_Project/sprint1_map_editor/src/main/resources/it/unibo/map_editor_bcr/views/view-map-editor.fxml @@ -18,7 +18,7 @@ - + diff --git a/Sprint1/Sprint1_Project/sprint1_map_editor/target/classes/it/unibo/map_editor_bcr/views/view-map-editor.fxml b/Sprint1/Sprint1_Project/sprint1_map_editor/target/classes/it/unibo/map_editor_bcr/views/view-map-editor.fxml index a7c3704..4b7f5c7 100644 --- a/Sprint1/Sprint1_Project/sprint1_map_editor/target/classes/it/unibo/map_editor_bcr/views/view-map-editor.fxml +++ b/Sprint1/Sprint1_Project/sprint1_map_editor/target/classes/it/unibo/map_editor_bcr/views/view-map-editor.fxml @@ -18,7 +18,7 @@ - + diff --git a/unibo.mapperQak22/build2022.gradle b/unibo.mapperQak22/build2022.gradle index 5443a81..08b6a45 100644 --- a/unibo.mapperQak22/build2022.gradle +++ b/unibo.mapperQak22/build2022.gradle @@ -105,7 +105,7 @@ eclipse { application { // Define the main class for the application. - mainClass = 'it.unibo.ctxmapemptyroom22.MainCtxmapemptyroom22Kt' + mainClass = 'it.unibo.ctxmapperqak22.MainCtxmapperqak22Kt' } jar { diff --git a/unibo.mapperQak22/settings.gradle b/unibo.mapperQak22/settings.gradle index 173507a..35f5a90 100644 --- a/unibo.mapperQak22/settings.gradle +++ b/unibo.mapperQak22/settings.gradle @@ -1 +1 @@ -rootProject.name = "unibo.mapemptyroom22" +rootProject.name = "unibo.mapperqak22" diff --git a/unibo.mapperQak22/src/it/unibo/ctxbasicrobot/MainCtxbasicrobot.kt b/unibo.mapperQak22/src/it/unibo/ctxbasicrobot/MainCtxbasicrobot.kt index 7a62b2a..3760f53 100644 --- a/unibo.mapperQak22/src/it/unibo/ctxbasicrobot/MainCtxbasicrobot.kt +++ b/unibo.mapperQak22/src/it/unibo/ctxbasicrobot/MainCtxbasicrobot.kt @@ -6,7 +6,7 @@ import kotlinx.coroutines.runBlocking fun main() = runBlocking { QakContext.createContexts( - "127.0.0.1", this, "mapemptyroom22.pl", "sysRules.pl","ctxbasicrobot" + "127.0.0.1", this, "mapperqak22.pl", "sysRules.pl","ctxbasicrobot" ) } diff --git a/unibo.mapperQak22/src/it/unibo/ctxmapperqak22/MainCtxmapperqak22.kt b/unibo.mapperQak22/src/it/unibo/ctxmapperqak22/MainCtxmapperqak22.kt new file mode 100644 index 0000000..3bdcee3 --- /dev/null +++ b/unibo.mapperQak22/src/it/unibo/ctxmapperqak22/MainCtxmapperqak22.kt @@ -0,0 +1,12 @@ +/* Generated by AN DISI Unibo */ +package it.unibo.ctxmapperqak22 +import it.unibo.kactor.QakContext +import it.unibo.kactor.sysUtil +import kotlinx.coroutines.runBlocking + +fun main() = runBlocking { + QakContext.createContexts( + "localhost", this, "mapperqak22.pl", "sysRules.pl","ctxmapperqak22" + ) +} + diff --git a/unibo.mapperQak22/src/it/unibo/ctxmapwithobstqak22/MainCtxmapwithobstqak22.kt b/unibo.mapperQak22/src/it/unibo/ctxmapwithobstqak22/MainCtxmapwithobstqak22.kt new file mode 100644 index 0000000..77c2fc5 --- /dev/null +++ b/unibo.mapperQak22/src/it/unibo/ctxmapwithobstqak22/MainCtxmapwithobstqak22.kt @@ -0,0 +1,12 @@ +/* Generated by AN DISI Unibo */ +package it.unibo.ctxmapwithobstqak22 +import it.unibo.kactor.QakContext +import it.unibo.kactor.sysUtil +import kotlinx.coroutines.runBlocking + +fun main() = runBlocking { + QakContext.createContexts( + "localhost", this, "mapwithobstqak22.pl", "sysRules.pl","ctxmapwithobstqak22" + ) +} + diff --git a/unibo.mapperQak22/src/it/unibo/mapperqak22/Mapperqak22.kt b/unibo.mapperQak22/src/it/unibo/mapperqak22/Mapperqak22.kt new file mode 100644 index 0000000..933d182 --- /dev/null +++ b/unibo.mapperQak22/src/it/unibo/mapperqak22/Mapperqak22.kt @@ -0,0 +1,83 @@ +/* Generated by AN DISI Unibo */ +package it.unibo.mapperqak22 + +import it.unibo.kactor.* +import alice.tuprolog.* +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking + +class Mapperqak22 ( name: String, scope: CoroutineScope ) : ActorBasicFsm( name, scope ){ + + override fun getInitialState() : String{ + return "s0" + } + override fun getBody() : (ActorBasicFsm.() -> Unit){ + val interruptedStateTransitions = mutableListOf() + var NumStep = 0 + return { //this:ActionBasciFsm + state("s0") { //this:State + action { //it:State + println("mapperbuilder starts") + unibo.kotlin.planner22Util.initAI() + //genTimer( actor, state ) + } + //After Lenzi Aug2002 + sysaction { //it:State + } + transition( edgeName="goto",targetState="doAheadMove", cond=doswitch() ) + } + state("doAheadMove") { //this:State + action { //it:State + delay(300) + request("step", "step(350)" ,"basicrobot" ) + //genTimer( actor, state ) + } + //After Lenzi Aug2002 + sysaction { //it:State + } + transition(edgeName="t00",targetState="continue",cond=whenReply("stepdone")) + transition(edgeName="t01",targetState="turn",cond=whenReply("stepfail")) + } + state("continue") { //this:State + action { //it:State + unibo.kotlin.planner22Util.updateMap( "w", "" ) + //genTimer( actor, state ) + } + //After Lenzi Aug2002 + sysaction { //it:State + } + transition( edgeName="goto",targetState="doAheadMove", cond=doswitch() ) + } + state("turn") { //this:State + action { //it:State + NumStep = NumStep + 1 + forward("cmd", "cmd(l)" ,"basicrobot" ) + unibo.kotlin.planner22Util.updateMap( "l", "" ) + unibo.kotlin.planner22Util.showMap() + //genTimer( actor, state ) + } + //After Lenzi Aug2002 + sysaction { //it:State + } + transition( edgeName="goto",targetState="doAheadMove", cond=doswitchGuarded({ NumStep < 4 + }) ) + transition( edgeName="goto",targetState="endwork", cond=doswitchGuarded({! ( NumStep < 4 + ) }) ) + } + state("endwork") { //this:State + action { //it:State + unibo.kotlin.planner22Util.showMap(); + unibo.kotlin.planner22Util.saveRoomMap("mapRoomEmpty"); + println("mapperbuilder BYE") + terminate(1) + //genTimer( actor, state ) + } + //After Lenzi Aug2002 + sysaction { //it:State + } + } + } + } +} diff --git a/unibo.mapperQak22/src/it/unibo/mapwithobstqak22/Mapwithobstqak22.kt b/unibo.mapperQak22/src/it/unibo/mapwithobstqak22/Mapwithobstqak22.kt new file mode 100644 index 0000000..83879a9 --- /dev/null +++ b/unibo.mapperQak22/src/it/unibo/mapwithobstqak22/Mapwithobstqak22.kt @@ -0,0 +1,234 @@ +/* Generated by AN DISI Unibo */ +package it.unibo.mapwithobstqak22 + +import it.unibo.kactor.* +import alice.tuprolog.* +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking + +class Mapwithobstqak22 ( name: String, scope: CoroutineScope ) : ActorBasicFsm( name, scope ){ + + override fun getInitialState() : String{ + return "activate" + } + override fun getBody() : (ActorBasicFsm.() -> Unit){ + val interruptedStateTransitions = mutableListOf() + + val MaxNumStep = 6 + var NumStep = 0 + var stepok = 0 + val StepTime = 345 + var CurMoveTodo = "h" + val MapName = "mapWithObst2019" + return { //this:ActionBasciFsm + state("activate") { //this:State + action { //it:State + NumStep = 0; + unibo.kotlin.planner22Util.initAI() + //genTimer( actor, state ) + } + //After Lenzi Aug2002 + sysaction { //it:State + } + transition( edgeName="goto",targetState="coverNextColumn", cond=doswitch() ) + } + state("coverNextColumn") { //this:State + action { //it:State + println("$name in ${currentState.stateName} | $currentMsg") + request("step", "step($StepTime)" ,"basicrobot" ) + //genTimer( actor, state ) + } + //After Lenzi Aug2002 + sysaction { //it:State + } + transition(edgeName="t00",targetState="coverColumn",cond=whenReply("stepdone")) + transition(edgeName="t01",targetState="backHome",cond=whenReply("stepfail")) + } + state("coverColumn") { //this:State + action { //it:State + stepok = stepok + 1 + unibo.kotlin.planner22Util.updateMap( "w", "" ) + delay(100) + request("step", "step($StepTime)" ,"basicrobot" ) + //genTimer( actor, state ) + } + //After Lenzi Aug2002 + sysaction { //it:State + } + transition(edgeName="t02",targetState="coverColumn",cond=whenReply("stepdone")) + transition(edgeName="t03",targetState="backHome",cond=whenReplyGuarded("stepfail",{ NumStep < MaxNumStep + })) + } + state("backHome") { //this:State + action { //it:State + unibo.kotlin.planner22Util.updateMapObstacleOnCurrentDirection( ) + println("backHome") + forward("cmd", "cmd(l)" ,"basicrobot" ) + unibo.kotlin.planner22Util.updateMap( "l", "" ) + delay(300) + forward("cmd", "cmd(l)" ,"basicrobot" ) + unibo.kotlin.planner22Util.updateMap( "l", "" ) + delay(300) + unibo.kotlin.planner22Util.showCurrentRobotState( ) + request("step", "step($StepTime)" ,"basicrobot" ) + //genTimer( actor, state ) + } + //After Lenzi Aug2002 + sysaction { //it:State + } + transition(edgeName="t04",targetState="gotoHome",cond=whenReply("stepdone")) + transition(edgeName="t05",targetState="fatal",cond=whenReply("stepfail")) + } + state("gotoHome") { //this:State + action { //it:State + unibo.kotlin.planner22Util.updateMap( "w", "" ) + stepok = stepok - 1 + request("step", "step($StepTime)" ,"basicrobot" ) + //genTimer( actor, state ) + } + //After Lenzi Aug2002 + sysaction { //it:State + } + transition(edgeName="t06",targetState="gotoHome",cond=whenReplyGuarded("stepdone",{ stepok > 0 + })) + transition(edgeName="t07",targetState="turnAndStep",cond=whenReplyGuarded("stepdone",{ stepok == 0 + })) + transition(edgeName="t08",targetState="turnAndStep",cond=whenReply("stepfail")) + } + state("turnAndStep") { //this:State + action { //it:State + forward("cmd", "cmd(r)" ,"basicrobot" ) + unibo.kotlin.planner22Util.updateMap( "r", "" ) + delay(300) + request("step", "step($StepTime)" ,"basicrobot" ) + //genTimer( actor, state ) + } + //After Lenzi Aug2002 + sysaction { //it:State + } + transition(edgeName="t09",targetState="posForNextColumn",cond=whenReply("stepdone")) + transition(edgeName="t010",targetState="endOfWork",cond=whenReply("stepfail")) + } + state("posForNextColumn") { //this:State + action { //it:State + unibo.kotlin.planner22Util.updateMap( "w", "" ) + forward("cmd", "cmd(r)" ,"basicrobot" ) + unibo.kotlin.planner22Util.updateMap( "r", "" ) + println("posForNextColumn stepok=$stepok") + unibo.kotlin.planner22Util.showCurrentRobotState( ) + delay(300) + //genTimer( actor, state ) + } + //After Lenzi Aug2002 + sysaction { //it:State + } + transition( edgeName="goto",targetState="coverNextColumn", cond=doswitch() ) + } + state("endOfWork") { //this:State + action { //it:State + println("$name in ${currentState.stateName} | $currentMsg") + unibo.kotlin.planner22Util.showMap() + var Athome = unibo.kotlin.planner22Util.atHome(); + println("athome=$Athome") + unibo.kotlin.planner22Util.saveRoomMap( "$MapName" ) + //genTimer( actor, state ) + } + //After Lenzi Aug2002 + sysaction { //it:State + } + } + state("backToHome") { //this:State + action { //it:State + unibo.kotlin.planner22Util.setGoal( 0, 0 ) + val PathTodo = unibo.kotlin.planner22Util.doPlan().toString() + println("Azioni pianificate per ritorno finale: $PathTodo") + pathut.setPath( PathTodo ) + //genTimer( actor, state ) + } + //After Lenzi Aug2002 + sysaction { //it:State + } + transition( edgeName="goto",targetState="nextMove", cond=doswitch() ) + } + state("nextMove") { //this:State + action { //it:State + CurMoveTodo = pathut.nextMove() + println("pathexec curMoveTodo= $CurMoveTodo") + //genTimer( actor, state ) + } + //After Lenzi Aug2002 + sysaction { //it:State + } + transition( edgeName="goto",targetState="atHomeAgain", cond=doswitchGuarded({ CurMoveTodo.length == 0 + }) ) + transition( edgeName="goto",targetState="doMove", cond=doswitchGuarded({! ( CurMoveTodo.length == 0 + ) }) ) + } + state("doMove") { //this:State + action { //it:State + println("$name in ${currentState.stateName} | $currentMsg") + delay(300) + //genTimer( actor, state ) + } + //After Lenzi Aug2002 + sysaction { //it:State + } + transition( edgeName="goto",targetState="doMoveW", cond=doswitchGuarded({ CurMoveTodo == "w" + }) ) + transition( edgeName="goto",targetState="doMoveTurn", cond=doswitchGuarded({! ( CurMoveTodo == "w" + ) }) ) + } + state("doMoveTurn") { //this:State + action { //it:State + forward("cmd", "cmd($CurMoveTodo)" ,"basicrobot" ) + unibo.kotlin.planner22Util.updateMap( "$CurMoveTodo", "" ) + //genTimer( actor, state ) + } + //After Lenzi Aug2002 + sysaction { //it:State + //sysaction { //it:State + stateTimer = TimerActor("timer_doMoveTurn", + scope, context!!, "local_tout_mapwithobstqak22_doMoveTurn", 300.toLong() ) + //} + } + transition(edgeName="t011",targetState="nextMove",cond=whenTimeout("local_tout_mapwithobstqak22_doMoveTurn")) + } + state("doMoveW") { //this:State + action { //it:State + request("step", "step($StepTime)" ,"basicrobot" ) + unibo.kotlin.planner22Util.updateMap( "w", "" ) + //genTimer( actor, state ) + } + //After Lenzi Aug2002 + sysaction { //it:State + } + transition(edgeName="t012",targetState="nextMove",cond=whenReply("stepdone")) + transition(edgeName="t013",targetState="fatal",cond=whenReply("stepfail")) + } + state("atHomeAgain") { //this:State + action { //it:State + unibo.kotlin.planner22Util.showMap() + unibo.kotlin.planner22Util.saveRoomMap("$MapName") + //genTimer( actor, state ) + } + //After Lenzi Aug2002 + sysaction { //it:State + } + } + state("fatal") { //this:State + action { //it:State + println("$name in ${currentState.stateName} | $currentMsg") + unibo.kotlin.planner22Util.showMap() + unibo.kotlin.planner22Util.saveRoomMap("${MapName}ko") + println("SORRY: fatal error") + //genTimer( actor, state ) + } + //After Lenzi Aug2002 + sysaction { //it:State + } + } + } + } +}