JointStateWriterMod.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. © Siemens AG, 2017-2018
  3. Author: Dr. Martin Bischoff (martin.bischoff@siemens.com)
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. <http://www.apache.org/licenses/LICENSE-2.0>.
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. // Modified by Lydia Ebbinghaus.
  15. using RosSharp.Urdf;
  16. using UnityEngine;
  17. using Joint = UnityEngine.Joint;
  18. namespace RosSharp.RosBridgeClient
  19. {
  20. [RequireComponent(typeof(Joint)), RequireComponent(typeof(UrdfJoint))]
  21. public class JointStateWriterMod : MonoBehaviour
  22. {
  23. private UrdfJoint urdfJoint;
  24. private float newState; // rad or m
  25. private float prevState; // rad or m
  26. private bool isNewStateReceived;
  27. private void Start()
  28. {
  29. urdfJoint = GetComponent<UrdfJoint>();
  30. }
  31. private void Update()
  32. {
  33. if (isNewStateReceived)
  34. {
  35. WriteUpdate();
  36. isNewStateReceived = false;
  37. }
  38. }
  39. private void WriteUpdate()
  40. {
  41. urdfJoint.UpdateJointState(newState-prevState);
  42. prevState = newState;
  43. }
  44. // Modified. Incorrect representation. Maybe due to other way of improting urdf or different coordinates. Undo : newState = state. Remove type
  45. public void Write(float state,robotType type)
  46. {
  47. switch (type)
  48. {
  49. case robotType.drz_telemax:
  50. newState = -state;
  51. break;
  52. case robotType.asterix_ugv:
  53. newState = state;
  54. break;
  55. }
  56. isNewStateReceived = true;
  57. }
  58. public void Write(float state)
  59. {
  60. newState = state;
  61. isNewStateReceived = true;
  62. }
  63. }
  64. }