rover.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. '''
  2. This is an example builder script that sets up a rover in Morse to
  3. be driven by ArduPilot.
  4. The rover has the basic set of sensors that ArduPilot needs
  5. To start the simulation use this:
  6. morse run rover.py
  7. Then connect with ArduPilot like this:
  8. sim_vehicle.py --model morse --console --map
  9. This model assumes you will setup a skid-steering rover with left throttle on
  10. channel 1 and right throttle on channel 2, which means you need to set:
  11. SERVO1_FUNCTION 73
  12. SERVO3_FUNCTION 74
  13. '''
  14. from morse.builder import *
  15. # use the ATRV rover
  16. vehicle = ATRV()
  17. vehicle.properties(Object = True, Graspable = False, Label = "Vehicle")
  18. vehicle.translate(x=0.0, z=0.0)
  19. # add a camera
  20. camera = SemanticCamera(name="Camera")
  21. camera.translate(x=0.2, y=0.3, z=0.9)
  22. vehicle.append(camera)
  23. camera.properties(cam_far=800)
  24. camera.properties(Vertical_Flip=True)
  25. # we could optionally stream the video to a port
  26. #camera.add_stream('socket')
  27. # add sensors needed for ArduPilot operation to a vehicle
  28. pose = Pose()
  29. vehicle.append(pose)
  30. imu = IMU()
  31. vehicle.append(imu)
  32. gps = GPS()
  33. gps.alter('UTM')
  34. vehicle.append(gps)
  35. velocity = Velocity()
  36. vehicle.append(velocity)
  37. # create a compound sensor of all of the individual sensors and stream it
  38. all_sensors = CompoundSensor([imu, gps, velocity, pose])
  39. all_sensors.add_stream('socket')
  40. vehicle.append(all_sensors)
  41. # make the vehicle controllable with speed and angular velocity
  42. # this will be available on port 60001 by default
  43. # an example command is:
  44. # {"v":2, "w":1}
  45. # which is 2m/s fwd, and rotating left at 1 radian/second
  46. motion = MotionVW()
  47. vehicle.append(motion)
  48. motion.add_stream('socket')
  49. # this would allow us to control the vehicle with a keyboard
  50. # we don't enable it as it causes issues with sensor consistency
  51. #keyboard = Keyboard()
  52. #keyboard.properties(Speed=3.0)
  53. #vehicle.append(keyboard)
  54. # Environment
  55. env = Environment('land-1/trees')
  56. env.set_camera_location([10.0, -10.0, 10.0])
  57. env.set_camera_rotation([1.0470, 0, 0.7854])
  58. env.select_display_camera(camera)
  59. env.set_camera_clip(clip_end=1000)
  60. # startup at CMAC. A location is needed for the magnetometer
  61. env.properties(longitude = 149.165230, latitude = -35.363261, altitude = 584.0)