To assign float numbers to double arrays
In the hardware interface of ros_control, I have
double joint_position_[7]
and in the read() function I want to assign values to it which I have got from a ros service call that is defined by type "sensor_msgs/JointState", i.e.,
$ rosmsg show sensor_msgs/JointState
std_msgs/Header header
uint32 seq
time stamp
string frame_id
string[] name
float64[] position
float64[] velocity
float64[] effort
What I tried was:
void ROBOTHardwareInterface::read() {
bool success = client.call(j_state_srv);
joint_position_ = j_state_srv.response.j_state.position
...
}
which by no surprise gives this error:
error: incompatible types in assignment of ‘sensor_msgs::JointState_<std::allocator<void> >::_position_type {aka std::vector<double>}’ to ‘double [7]’
joint_position_ = j_state_srv.response.j_state.position
Is there a good workaround for this?
As @bob-ROS mentioned, is there a reason you need to use a
double[7]
? If you instead used anotherstd::vector<double>
this would be a trivial operation.@jarvisschultz the problem is I am rather new to c++ and don't know what options I have. On the other hand , I'm also new to ros_control to know what's possible. Can you please also note how you would write it? especially how I should declare it in the header file.
Maybe something like this
@jarvisschultz It gave another error. In some other lines I also use them like the below. I'm not sure if ros_control is compatible with it.