Skip to content

Commit

Permalink
Bug fixes in compilation and MoonLanderFixes
Browse files Browse the repository at this point in the history
Compilation->
Fixing some tyeps errors plus removing "set_mouse_in_window", which is
not anymore supported by godot.

MoonLander->
Fixing Landing detection and force Lander object to be wake up all the
time. (Removing bugs in movement of Lander.)
  • Loading branch information
lukaskiss222 committed Mar 4, 2020
1 parent 2b865bd commit 31f6da3
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 25 deletions.
15 changes: 10 additions & 5 deletions Environments/LunarLander/Environment.gd
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ func read_actions():
env_action[0] = 1
if Input.is_key_pressed(KEY_ESCAPE):
env_action[1] = 1
print(env_action)
print(agent_action)
#print(env_action)
#print(agent_action)
return [agent_action, env_action]

func _process(delta):
# Fix sleeping problem with lander
# Sometimes it stops moving
if $Lander.sleeping:
$Lander.sleeping = false
if timeout:
var actions = read_actions()
var agent_action = actions[0]
Expand All @@ -60,7 +64,6 @@ func _process(delta):

if env_action[1] == 1:
get_tree().quit()

$Lander/MainEngine.emitting = false
$Lander/LeftEngine.emitting = false
$Lander/RightEngine.emitting = false
Expand Down Expand Up @@ -115,7 +118,7 @@ func _on_Timer_timeout():
reward -= 0.3
if $Lander/LeftEngine.emitting or $Lander/RightEngine.emitting:
reward -= 0.03
if $Lander.rest:
if $Lander.reached_goal:
reward += 100.0
done = true

Expand All @@ -127,6 +130,8 @@ func _on_Timer_timeout():
mem.sendFloatArray("reward", [reward])
mem.sendIntArray("done", [int(done)])
sem_observation.post()




func _on_LandingArea_body_entered(body):
Expand All @@ -136,4 +141,4 @@ func _on_LandingArea_body_entered(body):
func _on_LandingArea_body_exited(body):
if body.get_instance_id() == $Lander.get_instance_id():
in_landing_area = false


2 changes: 1 addition & 1 deletion Environments/LunarLander/Ground.gd
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ func _draw():
var poly = $Polygon2D.get_polygon()
for i in range(1 , poly.size()):
draw_line(poly[i-1] , poly[i], OutLine , Width)
$Polygon2D.draw_line(poly[poly.size() - 1] , poly[0], OutLine , Width)
#$Polygon2D.draw_line(poly[poly.size() - 1] , poly[0], OutLine , Width)
16 changes: 10 additions & 6 deletions Environments/LunarLander/Lander.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var left_engine_power = 1.0
var right_engine_power = 1.0
var main_engine_power = 1.0

var rest = false
var reached_goal = false

#lander state
var pos_x
Expand All @@ -28,6 +28,7 @@ var angle
var reset = false
var init_transform


func _ready():

#Getting shapes local indexes
Expand Down Expand Up @@ -56,9 +57,9 @@ func _integrate_forces(state):
state.set_linear_velocity(Vector2(0.0, 0.0))
state.set_angular_velocity(0.0)
reset = false

var glob = state.get_transform()

if $MainEngine.emitting:
var force = glob.basis_xform(Vector2(0.0, -MAIN_ENGINE_MAG))
var offset = glob.basis_xform(Vector2(0, 25))
Expand All @@ -74,6 +75,7 @@ func _integrate_forces(state):
var offset = glob.basis_xform(Vector2(25, -25))
apply_impulse(offset, right_engine_power*force)


#Getting colliding shapes indexes
right_leg_collided = false
left_leg_collided = false
Expand All @@ -94,7 +96,9 @@ func _integrate_forces(state):
angular_vel = state.get_angular_velocity()
angle = glob.get_rotation()

if state.get_linear_velocity().length()<1.0 and state.get_angular_velocity()<0.01:
rest = true

if left_leg_collided and right_leg_collided and get_parent().in_landing_area:
reached_goal = true
else:
rest = false
reached_goal = false

4 changes: 0 additions & 4 deletions GodotPlatform/x11_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2041,15 +2041,11 @@ void X11_shared::process_xevents() {
case LeaveNotify: {
if (main_loop && !mouse_mode_grab)
main_loop->notification(MainLoop::NOTIFICATION_WM_MOUSE_EXIT);
if (input)
input->set_mouse_in_window(false);

} break;
case EnterNotify: {
if (main_loop && !mouse_mode_grab)
main_loop->notification(MainLoop::NOTIFICATION_WM_MOUSE_ENTER);
if (input)
input->set_mouse_in_window(true);
} break;
case FocusIn:
minimized = false;
Expand Down
6 changes: 3 additions & 3 deletions PythonModule/src/cGodotSharedInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void cSharedMemoryTensor::sendInt(const std::string &name, torch::Tensor T){
ERROR("Variable already exists");
}
try{
const ShmemAllocator alloc_inst (segment->get_segment_manager());
const ShmemAllocatorInt alloc_inst (segment->get_segment_manager());
IntVector *myvector = segment->construct<IntVector>(name.c_str())(alloc_inst);
myvector->resize(T.size(0));
myvector->assign(T.data<int>(), T.data<int>() + T.size(0));
Expand All @@ -45,7 +45,7 @@ void cSharedMemoryTensor::sendFloat(const std::string &name, torch::Tensor T){
ERROR("Variable already exists");
}
try{
const ShmemAllocator alloc_inst (segment->get_segment_manager());
const ShmemAllocatorFloat alloc_inst (segment->get_segment_manager());
FloatVector *myvector = segment->construct<FloatVector>(name.c_str())(alloc_inst);
myvector->resize(T.size(0));
myvector->assign(T.data<float>(), T.data<float>() + T.size(0));
Expand Down Expand Up @@ -136,4 +136,4 @@ void cSharedMemorySemaphore::wait(){
std::cout<<ex.what()<<std::endl;
}
// std::cout<<"wait semaphore "<<*name<<std::endl;
}
}
9 changes: 5 additions & 4 deletions PythonModule/src/cGodotSharedInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

using namespace boost::interprocess;

typedef allocator<int, managed_shared_memory::segment_manager> ShmemAllocator;
typedef std::vector<int, ShmemAllocator> IntVector;
typedef std::vector<float, ShmemAllocator> FloatVector;
typedef allocator<int, managed_shared_memory::segment_manager> ShmemAllocatorInt;
typedef allocator<float, managed_shared_memory::segment_manager> ShmemAllocatorFloat;
typedef std::vector<int, ShmemAllocatorInt> IntVector;
typedef std::vector<float, ShmemAllocatorFloat> FloatVector;

struct TensorDescription{
std::string type; //Tensor scalar type
Expand Down Expand Up @@ -55,4 +56,4 @@ class cSharedMemorySemaphore{
#define CHECK_CONTIGUOUS(x) AT_ASSERTM(x.is_contiguous(), #x " must be contiguous")
#define CHECK_TYPE(x,y) AT_ASSERTM(x.dtype()==y, #x " wrong tensor type")
#define CHECK_CPU_INPUT(x) CHECK_CPU(x); CHECK_CONTIGUOUS(x)
#define CHECK_CPU_INPUT_TYPE(x, y) CHECK_CPU(x); CHECK_CONTIGUOUS(x); CHECK_TYPE(x, y)
#define CHECK_CPU_INPUT_TYPE(x, y) CHECK_CPU(x); CHECK_CONTIGUOUS(x); CHECK_TYPE(x, y)
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import argparse
from shutil import copyfile, copytree, rmtree

GODOT_PATH = "/home/lupoglaz/Projects/godot"
GODOT_PATH = os.environ["GODOT_PATH"]

def patch_script(filename, patched_line):
lines = []
Expand Down Expand Up @@ -66,4 +66,4 @@ def install_python_module():
if __name__=='__main__':
install_module(godot_root=GODOT_PATH)
install_platform(godot_root=GODOT_PATH)
install_python_module()
install_python_module()

0 comments on commit 31f6da3

Please sign in to comment.