@@ -16,22 +16,23 @@ using namespace viam::sdk;
1616
1717std::string find_motor (ResourceConfig cfg, std::string motor_name) {
1818 auto base_name = cfg.name ();
19- auto motor = cfg.attributes ()-> find (motor_name);
20- if (motor == cfg.attributes ()-> end ()) {
19+ auto motor = cfg.attributes (). find (motor_name);
20+ if (motor == cfg.attributes (). end ()) {
2121 std::ostringstream buffer;
2222 buffer << base_name << " : Required parameter `" << motor_name
2323 << " ` not found in configuration" ;
2424 throw std::invalid_argument (buffer.str ());
2525 }
26- const auto * const motor_string = motor->second ->get <std::string>();
27- if (!motor_string || motor_string->empty ()) {
28- std::ostringstream buffer;
29- buffer << base_name << " : Required non-empty string parameter `" << motor_name
30- << " ` is either not a string "
31- " or is an empty string" ;
32- throw std::invalid_argument (buffer.str ());
26+ const ProtoValue& motor_val = motor->second ;
27+ if (motor_val.is_a <std::string>() && !motor_val.get_unchecked <std::string>().empty ()) {
28+ return motor_val.get_unchecked <std::string>();
3329 }
34- return *motor_string;
30+
31+ std::ostringstream buffer;
32+ buffer << base_name << " : Required non-empty string parameter `" << motor_name
33+ << " ` is either not a string "
34+ " or is an empty string" ;
35+ throw std::invalid_argument (buffer.str ());
3536}
3637
3738void MyBase::reconfigure (const Dependencies& deps, const ResourceConfig& cfg) {
@@ -64,7 +65,7 @@ bool MyBase::is_moving() {
6465 return left_->is_moving () || right_->is_moving ();
6566}
6667
67- void MyBase::stop (const AttributeMap & extra) {
68+ void MyBase::stop (const ProtoStruct & extra) {
6869 std::string err_message;
6970 bool throw_err = false ;
7071
@@ -89,7 +90,7 @@ void MyBase::stop(const AttributeMap& extra) {
8990 }
9091}
9192
92- void MyBase::set_power (const Vector3& linear, const Vector3& angular, const AttributeMap & extra) {
93+ void MyBase::set_power (const Vector3& linear, const Vector3& angular, const ProtoStruct & extra) {
9394 // Stop the base if absolute value of linear and angular velocity is less
9495 // than 0.01.
9596 if (abs (linear.y ()) < 0.01 && abs (angular.z ()) < 0.01 ) {
@@ -104,20 +105,20 @@ void MyBase::set_power(const Vector3& linear, const Vector3& angular, const Attr
104105 right_->set_power (((linear.y () + angular.z ()) / sum), extra);
105106}
106107
107- AttributeMap MyBase::do_command (const AttributeMap & command) {
108+ ProtoStruct MyBase::do_command (const ProtoStruct & command) {
108109 std::cout << " Received DoCommand request for MyBase " << Resource::name () << std::endl;
109110 return command;
110111}
111112
112- std::vector<GeometryConfig> MyBase::get_geometries (const AttributeMap & extra) {
113+ std::vector<GeometryConfig> MyBase::get_geometries (const ProtoStruct & extra) {
113114 auto left_geometries = left_->get_geometries (extra);
114115 auto right_geometries = right_->get_geometries (extra);
115116 std::vector<GeometryConfig> geometries (left_geometries);
116117 geometries.insert (geometries.end (), right_geometries.begin (), right_geometries.end ());
117118 return geometries;
118119}
119120
120- Base::properties MyBase::get_properties (const AttributeMap & extra) {
121+ Base::properties MyBase::get_properties (const ProtoStruct & extra) {
121122 // Return fake properties.
122123 return {2 , 4 , 8 };
123124}
0 commit comments