0
$\begingroup$

Rosanswers logo

Hello, Recently, I have been working on the Torxis motors which are used in my robotic arm. I am sending six different joint values to six motors from RViz and I was able to move the robotic arm. The problem arises when I am fetching the joint values from the motor feedback. The feedback we receive is a 16-bit integer data that is stored in a variable with datatype "word". Now, I am trying to convert this "word" datatype into Float64 and was trying to publish it onto a ROS topic where there is a lot variation in the data that I am seeing on the topic. Actually, I was expecting a single value as I was giving stable joint values without any change but I ended up receiving a range of values varying at very a high rate on the topic. The feedback function is given below. I need to convert the variable data to a Float64 data.

word feedBack(byte address)  
{  
  word data = 0;   
  byte low, high;  
  Serial2.write(header);  
  Serial2.write(address);  
  Serial2.write(feed1);  
  while(!Serial2.available()){}  
  low = Serial2.read();  
  high = Serial2.read();   
  //Serial.println(data);  
  //low = 0; high = 1;  
  data = high;  
  data = data << 8 | low;  
  data = 4095-data;  
  return data;  
}

Originally posted by Apuroop on ROS Answers with karma: 3 on 2018-05-28

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

There seem to be two different questions here; why the joint angles are varying so much when the should be stable and how to convert a word (unsigned 16 bit integer) to a double precision float on an Arduino.

I can't help you with the first question without some more information, such as what device you're reading the serial data from to get the joint position.

Regarding converting the integer value to a 64 bit float, this is either very easy or impossible depending on the type of arduino you're using. The problem is that the standard arduino boards simply don't support 64 bit float values at all, some of them however do support it such as the Arduino Due and the Teensy 3.x family.

If you use a board which supports 64 bit floats then you can simply assign the word value to the float:

double my64BitFloat = wordValue;

If you have to use a board which doesn't support 64 bit floats then I can't see a solution to this. However the rosserial documentation states that it will automatically convert 32 bit floats to 64 bit floats when serializating messages with a loss of precision. But since you're converting from a 16 bit integer this loss of precision will not effect you at all.

So in short you can actually use a float (32 bit floating point) and assign that value to the message without any problems. Hope this helps.


Originally posted by PeteBlackerThe3rd with karma: 9529 on 2018-05-29

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.