SHARE
TWEET

Untitled

a guest Nov 21st, 2019 105 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MidTerm Exercise
  2.  
  3. Python Programming with GoPiGo
  4.  
  5.  Your program will make your robot dance"  – random actions.
  6. Ask the user to decide what movements the robot should make next.  The following letters perform specific actions – allow them to use all actions.  You need to be sure to ask them again if they use the wrong letter.
  7. w = forward
  8.  
  9. a = turn left
  10.  
  11. d  = turn right
  12.  
  13. s = move back
  14.  
  15. x = stop
  16.  
  17. t= increase speed
  18.  
  19. g = decrease speed
  20.  
  21. z = exit using sys module
  22.  
  23. Allow the user to turn on the LED’s
  24. Use the following modules or others, if you choose.
  25.  
  26. #!/usr/bin/env python3
  27.  
  28. from gopigo import *
  29.  
  30. import sys
  31.  
  32. import time
  33.  
  34. import random
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. Requirements = 60 pts
  43.  
  44. Minimum of three functions – main needs to be one of them.
  45.  
  46. Use of if/elif/else
  47.  
  48. Correct use of loops/where necessary
  49.  
  50. Comment sections of code
  51.  
  52. DocString
  53.  
  54. Correct use of syntax/no errors
  55.  
  56.  
  57.  
  58. Motor control functions:
  59. fwd(): Move the GoPiGo forward with PID (better control)
  60. motor_fwd(): Move the GoPiGo forward without PID
  61. bwd(): Move the GoPiGo back with PID (better control)
  62. motor_bwd(): Move the GoPiGo back without PID
  63. left(): Turn GoPiGo Left slow (one motor off, better control)
  64. left_rot(): Rotate GoPiGo left in same position (both motors moving in the opposite direction)
  65. right(): Turn GoPiGo right slow (one motor off, better control)
  66. right_rot(): Rotate GoPiGo right in same position both motors moving in the opposite direction)
  67. stop(): Stop the GoPiGo
  68. Motor speed Functions:
  69.  
  70. increase_speed(): Increase the speed of the GoPiGo by 10
  71. decrease_speed(): Decrease the speed of the GoPiGo by 10
  72. set_left_speed(): Set speed of the left motor
  73. set_right_speed(): Set speed of the right motor
  74. set_speed(): Set speeds of both the motors
  75. Encoder Functions:
  76.  
  77. enc_tgt(): Set encoder target to move the GoPiGo to a set distance
  78. enable_encoders(): Enable the encoders
  79. disable_encoders(): Disable the encoders
  80. Ultrasonic ranger read:
  81.  
  82. us_dist(): Read distance from the ultrasonic sensor
  83. LED control:
  84.  
  85. led_on(): Turn LED on
  86. led_off(): Turn LED off
  87. Servo control:
  88.  
  89. enable_servo(): Enables the servo
  90. disable_servo(): Disables the servo
  91. servo(): Set servo position
  92. Status from the GoPiGo:
  93.  
  94. volt(): Read battery voltage in V
  95. fw_ver(): Get the firmware version of the GoPiGo
  96. enable_com_timeout(): Enable communication time-out(stop the motors if no command received in the specified time-out)
  97. disable_com_timeout(): Disable communication time-out
  98. read_status(): Read the status register on the GoPiGo
  99. read_enc_status(): Read encoder status
  100. read_timeout_status(): Read timeout status
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top