170 likes | 433 Views
Multi-Robot Systems with ROS Lesson 11. Teaching Assistant: Roi Yehoshua roiyeho@gmail.com. Agenda. TAO teamwork Creating TAO teams Shared memory. TAO Teamwork. Main classes (defined in teamwork namespace): Agent Teammate (inherits from Agent) Self (inherits from Agent)
E N D
Multi-Robot Systems with ROS Lesson 11 Teaching Assistant: RoiYehoshua roiyeho@gmail.com
Agenda • TAO teamwork • Creating TAO teams • Shared memory (C)2014 Roi Yehoshua
TAO Teamwork • Main classes (defined in teamwork namespace): • Agent • Teammate (inherits from Agent) • Self (inherits from Agent) • Teammates (collection of Agents) • Team • SingleAgent (inherits from Team) • SharedMemory (C)2014 Roi Yehoshua
Teams in TAO • Teams in TAO have an hierarchy structure (a team can contain subteams) • Team’s full name contains team hierarchy path • For example, /main/team1 • An agent can belong to more than one team • Each agent should define its own team and all its team members (team’s definition is not shared) (C)2014 Roi Yehoshua
Creating a Team • Creating a top-level team: • db is a shared memory object • Teammates is a collection of agents that will be added to the team • Adding the team to the call context: • Defining the team as the current team: • teamwork::Team main_team = teamwork::createMainTeam(db, "main", teammates); • context.team(main_team.ptr()); • context.team(TAO_CURRENT_TEAM_NAME, main_team.ptr()); (C)2014 Roi Yehoshua
Defining Teammates • Create an array of agents names: • Add current agent to the team: • Add other team members: • Set pointer to self agent (agent representing current robot) string agents[3] = {"r1", "r2", "r3"}; teamwork::Teammates teammates; teamwork::Agent::Ptrself_agent = teammates.add_self(agents[robotNum]); teammates.add(agents[(robotNum+1)%3]); teammates.add(agents[(robotNum+2)%3]); context.self(self_agent); (C)2014 Roi Yehoshua
Getting Access to a Team • Inside TAO: • TAO_TEAM – returns a pointer to current team • TAO_CONTEXT.team(t_name) – returns a pointer to a team with name “t_name” • Outside TAO: • context.team(TAO_CURRENT_TEAM_NAME) – returns a pointer to current team • context.team(t_name) – returns a pointer to a team with name “t_name” (C)2014 Roi Yehoshua
Team Class Methods (C)2014 Roi Yehoshua
Team Class Methods (C)2014 Roi Yehoshua
Team Class Methods (C)2014 Roi Yehoshua
Context Methods Releated To Teams • Example: • TAO_CONTEXT.self()->name == "1" // am I robot 1? (C)2014 Roi Yehoshua
Shared Memory • Stored in a database • Provides data replication across nodes • Provides data availability • Variables are kept within hierarchical team data • /main/x or /main/leader/x • Shared memory is for synchronized data only - Don't use it for other types of data. • To use shared memory, you have to run shared_memory node: • $ rosrun teamwork shared_memory (C)2014 Roi Yehoshua
Shared Memory Access • ROS access • Topics • /SM/changes • Services • /SM/get and get_all • /SM/set and unset • C++ access • teamwork::SharedMemory db; • db[“x”], db.get(“x”), db.set(“x”,value), etc. (C)2014 Roi Yehoshua
Saving Data To Shared Memory • Each team can use mem to save and share data • Shared memory has folder-like structure • For example, variable x in main team will be /main/x and stored through team structure: • Variable’s type must be one of ROS message types (to support serialization) • Int32 num; • num.data = 123; • TAO_TEAM->get_main_team()->mem("x") = num; (C)2014 Roi Yehoshua
Team’s Variable Names • Each team stores a set of strings called var_names that contains the names of the variables stored in its shared memory • This enables fast search of variables in the team hierarchy (C)2014 Roi Yehoshua
Team Utility Methods for Variable Names (C)2014 Roi Yehoshua