@@ -14,8 +14,11 @@ import (
14
14
"go.viam.com/rdk/utils"
15
15
)
16
16
17
- // Config represents all supported fields in a Universal Robot Description Format (URDF) file.
18
- type Config struct {
17
+ // Extension is the file extension associated with URDF files.
18
+ const Extension string = "urdf"
19
+
20
+ // ModelConfig represents all supported fields in a Universal Robot Description Format (URDF) file.
21
+ type ModelConfig struct {
19
22
XMLName xml.Name `xml:"robot"`
20
23
Name string `xml:"name,attr"`
21
24
Links []link `xml:"link"`
@@ -41,9 +44,9 @@ type joint struct {
41
44
Limit * limit `xml:"limit,omitempty"`
42
45
}
43
46
44
- // NewConfigFromWorldState creates a urdf.Config struct which can be marshalled into xml and will be a
47
+ // NewModelFromWorldState creates a urdf.Config struct which can be marshalled into xml and will be a
45
48
// valid .urdf file representing the geometries in the given worldstate.
46
- func NewConfigFromWorldState (ws * referenceframe.WorldState , name string ) (* Config , error ) {
49
+ func NewModelFromWorldState (ws * referenceframe.WorldState , name string ) (* ModelConfig , error ) {
47
50
// the link we initialize this list with represents the world frame
48
51
links := []link {{Name : referenceframe .World }}
49
52
joints := make ([]joint , 0 )
@@ -68,40 +71,24 @@ func NewConfigFromWorldState(ws *referenceframe.WorldState, name string) (*Confi
68
71
Child : frame {g .Label ()},
69
72
})
70
73
}
71
- return & Config {
74
+ return & ModelConfig {
72
75
Name : name ,
73
76
Links : links ,
74
77
Joints : joints ,
75
78
}, nil
76
79
}
77
80
78
- // ParseXMLFile will read a given file and parse the contained URDF XML data into an equivalent Model.
79
- func ParseXMLFile (filename , modelName string ) (referenceframe.Model , error ) {
80
- //nolint:gosec
81
- xmlData , err := os .ReadFile (filename )
82
- if err != nil {
83
- return nil , errors .Wrap (err , "Failed to read URDF file" )
84
- }
85
-
86
- mc , err := ConvertURDFToConfig (xmlData , modelName )
87
- if err != nil {
88
- return nil , err
89
- }
90
-
91
- return mc .ParseConfig (modelName )
92
- }
93
-
94
- // ConvertURDFToConfig will transfer the given URDF XML data into an equivalent ModelConfig. Direct unmarshaling in the
81
+ // UnmarshalModelXML will transfer the given URDF XML data into an equivalent ModelConfig. Direct unmarshaling in the
95
82
// same fashion as ModelJSON is not possible, as URDF data will need to be evaluated to accommodate differences
96
83
// between the two kinematics encoding schemes.
97
- func ConvertURDFToConfig (xmlData []byte , modelName string ) (* referenceframe.ModelConfig , error ) {
84
+ func UnmarshalModelXML (xmlData []byte , modelName string ) (* referenceframe.ModelConfig , error ) {
98
85
// empty data probably means that the read URDF has no actionable information
99
86
if len (xmlData ) == 0 {
100
87
return nil , referenceframe .ErrNoModelInformation
101
88
}
102
89
103
- mc := & referenceframe.ModelConfig {}
104
- urdf := & Config {}
90
+ mc := & referenceframe.ModelConfig {OriginalFile : & referenceframe. ModelFile { Bytes : xmlData , Extension : Extension } }
91
+ urdf := & ModelConfig {}
105
92
err := xml .Unmarshal (xmlData , urdf )
106
93
if err != nil {
107
94
return nil , errors .Wrap (err , "Failed to convert URDF data to equivalent URDFConfig struct" )
@@ -242,3 +229,19 @@ func ConvertURDFToConfig(xmlData []byte, modelName string) (*referenceframe.Mode
242
229
}
243
230
return mc , nil
244
231
}
232
+
233
+ // ParseModelXMLFile will read a given file and parse the contained URDF XML data into an equivalent Model.
234
+ func ParseModelXMLFile (filename , modelName string ) (referenceframe.Model , error ) {
235
+ //nolint:gosec
236
+ xmlData , err := os .ReadFile (filename )
237
+ if err != nil {
238
+ return nil , errors .Wrap (err , "failed to read URDF file" )
239
+ }
240
+
241
+ mc , err := UnmarshalModelXML (xmlData , modelName )
242
+ if err != nil {
243
+ return nil , err
244
+ }
245
+
246
+ return mc .ParseConfig (modelName )
247
+ }
0 commit comments