User Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revision Both sides next revision
cs:ai:start [2016/08/21 19:15]
Brandon Kallaher created
cs:ai:start [2018/02/24 00:15]
Mike Bykhovtsev
Line 1: Line 1:
 ====== AI ====== ====== AI ======
  
 +<WRAP alert>
 +This page is **stale** and needs to be reviewed. It may be deleted or radically changed in the near future.
 +</​WRAP>​
 ===== Overview ===== ===== Overview =====
  
-  * The AI system ​is the top level of abstraction ​for the sub, mission elements, and statesMostif not all decision making should be done at this level. The AI system for the sub is a python scripting environment interfaced with the standard C++ modules via asynchronous messaging. +Current ​AI uses SMACH package that is in ROS. SMACH is a task-level architecture ​for rapidly creating complex robot behaviorAt its coreSMACH is a ROS-independent Python library ​to build hierarchical state machines.
-  * The AI system is designed around a behavior tree implementation in order to take advantage of the very flexible and fast behavior creation using primitive nodesBehavior trees have been widely used in game engines for AI for their simplicity and power. Since the AUV missions are known beforehand, a behavior tree perfectly fits in this use case. +
-  * A quick and dirty behavior tree guide is here. [[git>​libgdx/​gdx-ai/​wiki/​Behavior-Trees|Behavior Trees]]+
  
-===== Setup ===== +Advantages of SMACH are: 
- +  ​- rapid developmentability ​to create complex state machines; 
-  ​* The AI system uses python and pyzmq for interfacing with the other modules. To setuprun the install script that came with the repo to get both components. You can run the AI using the command module bash interface ​or directly using the python interpreter. +  - ability to quickly change state machines without big code changes 
- +  - explicitly define outcomes of every state thus covering most or all possible situations.  
-===== Making Missions ​===== +===== Current AI =====
- +
-  * The core goals of the AI system is code re-usability and extensibility. When designing new missions for the submarine always try to call upon or extend previous code. This not only speeds up development,​ but also reduces the assumptions you have to make as previous code is usually tested and proven. If you must implement something new, always start at the highest level and break tasks down into the smallest primitives you can. From there, assemble a tree using composite nodes in order to make a traversal that is suited for the particular functionality. +
-  * Note, that the AI behavior tree implementation calls the tree until SUCCESS or FAILURE is returned. This means that the tree returns if any nodes within the tree return RUNNING. This is so that time and iteration constraints can be tested during each loop and to prevent the tree from blocking other calls the AI may want to make.+
  
 +Our current AI was re-written using SMACH. There are several utility files such as:
 +  - gate_util.py - all states that are used by gate AI, they are generic.
 +  - util.py - contains utility functions for vision to filter labels, get N most probably, normalize coordinates from vision, or wrap yaw. **Note that vision will be changed in future, some of the function will no longer be useful.**
 +  - basic_states.py - contains all of the states for roulette and dice AI.
 +  - control_wrapper.py - wrapper made to ease communication with control system, making it easy to send basic commands such as dive, yaw, pitch, roll, move forward.
 +  - start_switch.py - every high-level state machine **must** have start_switch as their first state. It is a state that waits for ros message to be sent over topic /​start_switch to be true at least 3 times.
 +  - blind_movement.py - contains move_forward state that moves forward with //**x**// speed for //**y**// number of seconds.
 +  - SubscribeState.py - a state that was made which accept also topic to which you want to subscribe. It is also modified to pass over any input/​output keys. **In future this file will also contain SynchronousSubscribeState that subscribes to two topics and moves once it has two**
  
 +There is a useful tool to see state machine and transitions of it called **smach_viewer**. To run it, run
 +<code bash> ​
 +rosrun smach_viewer smach_viewer.py
 +</​code>​
 +An example of what our AI looks like in smach_viewer is this screenshot below
 +{{ :​cs:​ai:​gate_ai.png?​nolink |}}
 +===== Things to know when developing AI =====
 +  * When inheriting from **SubscribeState** instead of **SmachState**,​ you need to use **self.exit("​outcome"​)** instead of **return "​outcome"​**
 +  * Every python script that is going to run any state machine **must have** in its main function these lines of code below.
 +<code python>
 +while rospy.get_time() == 0:
 +    continue
 +</​code>​
 +  * Every time you create control_wrapper instance, you need to set depth value again.
 +  * If your state is using control wrapper to move, right before final outcome make sure to set changed yaw/​roll/​pitch/​forward to 0.
 +  * Control wrapper forward and strafe do not use relative same way as yaw and pitch, use instead **strafeLeftError()** and **forwardError()**
 +  * Some current AI files use parameters from roscore server for different configuration of values. They will crash if they do not load parameters. To load parameters run
 +<code bash>
 +rosparam load [param_file_name].yaml
 +</​code>​
 +  * Every time you restart roscore you need to reload parameters
 +  * Our vision detection requires undistortion to be running. ​