PageRenderTime 58ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/src/man/sensors/SensorsModule.cpp

https://github.com/wdawson/nbites
C++ | 510 lines | 410 code | 60 blank | 40 comment | 11 complexity | 2b544e27d13828e4ae1faeb4a7bf6595 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0
  1. #include "SensorsModule.h"
  2. #include "Common.h"
  3. #include <stdio.h>
  4. namespace man {
  5. namespace sensors {
  6. SensorsModule::SensorsModule(boost::shared_ptr<AL::ALBroker> broker)
  7. : portals::Module(),
  8. jointsOutput_(base()),
  9. currentsOutput_(base()),
  10. temperatureOutput_(base()),
  11. chestboardButtonOutput_(base()),
  12. footbumperOutput_(base()),
  13. inertialsOutput_(base()),
  14. sonarsOutput_(base()),
  15. fsrOutput_(base()),
  16. batteryOutput_(base()),
  17. stiffStatusOutput_(base()),
  18. broker_(broker),
  19. fastMemoryAccess_(new AL::ALMemoryFastAccess()),
  20. sensorValues_(NUM_SENSOR_VALUES),
  21. sensorKeys_(NUM_SENSOR_VALUES)
  22. {
  23. // Initialize the Aldebaran fast access memory interface
  24. // to quickly read sensor values from memory.
  25. initializeSensorFastAccess();
  26. initializeSonarValues();
  27. }
  28. SensorsModule::~SensorsModule()
  29. {
  30. }
  31. void SensorsModule::initializeSensorFastAccess()
  32. {
  33. int i = 0;
  34. // Joint Angles
  35. for(; i < END_JOINTS; ++i)
  36. {
  37. sensorKeys_[i] = std::string("Device/SubDeviceList/") +
  38. SensorNames[i] + std::string("/Position/Sensor/Value");
  39. }
  40. i++;
  41. // Joint Currents
  42. for(; i < END_CURRENTS; ++i)
  43. {
  44. // Subtract 27 from index in SensorsNames[] to get correct value.
  45. sensorKeys_[i] = std::string("Device/SubDeviceList/") +
  46. SensorNames[i-27] + std::string("/ElectricCurrent/Sensor/Value");
  47. }
  48. i++;
  49. // Temperatures
  50. for(; i < END_TEMPERATURES; ++i)
  51. {
  52. // Subtract 2*27 from index in SensorsNames[] to get correct value.
  53. sensorKeys_[i] = std::string("Device/SubDeviceList/") +
  54. SensorNames[i-2*27] + std::string("/Temperature/Sensor/Value");
  55. }
  56. i++;
  57. // FSR (Left foot)
  58. for(; i < END_FSRS_LEFT; ++i)
  59. {
  60. sensorKeys_[i] = std::string("Device/SubDeviceList/LFoot/FSR/") +
  61. SensorNames[i] + std::string("/Sensor/Value");
  62. }
  63. i++;
  64. // FSR (Right foot)
  65. for(; i < END_FSRS_RIGHT; ++i)
  66. {
  67. sensorKeys_[i] = std::string("Device/SubDeviceList/RFoot/FSR/") +
  68. SensorNames[i] + std::string("/Sensor/Value");
  69. }
  70. i++;
  71. // Inertial Sensors
  72. for(; i < END_INTERTIALS; ++i)
  73. {
  74. sensorKeys_[i] = std::string("Device/SubDeviceList/InertialSensor/") +
  75. SensorNames[i] + std::string("/Sensor/Value");
  76. }
  77. i++;
  78. // There are 2 battery values.
  79. sensorKeys_[i] = std::string("Device/SubDeviceList/Battery/Charge/Sensor/Value");
  80. i++;
  81. /* IMPORTANT for some reason, battery charge cannot be read correctly unless
  82. * battery current is read also, who knows why, bad aldebaran code?
  83. * NOT ACTUALLY OUTPORTALED OR USED AT ALL, current is needed for bug fix */
  84. sensorKeys_[i] = std::string("Device/SubDeviceList/Battery/Current/Sensor/Value");
  85. i++;
  86. // There are 2 important sonars.
  87. sensorKeys_[i] = std::string("Device/SubDeviceList/US/Left/Sensor/Value");
  88. i++;
  89. sensorKeys_[i] = std::string("Device/SubDeviceList/US/Right/Sensor/Value");
  90. i++;
  91. // There are 4 foot bumpers.
  92. sensorKeys_[i] = std::string("Device/SubDeviceList/LFoot/Bumper/Left/Sensor/Value");
  93. i++;
  94. sensorKeys_[i] = std::string("Device/SubDeviceList/LFoot/Bumper/Right/Sensor/Value");
  95. i++;
  96. sensorKeys_[i] = std::string("Device/SubDeviceList/RFoot/Bumper/Left/Sensor/Value");
  97. i++;
  98. sensorKeys_[i] = std::string("Device/SubDeviceList/RFoot/Bumper/Right/Sensor/Value");
  99. i++;
  100. // There is a single chest button.
  101. sensorKeys_[i] = std::string("Device/SubDeviceList/ChestBoard/Button/Sensor/Value");
  102. i++;
  103. // All joints have stiffnesses associated with them.
  104. sensorKeys_[i] = std::string("Device/SubDeviceList/HeadPitch/Hardness/Actuator/Value");
  105. i++;
  106. sensorKeys_[i] = std::string("Device/SubDeviceList/HeadYaw/Hardness/Actuator/Value");
  107. i++;
  108. sensorKeys_[i] = std::string("Device/SubDeviceList/LAnklePitch/Hardness/Actuator/Value");
  109. i++;
  110. sensorKeys_[i] = std::string("Device/SubDeviceList/LAnkleRoll/Hardness/Actuator/Value");
  111. i++;
  112. sensorKeys_[i] = std::string("Device/SubDeviceList/LElbowRoll/Hardness/Actuator/Value");
  113. i++;
  114. sensorKeys_[i] = std::string("Device/SubDeviceList/LElbowYaw/Hardness/Actuator/Value");
  115. i++;
  116. sensorKeys_[i] = std::string("Device/SubDeviceList/LHand/Hardness/Actuator/Value");
  117. i++;
  118. sensorKeys_[i] = std::string("Device/SubDeviceList/LHipPitch/Hardness/Actuator/Value");
  119. i++;
  120. sensorKeys_[i] = std::string("Device/SubDeviceList/LHipRoll/Hardness/Actuator/Value");
  121. i++;
  122. sensorKeys_[i] = std::string("Device/SubDeviceList/LHipYawPitch/Hardness/Actuator/Value");
  123. i++;
  124. sensorKeys_[i] = std::string("Device/SubDeviceList/LKneePitch/Hardness/Actuator/Value");
  125. i++;
  126. sensorKeys_[i] = std::string("Device/SubDeviceList/LShoulderPitch/Hardness/Actuator/Value");
  127. i++;
  128. sensorKeys_[i] = std::string("Device/SubDeviceList/LShoulderRoll/Hardness/Actuator/Value");
  129. i++;
  130. sensorKeys_[i] = std::string("Device/SubDeviceList/LWristYaw/Hardness/Actuator/Value");
  131. i++;
  132. sensorKeys_[i] = std::string("Device/SubDeviceList/RAnklePitch/Hardness/Actuator/Value");
  133. i++;
  134. sensorKeys_[i] = std::string("Device/SubDeviceList/RAnkleRoll/Hardness/Actuator/Value");
  135. i++;
  136. sensorKeys_[i] = std::string("Device/SubDeviceList/RElbowRoll/Hardness/Actuator/Value");
  137. i++;
  138. sensorKeys_[i] = std::string("Device/SubDeviceList/RElbowYaw/Hardness/Actuator/Value");
  139. i++;
  140. sensorKeys_[i] = std::string("Device/SubDeviceList/RHand/Hardness/Actuator/Value");
  141. i++;
  142. sensorKeys_[i] = std::string("Device/SubDeviceList/RHipPitch/Hardness/Actuator/Value");
  143. i++;
  144. sensorKeys_[i] = std::string("Device/SubDeviceList/RHipYawPitch/Hardness/Actuator/Value");
  145. i++;
  146. sensorKeys_[i] = std::string("Device/SubDeviceList/RHipRoll/Hardness/Actuator/Value");
  147. i++;
  148. sensorKeys_[i] = std::string("Device/SubDeviceList/RKneePitch/Hardness/Actuator/Value");
  149. i++;
  150. sensorKeys_[i] = std::string("Device/SubDeviceList/RShoulderPitch/Hardness/Actuator/Value");
  151. i++;
  152. sensorKeys_[i]= std::string("Device/SubDeviceList/RShoulderRoll/Hardness/Actuator/Value");
  153. i++;
  154. sensorKeys_[i] = std::string("Device/SubDeviceList/RWristYaw/Hardness/Actuator/Value");
  155. fastMemoryAccess_->ConnectToVariables(broker_, sensorKeys_);
  156. std::cout << "SensorsModule : Sensor keys initialized." << std::endl;
  157. // for(std::vector<std::string>::iterator iter = sensorKeys_.begin();
  158. // iter != sensorKeys_.end();
  159. // ++iter)
  160. // {
  161. // std::cout << *iter << std::endl;
  162. // }
  163. }
  164. void SensorsModule::initializeSonarValues()
  165. {
  166. // Get a proxy to the DCM.
  167. boost::shared_ptr<AL::DCMProxy> dcmProxy = broker_->getDcmProxy();
  168. if(dcmProxy != 0)
  169. {
  170. try
  171. {
  172. // For DCM::set() see:
  173. // http://www.aldebaran-robotics.com/documentation/naoqi/sensors/dcm-api.html#DCMProxy::set__AL::ALValueCR
  174. AL::ALValue dcmSonarCommand;
  175. dcmSonarCommand.arraySetSize(3);
  176. dcmSonarCommand[0] = std::string("Device/SubDeviceList/US/Actuator/Value"); // Device name.
  177. dcmSonarCommand[1] = std::string("ClearAll"); // Delete all timed commands before adding this one.
  178. dcmSonarCommand[2].arraySetSize(1); // A list of (1) timed-commands.
  179. dcmSonarCommand[2][0].arraySetSize(2);
  180. dcmSonarCommand[2][0][0] = 68.0; // The command itself.
  181. dcmSonarCommand[2][0][1] = dcmProxy->getTime(0); // The DCM time for the command to be applied.
  182. // Send the timed command to the sonars.
  183. dcmProxy->set(dcmSonarCommand);
  184. }
  185. catch(AL::ALError& e)
  186. {
  187. std::cout << "SensorsModule : Failed to initialize sonars, "
  188. << e.toString() << std::endl;
  189. }
  190. }
  191. }
  192. void SensorsModule::updateSensorValues()
  193. {
  194. //std::cout << "SensorsModule : Retrieving sensor values from NAOqi." << std::endl;
  195. // Update stored sensor values.
  196. fastMemoryAccess_->GetValues(sensorValues_);
  197. updateJointsMessage();
  198. updateCurrentsMessage();
  199. updateTemperatureMessage();
  200. updateChestboardButtonMessage();
  201. updateFootbumperMessage();
  202. updateInertialsMessage();
  203. updateSonarsMessage();
  204. updateFSRMessage();
  205. updateBatteryMessage();
  206. updateStiffMessage();
  207. // std::cout << "SensorsModule : Sensor values " << std::endl;
  208. // for(int i = 0; i < NUM_SENSOR_VALUES; ++i)
  209. // {
  210. // std::cout << SensorNames[i] << " = " << sensorValues_[i] << std::endl;
  211. // }
  212. }
  213. void SensorsModule::updateJointsMessage()
  214. {
  215. portals::Message<messages::JointAngles> jointsMessage(0);
  216. jointsMessage.get()->set_head_yaw(sensorValues_[HeadYaw]);
  217. jointsMessage.get()->set_head_pitch(sensorValues_[HeadPitch]);
  218. jointsMessage.get()->set_l_shoulder_pitch(sensorValues_[LShoulderPitch]);
  219. jointsMessage.get()->set_l_shoulder_roll(sensorValues_[LShoulderRoll]);
  220. jointsMessage.get()->set_l_elbow_yaw(sensorValues_[LElbowYaw]);
  221. jointsMessage.get()->set_l_elbow_roll(sensorValues_[LElbowRoll]);
  222. jointsMessage.get()->set_l_wrist_yaw(sensorValues_[LWristYaw]);
  223. jointsMessage.get()->set_l_hand(sensorValues_[LHand]);
  224. jointsMessage.get()->set_r_shoulder_pitch(sensorValues_[RShoulderPitch]);
  225. jointsMessage.get()->set_r_shoulder_roll(sensorValues_[RShoulderRoll]);
  226. jointsMessage.get()->set_r_elbow_yaw(sensorValues_[RElbowYaw]);
  227. jointsMessage.get()->set_r_elbow_roll(sensorValues_[RElbowRoll]);
  228. jointsMessage.get()->set_r_wrist_yaw(sensorValues_[RWristYaw]);
  229. jointsMessage.get()->set_r_hand(sensorValues_[RHand]);
  230. jointsMessage.get()->set_l_hip_yaw_pitch(sensorValues_[LHipYawPitch]);
  231. jointsMessage.get()->set_r_hip_yaw_pitch(sensorValues_[RHipYawPitch]);
  232. jointsMessage.get()->set_l_hip_roll(sensorValues_[LHipRoll]);
  233. jointsMessage.get()->set_l_hip_pitch(sensorValues_[LHipPitch]);
  234. jointsMessage.get()->set_l_knee_pitch(sensorValues_[LKneePitch]);
  235. jointsMessage.get()->set_l_ankle_pitch(sensorValues_[LAnklePitch]);
  236. jointsMessage.get()->set_l_ankle_roll(sensorValues_[LAnkleRoll]);
  237. jointsMessage.get()->set_r_hip_roll(sensorValues_[RHipRoll]);
  238. jointsMessage.get()->set_r_hip_pitch(sensorValues_[RHipPitch]);
  239. jointsMessage.get()->set_r_knee_pitch(sensorValues_[RKneePitch]);
  240. jointsMessage.get()->set_r_ankle_pitch(sensorValues_[RAnklePitch]);
  241. jointsMessage.get()->set_r_ankle_roll(sensorValues_[RAnkleRoll]);
  242. jointsOutput_.setMessage(jointsMessage);
  243. }
  244. void SensorsModule::updateCurrentsMessage()
  245. {
  246. portals::Message<messages::JointAngles> jointsMessage(0);
  247. jointsMessage.get()->set_head_yaw(sensorValues_[HeadYawCurrent]);
  248. jointsMessage.get()->set_head_pitch(sensorValues_[HeadPitchCurrent]);
  249. jointsMessage.get()->set_l_shoulder_pitch(sensorValues_[LShoulderPitchCurrent]);
  250. jointsMessage.get()->set_l_shoulder_roll(sensorValues_[LShoulderRollCurrent]);
  251. jointsMessage.get()->set_l_elbow_yaw(sensorValues_[LElbowYawCurrent]);
  252. jointsMessage.get()->set_l_elbow_roll(sensorValues_[LElbowRollCurrent]);
  253. jointsMessage.get()->set_l_wrist_yaw(sensorValues_[LWristYawCurrent]);
  254. jointsMessage.get()->set_l_hand(sensorValues_[LHandCurrent]);
  255. jointsMessage.get()->set_r_shoulder_pitch(sensorValues_[RShoulderPitchCurrent]);
  256. jointsMessage.get()->set_r_shoulder_roll(sensorValues_[RShoulderRollCurrent]);
  257. jointsMessage.get()->set_r_elbow_yaw(sensorValues_[RElbowYawCurrent]);
  258. jointsMessage.get()->set_r_elbow_roll(sensorValues_[RElbowRollCurrent]);
  259. jointsMessage.get()->set_r_wrist_yaw(sensorValues_[RWristYawCurrent]);
  260. jointsMessage.get()->set_r_hand(sensorValues_[RHandCurrent]);
  261. jointsMessage.get()->set_l_hip_yaw_pitch(sensorValues_[LHipYawPitchCurrent]);
  262. jointsMessage.get()->set_r_hip_yaw_pitch(sensorValues_[RHipYawPitchCurrent]);
  263. jointsMessage.get()->set_l_hip_roll(sensorValues_[LHipRollCurrent]);
  264. jointsMessage.get()->set_l_hip_pitch(sensorValues_[LHipPitchCurrent]);
  265. jointsMessage.get()->set_l_knee_pitch(sensorValues_[LKneePitchCurrent]);
  266. jointsMessage.get()->set_l_ankle_pitch(sensorValues_[LAnklePitchCurrent]);
  267. jointsMessage.get()->set_l_ankle_roll(sensorValues_[LAnkleRollCurrent]);
  268. jointsMessage.get()->set_r_hip_roll(sensorValues_[RHipRollCurrent]);
  269. jointsMessage.get()->set_r_hip_pitch(sensorValues_[RHipPitchCurrent]);
  270. jointsMessage.get()->set_r_knee_pitch(sensorValues_[RKneePitchCurrent]);
  271. jointsMessage.get()->set_r_ankle_pitch(sensorValues_[RAnklePitchCurrent]);
  272. jointsMessage.get()->set_r_ankle_roll(sensorValues_[RAnkleRollCurrent]);
  273. currentsOutput_.setMessage(jointsMessage);
  274. }
  275. void SensorsModule::updateTemperatureMessage()
  276. {
  277. portals::Message<messages::JointAngles> temperaturesMessage(0);
  278. temperaturesMessage.get()->set_head_yaw(sensorValues_[HeadYawTemp]);
  279. temperaturesMessage.get()->set_head_pitch(sensorValues_[HeadPitchTemp]);
  280. temperaturesMessage.get()->set_l_shoulder_pitch(sensorValues_[LShoulderPitchTemp]);
  281. temperaturesMessage.get()->set_l_shoulder_roll(sensorValues_[LShoulderRollTemp]);
  282. temperaturesMessage.get()->set_l_elbow_yaw(sensorValues_[LElbowYawTemp]);
  283. temperaturesMessage.get()->set_l_elbow_roll(sensorValues_[LElbowRollTemp]);
  284. temperaturesMessage.get()->set_l_wrist_yaw(sensorValues_[LWristYawTemp]);
  285. temperaturesMessage.get()->set_l_hand(sensorValues_[LHandTemp]);
  286. temperaturesMessage.get()->set_r_shoulder_pitch(sensorValues_[RShoulderPitchTemp]);
  287. temperaturesMessage.get()->set_r_shoulder_roll(sensorValues_[RShoulderRollTemp]);
  288. temperaturesMessage.get()->set_r_elbow_yaw(sensorValues_[RElbowYawTemp]);
  289. temperaturesMessage.get()->set_r_elbow_roll(sensorValues_[RElbowRollTemp]);
  290. temperaturesMessage.get()->set_r_wrist_yaw(sensorValues_[RWristYawTemp]);
  291. temperaturesMessage.get()->set_r_hand(sensorValues_[RHandTemp]);
  292. temperaturesMessage.get()->set_l_hip_yaw_pitch(sensorValues_[LHipYawPitchTemp]);
  293. temperaturesMessage.get()->set_r_hip_yaw_pitch(sensorValues_[RHipYawPitchTemp]);
  294. temperaturesMessage.get()->set_l_hip_roll(sensorValues_[LHipRollTemp]);
  295. temperaturesMessage.get()->set_l_hip_pitch(sensorValues_[LHipPitchTemp]);
  296. temperaturesMessage.get()->set_l_knee_pitch(sensorValues_[LKneePitchTemp]);
  297. temperaturesMessage.get()->set_l_ankle_pitch(sensorValues_[LAnklePitchTemp]);
  298. temperaturesMessage.get()->set_l_ankle_roll(sensorValues_[LAnkleRollTemp]);
  299. temperaturesMessage.get()->set_r_hip_roll(sensorValues_[RHipRollTemp]);
  300. temperaturesMessage.get()->set_r_hip_pitch(sensorValues_[RHipPitchTemp]);
  301. temperaturesMessage.get()->set_r_knee_pitch(sensorValues_[RKneePitchTemp]);
  302. temperaturesMessage.get()->set_r_ankle_pitch(sensorValues_[RAnklePitchTemp]);
  303. temperaturesMessage.get()->set_r_ankle_roll(sensorValues_[RAnkleRollTemp]);
  304. temperatureOutput_.setMessage(temperaturesMessage);
  305. }
  306. void SensorsModule::updateChestboardButtonMessage()
  307. {
  308. portals::Message<messages::ButtonState> chestboardMessage(0);
  309. chestboardMessage.get()->set_pressed(
  310. sensorValues_[ChestboardButton] > 0.5f ? true : false
  311. );
  312. chestboardButtonOutput_.setMessage(chestboardMessage);
  313. }
  314. void SensorsModule::updateFootbumperMessage()
  315. {
  316. portals::Message<messages::FootBumperState> footbumperMessage(0);
  317. footbumperMessage.get()->mutable_l_foot_bumper_left() ->set_pressed(
  318. sensorValues_[LFootBumperLeft] > 0.5f ? true : false
  319. );
  320. footbumperMessage.get()->mutable_l_foot_bumper_right()->set_pressed(
  321. sensorValues_[LFootBumperRight] > 0.5f ? true : false
  322. );
  323. footbumperMessage.get()->mutable_r_foot_bumper_left() ->set_pressed(
  324. sensorValues_[RFootBumperLeft] > 0.5f ? true : false
  325. );
  326. footbumperMessage.get()->mutable_r_foot_bumper_right()->set_pressed(
  327. sensorValues_[RFootBumperRight] > 0.5f ? true : false
  328. );
  329. footbumperOutput_.setMessage(footbumperMessage);
  330. }
  331. void SensorsModule::updateInertialsMessage()
  332. {
  333. portals::Message<messages::InertialState> inertialsMessage(0);
  334. inertialsMessage.get()->set_acc_x(sensorValues_[AccX]);
  335. inertialsMessage.get()->set_acc_y(sensorValues_[AccY]);
  336. inertialsMessage.get()->set_acc_z(sensorValues_[AccZ]);
  337. inertialsMessage.get()->set_gyr_x(sensorValues_[GyrX]);
  338. inertialsMessage.get()->set_gyr_y(sensorValues_[GyrY]);
  339. inertialsMessage.get()->set_angle_x(sensorValues_[AngleX]);
  340. inertialsMessage.get()->set_angle_y(sensorValues_[AngleY]);
  341. inertialsOutput_.setMessage(inertialsMessage);
  342. }
  343. void SensorsModule::updateSonarsMessage()
  344. {
  345. portals::Message<messages::SonarState> sonarsMessage(0);
  346. sonarsMessage.get()->set_us_left(sensorValues_[USLeft]);
  347. sonarsMessage.get()->set_us_right(sensorValues_[USRight]);
  348. sonarsOutput_.setMessage(sonarsMessage);
  349. }
  350. void SensorsModule::updateFSRMessage()
  351. {
  352. portals::Message<messages::FSR> fsrMessage(0);
  353. // Left foot FSR values.
  354. fsrMessage.get()->set_lfl(sensorValues_[LFsrFL]);
  355. fsrMessage.get()->set_lfr(sensorValues_[LFsrFR]);
  356. fsrMessage.get()->set_lrl(sensorValues_[LFsrRL]);
  357. fsrMessage.get()->set_lrr(sensorValues_[LFsrRR]);
  358. // Right foot FSR values.
  359. fsrMessage.get()->set_rfl(sensorValues_[RFsrFL]);
  360. fsrMessage.get()->set_rfr(sensorValues_[RFsrFR]);
  361. fsrMessage.get()->set_rrl(sensorValues_[RFsrRL]);
  362. fsrMessage.get()->set_rrr(sensorValues_[RFsrRR]);
  363. fsrOutput_.setMessage(fsrMessage);
  364. }
  365. void SensorsModule::updateBatteryMessage()
  366. {
  367. portals::Message<messages::BatteryState> batteryMessage(0);
  368. batteryMessage.get()->set_charge(sensorValues_[BatteryCharge]);
  369. batteryOutput_.setMessage(batteryMessage);
  370. }
  371. void SensorsModule::updateStiffMessage()
  372. {
  373. portals::Message<messages::StiffStatus> stiffMessage(0);
  374. if (sensorValues_[HeadPitchStiff] > 0 ||
  375. sensorValues_[HeadYawStiff] > 0 ||
  376. sensorValues_[LAnklePitchStiff] > 0 ||
  377. sensorValues_[LAnkleRollStiff] > 0 ||
  378. sensorValues_[LElbowRollStiff] > 0 ||
  379. sensorValues_[LElbowYawStiff] > 0 ||
  380. sensorValues_[LHandStiff] > 0 ||
  381. sensorValues_[LHipPitchStiff] > 0 ||
  382. sensorValues_[LHipRollStiff] > 0 ||
  383. sensorValues_[LHipYawPitchStiff] > 0 ||
  384. sensorValues_[LKneePitchStiff] > 0 ||
  385. sensorValues_[LShoulderPitchStiff] > 0 ||
  386. sensorValues_[LShoulderRollStiff] > 0 ||
  387. sensorValues_[LWristYawStiff] > 0 ||
  388. sensorValues_[RAnklePitchStiff] > 0 ||
  389. sensorValues_[RAnkleRollStiff] > 0 ||
  390. sensorValues_[RElbowRollStiff] > 0 ||
  391. sensorValues_[RElbowYawStiff] > 0 ||
  392. sensorValues_[RHandStiff] > 0 ||
  393. sensorValues_[RHipPitchStiff] > 0 ||
  394. sensorValues_[RHipYawPitchStiff] > 0 ||
  395. sensorValues_[RHipRollStiff] > 0 ||
  396. sensorValues_[RKneePitchStiff] > 0 ||
  397. sensorValues_[RShoulderPitchStiff] > 0 ||
  398. sensorValues_[RShoulderRollStiff] > 0 ||
  399. sensorValues_[RWristYawStiff] > 0)
  400. {
  401. stiffMessage.get()->set_on(1);
  402. }
  403. else
  404. {
  405. stiffMessage.get()->set_on(0);
  406. }
  407. stiffStatusOutput_.setMessage(stiffMessage);
  408. }
  409. // Helper method so that we can print out a Sweet Moves joint angle
  410. // tuple directly when we want to (ie 5 button presses)
  411. std::string makeSweetMoveTuple(const messages::JointAngles* angles)
  412. {
  413. char output[240];
  414. sprintf(output, "((%3.1f, %3.1f, %3.1f, %3.1f),\n(%3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f),\n(%3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f),\n(%3.1f, %3.1f, %3.1f, %3.1f))\n",
  415. TO_DEG*angles->l_shoulder_pitch(),
  416. TO_DEG*angles->l_shoulder_roll(),
  417. TO_DEG*angles->l_elbow_yaw(),
  418. TO_DEG*angles->l_elbow_roll(),
  419. TO_DEG*angles->l_hip_yaw_pitch(),
  420. TO_DEG*angles->l_hip_roll(),
  421. TO_DEG*angles->l_hip_pitch(),
  422. TO_DEG*angles->l_knee_pitch(),
  423. TO_DEG*angles->l_ankle_pitch(),
  424. TO_DEG*angles->l_ankle_roll(),
  425. TO_DEG*angles->r_hip_yaw_pitch(),
  426. TO_DEG*angles->r_hip_roll(),
  427. TO_DEG*angles->r_hip_pitch(),
  428. TO_DEG*angles->r_knee_pitch(),
  429. TO_DEG*angles->r_ankle_pitch(),
  430. TO_DEG*angles->r_ankle_roll(),
  431. TO_DEG*angles->r_shoulder_pitch(),
  432. TO_DEG*angles->r_shoulder_roll(),
  433. TO_DEG*angles->r_elbow_yaw(),
  434. TO_DEG*angles->r_elbow_roll());
  435. return std::string(output);
  436. }
  437. void SensorsModule::run_()
  438. {
  439. printInput.latch();
  440. // Simply update all sensor readings from ALMemory.
  441. updateSensorValues();
  442. if(printInput.message().toggle() != lastPrint)
  443. {
  444. std::cout << makeSweetMoveTuple(jointsOutput_.getMessage(true).get())
  445. << std::endl;
  446. lastPrint = !lastPrint;
  447. }
  448. }
  449. } // namespace sensors
  450. } // namespace man