Skip to content

Commit

Permalink
Merge pull request #21 from Doomse/main
Browse files Browse the repository at this point in the history
Add default values to Ros Message types
  • Loading branch information
Oberacda authored Jan 14, 2025
2 parents f5b6373 + 213380d commit 1a1fd6c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 31 deletions.
12 changes: 1 addition & 11 deletions src/components/param_inputs/RosNameParam.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,7 @@ function onInput(event: Event) {
const target = event.target as HTMLInputElement
let new_name = target.value || ''

let results
if (type_param.value === undefined) {
results = search_fuse.value.search({ name: new_name })
} else {
const type = (type_param.value.value.value as RosType).type_str
if (type === '') {
results = search_fuse.value.search({ name: new_name })
} else {
results = search_fuse.value.search({ name: new_name, type: type })
}
}
const results = search_fuse.value.search({ name: new_name })

search_results.value = results.map((x) => x.item)

Expand Down
38 changes: 18 additions & 20 deletions src/types/python_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const PyDefaultValues = new Map<string, PyObject | PyReduce>()
export const OrderedDict_Name = 'collections.OrderedDict'
PyDefaultValues.set(OrderedDict_Name, {
'py/reduce': [{ 'py/type': OrderedDict_Name }, { 'py/tuple': [[]] }, null, null, null]
} as PyReduce )
} as PyReduce)

export type PyLogger = PyObject & {
logger_level: string
Expand All @@ -44,7 +44,7 @@ export const LoggerLevel_Name = 'ros_bt_py.ros_helpers.LoggerLevel'
PyDefaultValues.set(LoggerLevel_Name, {
'py/object': LoggerLevel_Name,
logger_level: 'Debug'
} as PyLogger )
} as PyLogger)

export type PyOperator = PyObject & {
operator: string
Expand All @@ -53,12 +53,12 @@ export const MathUnaryOperator_Name = 'ros_bt_py.helpers.MathUnaryOperator'
PyDefaultValues.set(MathUnaryOperator_Name, {
'py/object': MathUnaryOperator_Name,
operator: 'sqrt'
} as PyOperator )
} as PyOperator)
export const MathBinaryOperator_Name = 'ros_bt_py.helpers.MathBinaryOperator'
PyDefaultValues.set(MathBinaryOperator_Name, {
'py/object': MathBinaryOperator_Name,
operator: '+'
} as PyOperator )
} as PyOperator)

export type PyOperand = PyObject & {
operand_type: string
Expand All @@ -67,12 +67,12 @@ export const MathOperandType_Name = 'ros_bt_py.helpers.MathOperandType'
PyDefaultValues.set(MathOperandType_Name, {
'py/object': MathOperandType_Name,
operand_type: 'float'
} as PyOperand )
} as PyOperand)
export const MathUnaryOperandType_Name = 'ros_bt_py.helpers.MathUnaryOperandType'
PyDefaultValues.set(MathUnaryOperandType_Name, {
'py/object': MathUnaryOperandType_Name,
operand_type: 'float'
} as PyOperand )
} as PyOperand)

export type PyEnum = PyObject & {
enum_value: string
Expand All @@ -83,7 +83,7 @@ PyDefaultValues.set(EnumValue_Name, {
'py/object': EnumValue_Name,
enum_value: '',
field_names: []
} as PyEnum )
} as PyEnum)

export type PyFilePath = PyObject & {
path: string
Expand All @@ -92,26 +92,26 @@ export const FilePath_Name = 'ros_bt_py.custom_types.FilePath'
PyDefaultValues.set(FilePath_Name, {
'py/object': FilePath_Name,
path: ''
} as PyFilePath )
} as PyFilePath)

export type RosType = PyObject & {
type_str: string
}
export const RosTopicType_Name = 'ros_bt_py.custom_types.RosTopicType'
PyDefaultValues.set(RosTopicType_Name, {
'py/object': RosTopicType_Name,
type_str: ''
} as RosType )
type_str: 'std_msgs/msg/Empty'
} as RosType)
export const RosServiceType_Name = 'ros_bt_py.custom_types.RosServiceType'
PyDefaultValues.set(RosServiceType_Name, {
'py/object': RosServiceType_Name,
type_str: ''
} as RosType )
type_str: 'std_srvs/srv/Empty'
} as RosType)
export const RosActionType_Name = 'ros_bt_py.custom_types.RosActionType'
PyDefaultValues.set(RosActionType_Name, {
'py/object': RosActionType_Name,
type_str: ''
} as RosType )
type_str: 'example_interfaces/action/Fibonacci'
} as RosType)

export type RosName = PyObject & {
name: string
Expand All @@ -120,24 +120,22 @@ export const RosTopicName_Name = 'ros_bt_py.custom_types.RosTopicName'
PyDefaultValues.set(RosTopicName_Name, {
'py/object': RosTopicName_Name,
name: ''
} as RosName )
} as RosName)
export const RosServiceName_Name = 'ros_bt_py.custom_types.RosServiceName'
PyDefaultValues.set(RosServiceName_Name, {
'py/object': RosServiceName_Name,
name: ''
} as RosName )
} as RosName)
export const RosActionName_Name = 'ros_bt_py.custom_types.RosActionName'
PyDefaultValues.set(RosActionName_Name, {
'py/object': RosActionName_Name,
name: ''
} as RosName )
} as RosName)

export function isPythonTypeWithDefault(type: string) {
return PyDefaultValues.has(type)
}

export function getPythonTypeDefault(type: string) {
return structuredClone(
PyDefaultValues.get(type)
)
return structuredClone(PyDefaultValues.get(type))
}

0 comments on commit 1a1fd6c

Please sign in to comment.