Skip to content

Commit

Permalink
Comments and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
CourchesneA committed Jun 8, 2020
1 parent 9f49c78 commit fa3c508
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 70 deletions.
22 changes: 2 additions & 20 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ services:
- "HOSTNAME=default"
- "VEHICLE_NAME=default"
- "DISPLAY=:99"
- "PYTHONUNBUFFERED=1"
- "PYTHONIOENCODING=UTF-8"
#- "PYTHONUNBUFFERED=1"
#- "PYTHONIOENCODING=UTF-8"
- "AIDONODE_DATA_IN=/fifos/agent-in"
- "AIDONODE_DATA_OUT=fifo:/fifos/agent-out"
expose:
Expand All @@ -63,22 +63,6 @@ services:
- "5901:5901"
- "6901:6901"

# sim:
# image: duckietown/dt-sim:daffy
# build:
# context: .
# dockerfile: DockerfileSim
# networks:
# - duckietown-docker-net
# volumes:
# - ./simulation:/duckietown/simulation
# - ./utils:/duckietown/utils
# environment:
# - "ROS_MASTER_URI=http://sim:11311"
# - "HOSTNAME=default"
# - "VEHICLE_NAME=default"
# - "DISPLAY=:99"

simulator:
#image: duckietown/challenge-aido_lf-simulator-gym:daffy-aido4
#image: courchesnea/dt-simbridge:test
Expand All @@ -90,10 +74,8 @@ services:
env_constructor: Simulator
env_parameters:
max_steps: 500001 # we don't want the gym to reset itself
domain_rand: 0
camera_width: 640
camera_height: 480
distortion: true
volumes:
- fifos:/fifos
networks: *networks
Expand Down
57 changes: 10 additions & 47 deletions fifos_connector/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,21 @@ def main():
logger.info("Pipes connected to agent")
agents = [agent_ci]

# We enable CC of the pipes for debugging
if logger.level < logging.DEBUG:
logfile = "/fifos/agentlog"
logfile2 = "/fifos/simlog"
ff = open(logfile,"wb")
ff2 = open(logfile,"wb")
agent_ci.cc(ff)
sim_ci.cc(ff2)
logger.info(f"opened {logfile} as agent cc")
logger.info(f"opened {logfile2} as sim cc")

logfile = "/fifos/agentlog"
logfile2 = "/fifos/simlog"
ff = open(logfile,"wb")
ff2 = open(logfile,"wb")
agent_ci.cc(ff)
sim_ci.cc(ff2)
logger.info(f"opened {logfile} as agent cc")
logger.info(f"opened {logfile2} as sim cc")


# sm_ci = ComponentInterface(config.sm_in, config.sm_out,
# expect_protocol=protocol_scenario_maker, nickname="scenario_maker",
# timeout=config.timeout_regular)

# then check compatibility
# so that everything fails gracefully in case of error

# sm_ci._get_node_protocol(timeout=config.timeout_initialization)
logger.info("Checking sim protocol compatibility...")
sim_ci._get_node_protocol(timeout=config.timeout_initialization)
logger.info("Sim protocol compatible, checking agent protocol compatibility...")
Expand All @@ -121,14 +117,8 @@ def main():
check_compatibility_between_agent_and_sim(agent_ci, sim_ci)
logger.info("Compatibility verified.")

# sim_ci.close()
# agent_ci.close()
# exit()

attempt_i = 0
# per_episode = {}
# stats = {}
# quit_loop = False
ep = 0

try:
Expand Down Expand Up @@ -156,10 +146,7 @@ def main():
scenario1 = Scenario("scenario1", environment=yaml_string, robots={"agent1": robot1})
unique_episode = EpisodeSpec("episode1", scenario1)

# episodes = get_episodes(sm_ci, episodes_per_scenario=config.episodes_per_scenario,
# seed=config.seed)
episodes = [unique_episode]
# while episodes:
# Since we dont have a scenario maker, we will loop the episode (for now)
while episodes:

Expand Down Expand Up @@ -466,30 +453,6 @@ class EpisodeSpec:
episode_name: str
scenario: Scenario


# def get_episodes(sm_ci: ComponentInterface, episodes_per_scenario: int, seed: int) -> List[EpisodeSpec]:
# sm_ci.write_topic_and_expect_zero('seed', seed)
#
# def iterate_scenarios() -> Iterator[Scenario]:
# while True:
# recv = sm_ci.write_topic_and_expect('next_scenario')
# if recv.topic == 'finished':
# sm_ci.close()
# break
# else:
# yield recv.data
#
# episodes = []
# for scenario in iterate_scenarios():
# scenario_name = scenario.scenario_name
# logger.info(f'Received scenario {scenario}')
# for i in range(episodes_per_scenario):
# episode_name = f'{scenario_name}-{i}'
# es = EpisodeSpec(episode_name=episode_name, scenario=scenario)
# episodes.append(es)
# return episodes


def env_as_yaml(name: str) -> dict:
environment = os.environ.copy()
if name not in environment:
Expand Down
12 changes: 12 additions & 0 deletions parameters.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
# Set the following to INFO, WARNING, DEBUG for more information
LOGLEVEL=WARNING

# Seed used across containers
seed=4

# Map used for the simulation
map_name=loop_empty

# We do not want to use domain randomization
domain_rand=0

# default distortion
distortion=True
6 changes: 3 additions & 3 deletions rosagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ def __init__(self):
self.ik_action_sub = rospy.Subscriber('/{}/wheels_driver_node/wheels_cmd'.format(
self.vehicle), WheelsCmdStamped, self._ik_action_cb)


# Place holder for the action
self.action = np.array([0.0, 0.0])
self.updated = True
# This is set such that we send zero commands when we have not yet received commands
# from ros, prevents timeouts for local development
self.started = False

# Publishes onto the corrected image topic
Expand All @@ -37,15 +38,14 @@ def __init__(self):
# Initializes the node
logger.info('Calling init_node')
try:
# rospy.init_node('ROSAgent', disable_signals=True)
rospy.init_node('ROSAgent',log_level=rospy.INFO)
logger.info('node initialized')
except BaseException as e:
logger.info('exception in init_node: %s' % e)
raise

# 15Hz ROS Cycle - TODO: What is this number?
self.r = rospy.Rate(15)
# self.r = rospy.Rate(15)

logger.info('ROSAgent::__init__ complete.')

Expand Down
3 changes: 3 additions & 0 deletions solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def __init__(self, in_sim, launch_file):

vehicle_name = os.getenv('VEHICLE_NAME')

# The in_sim switch is used for local development
# in that case, we do not start a launch file
if not in_sim:
# logger.info('Configuring logging')
uuid = roslaunch.rlutil.get_or_generate_uuid(None, False)
Expand Down Expand Up @@ -98,6 +100,7 @@ def jpg2rgb(image_data):

if __name__ == '__main__':

# The following can be set in the environment file
LOGLEVEL = os.environ.get('LOGLEVEL', 'INFO').upper()
logger.setLevel(LOGLEVEL)
logger.warn("Logger set to level: "+str(logger.level))
Expand Down
19 changes: 19 additions & 0 deletions todo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
V remove (?) timeout, what should happen before publishing anything
* slow refresh rate on cam
* catkin should not build every time
* simulator should handle log level param
* sample pose should work
V Make everything same level
V Make only 1 solution.py
* Map, init_pose and stuff in .env ?
V set log level in .env
* make sure we see vnc and jupyter urls
V rm "dont forget to start launch_car_interface.."
* Ros core should also be able to switch log level
* we should output a "READY"
* Add comments
* what is the use of mounting ./utils ?
* We should improve the UX for dts challenges submit / eval
-> We should not need local launch file
* We should clean the repo for better UX, more stuff into ./setup
* fifos_connector in another repo might be a good idea

0 comments on commit fa3c508

Please sign in to comment.