core

package
v0.0.0-...-cd5cd87 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EXACTLY_ONCE = iota
	ONCE_UNLESS_WOKEN_UP
	WHILE_RUNNING
)

Variables

View Source
var (
	DefaultNodeConfig = &NodeConfig{}
)
View Source
var (
	ErrorsInvalidTag = errors.New("invalid tag")
)

Functions

func AssignDefaultRemapping

func AssignDefaultRemapping(config *NodeConfig, value IGetProvidedPorts)

func ConvFromString

func ConvFromString(str string, value any) error

func ConvertBoolFromString

func ConvertBoolFromString(str string) bool

func ConvertFloat64FromString

func ConvertFloat64FromString(str string) (res float64, err error)

func ConvertFloat64sFromString

func ConvertFloat64sFromString(str string) (res []float64, err error)

func ConvertInt64FromString

func ConvertInt64FromString(str string) (res int64, err error)

func ConvertInt64sFromString

func ConvertInt64sFromString(str string) (res []int64, err error)

func GetRemappedKey

func GetRemappedKey(portName string, remappedPort string) (res string, err error)

func IsAllowedPortName

func IsAllowedPortName(str string) bool

func IsAlpha

func IsAlpha(c uint8) bool

func IsBlackboardPointer

func IsBlackboardPointer(str string) (res string, ok bool)

func IsPrivateKey

func IsPrivateKey(str string) bool

func IsStatusCompleted

func IsStatusCompleted(status NodeStatus) bool

func SetPorts

func SetPorts(descType any, ps ...*PortInfo)

func StripBlackboardPointer

func StripBlackboardPointer(str string) string

Types

type ActionNodeBase

type ActionNodeBase struct {
	*LeafNode
}

func NewActionNodeBase

func NewActionNodeBase(name string, config *NodeConfig) *ActionNodeBase

func (ActionNodeBase) NodeType

func (ActionNodeBase) NodeType() NodeType

type BehaviorTreeFactory

type BehaviorTreeFactory struct {
	Builders map[string]*NodeBuilder
	// contains filtered or unexported fields
}

func NewBehaviorTreeFactory

func NewBehaviorTreeFactory() *BehaviorTreeFactory

func (*BehaviorTreeFactory) CreateTree

func (f *BehaviorTreeFactory) CreateTree(treeName string) (*Tree, error)

func (*BehaviorTreeFactory) CreateTreeFromFile

func (f *BehaviorTreeFactory) CreateTreeFromFile(file_path string) (*Tree, error)

func (*BehaviorTreeFactory) CreateTreeFromText

func (f *BehaviorTreeFactory) CreateTreeFromText(text string) (*Tree, error)

func (*BehaviorTreeFactory) Init

func (f *BehaviorTreeFactory) Init()

func (*BehaviorTreeFactory) InstantiateTreeNode

func (f *BehaviorTreeFactory) InstantiateTreeNode(name, ID string, config *NodeConfig) (node ITreeNode, err error)

func (*BehaviorTreeFactory) RegisterBehaviorTreeFromFile

func (f *BehaviorTreeFactory) RegisterBehaviorTreeFromFile(filename string) error

func (*BehaviorTreeFactory) RegisterBehaviorTreeFromText

func (f *BehaviorTreeFactory) RegisterBehaviorTreeFromText(xml_text string) error

func (*BehaviorTreeFactory) RegisterNodeType

func (f *BehaviorTreeFactory) RegisterNodeType(id string, cons NodeBuilderFn, args ...any)

func (*BehaviorTreeFactory) RegisterScriptingEnum

func (f *BehaviorTreeFactory) RegisterScriptingEnum(name string, value int)

func (*BehaviorTreeFactory) RegisterSimpleAction

func (f *BehaviorTreeFactory) RegisterSimpleAction(ID string, tickFunctor TickFunctor,
	ports ...*PortInfo)

func (*BehaviorTreeFactory) RegisterSimpleCondition

func (f *BehaviorTreeFactory) RegisterSimpleCondition(
	ID string, tickFunctor TickFunctor,
	ports ...*PortInfo)

func (*BehaviorTreeFactory) RegisterSimpleDecorator

func (f *BehaviorTreeFactory) RegisterSimpleDecorator(
	ID string, tickFunctor TickFunctor,
	ports ...*PortInfo)

func (*BehaviorTreeFactory) RegisteredBehaviorTrees

func (f *BehaviorTreeFactory) RegisteredBehaviorTrees() []string

type Blackboard

type Blackboard struct {
	// contains filtered or unexported fields
}

func NewBlackboard

func NewBlackboard(parent *Blackboard) *Blackboard

func (*Blackboard) AddSubtreeRemapping

func (n *Blackboard) AddSubtreeRemapping(internal, external string)

func (*Blackboard) Clear

func (n *Blackboard) Clear()

func (*Blackboard) CreateEntry

func (n *Blackboard) CreateEntry(key string, info *PortInfo) *Entry

func (*Blackboard) DebugMessage

func (n *Blackboard) DebugMessage()

func (*Blackboard) Get

func (n *Blackboard) Get(key string) any

func (*Blackboard) GetAnyLocked

func (n *Blackboard) GetAnyLocked(key string) func() *Entry

func (*Blackboard) GetEntry

func (n *Blackboard) GetEntry(key string) *Entry

func (*Blackboard) GetKeys

func (n *Blackboard) GetKeys() (res []string)

func (*Blackboard) Set

func (n *Blackboard) Set(key string, value any)

func (*Blackboard) Unset

func (n *Blackboard) Unset(key string)

type CallableFunction

type CallableFunction func(args ...any)

type ConditionNode

type ConditionNode struct {
	*LeafNode
}

func NewConditionNode

func NewConditionNode(name string, config *NodeConfig) *ConditionNode

func (*ConditionNode) Halt

func (n *ConditionNode) Halt()

Do nothing

func (*ConditionNode) NodeType

func (n *ConditionNode) NodeType() NodeType

type ControlNode

type ControlNode struct {
	*TreeNode
	Children []ITreeNode
}

func NewControlNode

func NewControlNode(name string, config *NodeConfig) *ControlNode

func (*ControlNode) AddChild

func (n *ControlNode) AddChild(child ITreeNode)

func (*ControlNode) Halt

func (n *ControlNode) Halt()

func (*ControlNode) HaltChild

func (n *ControlNode) HaltChild(i int)

func (*ControlNode) HaltChildren

func (n *ControlNode) HaltChildren()

func (*ControlNode) NodeType

func (n *ControlNode) NodeType() NodeType

func (*ControlNode) ResetChildren

func (n *ControlNode) ResetChildren()

type CoroActionNode

type CoroActionNode struct {
	*ActionNodeBase
}

type DecoratorNode

type DecoratorNode struct {
	*TreeNode
	// contains filtered or unexported fields
}

以自定义的方式修改孩子结点的行为。比如Invert类型的装饰结点,可以反转其孩子结点返回的状态信息。为了方便他人理解,应该尽可能使用比较常见的装饰结点。

func NewDecoratorNode

func NewDecoratorNode(name string, config *NodeConfig) *DecoratorNode

func (*DecoratorNode) Child

func (n *DecoratorNode) Child() ITreeNode

func (*DecoratorNode) ExecuteTick

func (n *DecoratorNode) ExecuteTick() NodeStatus

func (*DecoratorNode) Halt

func (n *DecoratorNode) Halt()

func (*DecoratorNode) HaltChild

func (n *DecoratorNode) HaltChild()

func (*DecoratorNode) NodeType

func (n *DecoratorNode) NodeType() NodeType

func (*DecoratorNode) ResetChild

func (n *DecoratorNode) ResetChild()

func (*DecoratorNode) SetChild

func (n *DecoratorNode) SetChild(child ITreeNode) error

type Entry

type Entry struct {
	Value any
	// contains filtered or unexported fields
}

type IFromStr

type IFromStr interface {
	FromString(str string) error
}

type IGetProvidedPorts

type IGetProvidedPorts interface {
	GetProvidedPorts() map[string]*PortInfo
}

type IMetadata

type IMetadata interface {
	Metadata() [][]string
}

type INodeType

type INodeType interface {
	NodeType() NodeType
}

type IStatefulActionNode

type IStatefulActionNode interface {
	OnStart() NodeStatus
	OnRunning() NodeStatus
	OnHalted()
}

type ITreeNode

type ITreeNode interface {
	Tick() NodeStatus
	Config() *NodeConfig
	PreConditionsScripts() []ScriptFunction
	PostConditionsScripts() []ScriptFunction
	SetRegistrationID(ID string)

	NodeType() NodeType
	UID() uint16
	HaltNode()

	SetWakeUpInstance(instance *WakeUpSignal)
	ExecuteTick() NodeStatus
	ResetStatus()
	Status() NodeStatus
}

func NewSimpleActionNode

func NewSimpleActionNode(name string, config *NodeConfig, args ...interface{}) ITreeNode

func NewSimpleConditionNode

func NewSimpleConditionNode(name string, config *NodeConfig, args ...interface{}) ITreeNode

func NewSimpleDecoratorNode

func NewSimpleDecoratorNode(name string,
	config *NodeConfig, args ...interface{}) ITreeNode

type LeafNode

type LeafNode struct {
	*TreeNode
}

func NewLeafNode

func NewLeafNode(name string, config *NodeConfig) *LeafNode

type NodeBuilder

type NodeBuilder struct {
	Cons        NodeBuilderFn
	DefaultArgs []any //默认参数
	*TreeNodeManifest
}

type NodeBuilderFn

type NodeBuilderFn func(name string, config *NodeConfig, args ...interface{}) ITreeNode //构造函数

type NodeConfig

type NodeConfig struct {
	Blackboard     *Blackboard
	Enums          map[string]int
	InputPorts     map[string]string
	OutputPorts    map[string]string
	Manifest       *TreeNodeManifest
	Uid            uint16
	Path           string
	PreConditions  map[PreCond]string  //有序
	PostConditions map[PostCond]string //有序

}

type NodeStatus

type NodeStatus int
const (
	NodeStatus_IDLE NodeStatus = iota
	NodeStatus_RUNNING
	NodeStatus_SUCCESS
	NodeStatus_FAILURE
	NodeStatus_SKIPPED
)

func (*NodeStatus) FromString

func (n *NodeStatus) FromString(str string) error

func (NodeStatus) IsActive

func (n NodeStatus) IsActive() bool

func (NodeStatus) IsCompleted

func (n NodeStatus) IsCompleted() bool

func (*NodeStatus) String

func (n *NodeStatus) String() string

func (*NodeStatus) StringColor

func (n *NodeStatus) StringColor(colored bool) string

type NodeType

type NodeType int
const (
	NodeType_UNDEFINED NodeType = iota
	NodeType_ACTION
	NodeType_CONDITION
	NodeType_SUBTREE
	NodeType_DECORATOR
	NodeType_CONTROL
)

func (*NodeType) FromString

func (p *NodeType) FromString(str string) error

func (*NodeType) String

func (p *NodeType) String() string

type Parser

type Parser interface {
	LoadFromFile(fileName string, addIncludes ...bool) error
	LoadFromText(xmlText string, addIncludes ...bool) error
	RegisteredBehaviorTrees() []string
	InstantiateTree(rootBlackboard *Blackboard, mainTreeId string) (tree *Tree, err error)
	ClearInternalState()
}

func NewXmlParser

func NewXmlParser() Parser

type PortDirection

type PortDirection int
const (
	PortDirection_INPUT PortDirection = iota
	PortDirection_OUTPUT
	PortDirection_INOUT
)

func (*PortDirection) FromString

func (p *PortDirection) FromString(str string) error

func (*PortDirection) String

func (p *PortDirection) String() string

type PortInfo

type PortInfo struct {
	Name string
	// contains filtered or unexported fields
}

func BidirectionalPort

func BidirectionalPort(name string, desc ...string) *PortInfo

func BidirectionalPortWithDefaultValue

func BidirectionalPortWithDefaultValue(name string, defaultValue any, desc ...string) *PortInfo

func GetPorts

func GetPorts(name string) (res *PortInfo, ok bool)

func InputPort

func InputPort(name string, desc ...string) *PortInfo

func InputPortWithDefaultValue

func InputPortWithDefaultValue(name string, defaultValue any, desc ...string) *PortInfo

func NewPortInfo

func NewPortInfo(direction PortDirection, name string, desc ...string) *PortInfo

func OutPort

func OutPort(name string, desc ...string) *PortInfo

func OutputPortWithDefaultValue

func OutputPortWithDefaultValue(name string, defaultValue any, desc ...string) *PortInfo

func (*PortInfo) DefaultValue

func (p *PortInfo) DefaultValue() any

func (*PortInfo) DefaultValueString

func (p *PortInfo) DefaultValueString() string

func (*PortInfo) Description

func (p *PortInfo) Description() string

func (*PortInfo) Direction

func (p *PortInfo) Direction() PortDirection

func (*PortInfo) SetDefaultValue

func (p *PortInfo) SetDefaultValue(value any)

func (*PortInfo) SetDescription

func (p *PortInfo) SetDescription(description string)

type PostCond

type PostCond int
const (
	// order of the enums also tell us the execution order
	PostCond_ON_HALTED PostCond = iota
	PostCond_ON_FAILURE
	PostCond_ON_SUCCESS
	PostCond_ALWAYS
	PostCond_COUNT_
)

func (PostCond) String

func (p PostCond) String() string

type PostTickCallback

type PostTickCallback func(node *TreeNode, status NodeStatus) NodeStatus

type PreCond

type PreCond int
const (
	// order of the enums also tell us the execution order
	PreCond_FAILURE_IF PreCond = iota
	PreCond_SUCCESS_IF
	PreCond_SKIP_IF
	PreCond_WHILE_TRUE
	PreCond_COUNT_
)

func (PreCond) String

func (p PreCond) String() string

type PreTickCallback

type PreTickCallback func(node *TreeNode) NodeStatus

type ProtectedQueue

type ProtectedQueue struct {
	Items list.List
	Mtx   sync.Mutex
}

type ScriptFunction

type ScriptFunction func(args ...interface{}) bool

func ParseScript

func ParseScript(s string) (ScriptFunction, error)

type Signal

type Signal struct {
	// contains filtered or unexported fields
}

func NewSignal

func NewSignal() *Signal

func (*Signal) Notify

func (c *Signal) Notify(args ...any)

func (*Signal) Subscribe

func (c *Signal) Subscribe(fn CallableFunction) CallableFunction

type SimpleActionNode

type SimpleActionNode struct {
	*SyncActionNode
	// contains filtered or unexported fields
}

func (*SimpleActionNode) Tick

func (n *SimpleActionNode) Tick() NodeStatus

type SimpleConditionNode

type SimpleConditionNode struct {
	*ConditionNode
	// contains filtered or unexported fields
}

func (*SimpleConditionNode) Tick

func (s *SimpleConditionNode) Tick() NodeStatus

type SimpleDecoratorNode

type SimpleDecoratorNode struct {
	*DecoratorNode
	// contains filtered or unexported fields
}

func (*SimpleDecoratorNode) Tick

func (n *SimpleDecoratorNode) Tick() NodeStatus

type SortMap

type SortMap[T1 cmp.Ordered, T2 any] struct {
	// contains filtered or unexported fields
}

func NewSortMap

func NewSortMap[T1 cmp.Ordered, T2 any]() *SortMap[T1, T2]

func (*SortMap[T1, T2]) Delete

func (s *SortMap[T1, T2]) Delete(key T1)

func (*SortMap[T1, T2]) Front

func (s *SortMap[T1, T2]) Front() (value T2, ok bool)

func (*SortMap[T1, T2]) Get

func (s *SortMap[T1, T2]) Get(key T1) (value T2, ok bool)

func (*SortMap[T1, T2]) Range

func (s *SortMap[T1, T2]) Range(fn func(key T1, value T2) (stop bool))

func (*SortMap[T1, T2]) Reset

func (s *SortMap[T1, T2]) Reset()

func (*SortMap[T1, T2]) Set

func (s *SortMap[T1, T2]) Set(key T1, value T2)

type StatefulActionNode

type StatefulActionNode struct {
	*ActionNodeBase
	IStatefulActionNode
	// contains filtered or unexported fields
}

func NewStatefulActionNode

func NewStatefulActionNode(name string, config *NodeConfig) *StatefulActionNode

func (*StatefulActionNode) Halt

func (n *StatefulActionNode) Halt()

func (*StatefulActionNode) IsHaltRequested

func (n *StatefulActionNode) IsHaltRequested() bool

func (*StatefulActionNode) Tick

func (n *StatefulActionNode) Tick() NodeStatus

type Subtree

type Subtree struct {
	TreeId       string
	InstanceName string
	Blackboard   *Blackboard
	Nodes        []ITreeNode
	Subtree      *Subtree
}

type SubtreeModel

type SubtreeModel struct {
	// contains filtered or unexported fields
}

type SyncActionNode

type SyncActionNode struct {
	*ActionNodeBase
}

func NewSyncActionNode

func NewSyncActionNode(name string, config *NodeConfig) *SyncActionNode

func (*SyncActionNode) ExecuteTick

func (s *SyncActionNode) ExecuteTick() NodeStatus

type TestNodeConfig

type TestNodeConfig struct {
	Id string
	/// status to return when the action is completed
	ReturnStatus NodeStatus
	/// script to execute when actions is completed
	PostScript string
	//毫秒
	AsyncDelay time.Duration
	PreFunc    func()
	PostFunc   func()
}

func NewTestNodeConfig

func NewTestNodeConfig() *TestNodeConfig

type ThreadedAction

type ThreadedAction struct {
	*ActionNodeBase
	// contains filtered or unexported fields
}

func NewThreadedAction

func NewThreadedAction(name string, config *NodeConfig) *ThreadedAction

func (*ThreadedAction) ExecuteTick

func (n *ThreadedAction) ExecuteTick() NodeStatus

This method spawn a new thread. Do NOT remove the "final" keyword.

func (*ThreadedAction) Halt

func (n *ThreadedAction) Halt()

func (*ThreadedAction) IsHaltRequested

func (n *ThreadedAction) IsHaltRequested() bool

type TickFunctor

type TickFunctor func(node ITreeNode, status ...NodeStatus) NodeStatus

type TickOption

type TickOption int

type Tree

type Tree struct {
	Subtrees []*Subtree
	// contains filtered or unexported fields
}

func NewTree

func NewTree() *Tree

func (*Tree) GetUID

func (t *Tree) GetUID() uint16

func (*Tree) Init

func (t *Tree) Init()

func (*Tree) Root

func (t *Tree) Root() ITreeNode

func (*Tree) Sleep

func (t *Tree) Sleep(timeout time.Duration)

func (*Tree) TickExactlyOnce

func (t *Tree) TickExactlyOnce() NodeStatus

func (*Tree) TickOnce

func (t *Tree) TickOnce() NodeStatus

func (*Tree) TickRoot

func (t *Tree) TickRoot(opt TickOption, sleepTime time.Duration) NodeStatus

func (*Tree) TickWhileRunning

func (t *Tree) TickWhileRunning(sleepTimes ...time.Duration) NodeStatus

type TreeNode

type TreeNode struct {
	// contains filtered or unexported fields
}

func NewTreeNode

func NewTreeNode(name string, cfg *NodeConfig) *TreeNode

func (*TreeNode) Config

func (n *TreeNode) Config() *NodeConfig

func (*TreeNode) EmitWakeUpSignal

func (n *TreeNode) EmitWakeUpSignal()

func (*TreeNode) ExecuteTick

func (n *TreeNode) ExecuteTick() NodeStatus

func (*TreeNode) FullPath

func (n *TreeNode) FullPath() string

func (*TreeNode) GetInput

func (n *TreeNode) GetInput(key string, destination any) (res any, err error)

func (*TreeNode) GetLockedPortContent

func (n *TreeNode) GetLockedPortContent(key string) func() *Entry

func (*TreeNode) GetRawPortValue

func (n *TreeNode) GetRawPortValue(key string) string

func (*TreeNode) Halt

func (n *TreeNode) Halt()

/ The method used to interrupt the execution of a RUNNING node. / Only Async nodes that may return RUNNING should implement it.

func (*TreeNode) HaltNode

func (n *TreeNode) HaltNode()

func (*TreeNode) ModifyPortsRemapping

func (n *TreeNode) ModifyPortsRemapping(newRemapping map[string]string)

func (*TreeNode) Name

func (n *TreeNode) Name() string

func (*TreeNode) PostConditionsScripts

func (n *TreeNode) PostConditionsScripts() []ScriptFunction

func (*TreeNode) PreConditionsScripts

func (n *TreeNode) PreConditionsScripts() []ScriptFunction

func (*TreeNode) RequiresWakeUp

func (n *TreeNode) RequiresWakeUp() bool

func (*TreeNode) ResetStatus

func (n *TreeNode) ResetStatus()

func (*TreeNode) SetOutput

func (n *TreeNode) SetOutput(key string, value any)

func (*TreeNode) SetPostTickFunction

func (n *TreeNode) SetPostTickFunction(callback func(node *TreeNode, status NodeStatus) NodeStatus)

func (*TreeNode) SetPreTickFunction

func (n *TreeNode) SetPreTickFunction(callback func(node *TreeNode) NodeStatus)

func (*TreeNode) SetRegistrationID

func (n *TreeNode) SetRegistrationID(ID string)

func (*TreeNode) SetStatus

func (n *TreeNode) SetStatus(status NodeStatus)

func (*TreeNode) SetWakeUpInstance

func (n *TreeNode) SetWakeUpInstance(instance *WakeUpSignal)

func (*TreeNode) Status

func (n *TreeNode) Status() NodeStatus

func (*TreeNode) Tick

func (n *TreeNode) Tick() NodeStatus

func (*TreeNode) UID

func (n *TreeNode) UID() uint16

type TreeNodeManifest

type TreeNodeManifest struct {
	Type           NodeType
	RegistrationID string
	Ports          map[string]*PortInfo
	Metadata       []map[string]string
}

func NewTreeNodeManifest

func NewTreeNodeManifest(value any) *TreeNodeManifest

type WakeUpSignal

type WakeUpSignal struct {
	// contains filtered or unexported fields
}

func NewWakeUpSignal

func NewWakeUpSignal() *WakeUpSignal

func (*WakeUpSignal) EmitSignal

func (s *WakeUpSignal) EmitSignal()

func (*WakeUpSignal) WaitFor

func (s *WakeUpSignal) WaitFor(usec time.Duration) bool

type XmlTag

type XmlTag struct {
	Children []*XmlTag
	// contains filtered or unexported fields
}

func (*XmlTag) GetAttr

func (p *XmlTag) GetAttr(key string) string

func (*XmlTag) GetAttrs

func (p *XmlTag) GetAttrs() (res []xml.Attr)

func (*XmlTag) IsTag

func (p *XmlTag) IsTag(key string) bool

func (*XmlTag) TagName

func (p *XmlTag) TagName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL