Skip to content

Commit

Permalink
* moved object detection into own folder
Browse files Browse the repository at this point in the history
 * added installation instructions to README.md
 * make BounceBot class to provide an interface to control the Picar and the turret
  • Loading branch information
JuliusHendrix committed Apr 21, 2022
1 parent c5209ce commit 36339fb
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 0 deletions.
Empty file added ObjectDetection/__init__.py
Empty file.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# RoboticsObjectDetection

Simple OpenCV Baseline: https://www.youtube.com/watch?v=HXDD7-EnGBY&ab_channel=Murtaza%27sWorkshop-RoboticsandAI

# Robot Control
The packages used to control the robot can be found on the documentation page:

https://docs.sunfounder.com/projects/picar-x/en/latest/python/python_start/download_and_run_code.html
Empty file added RobotControl/__init__.py
Empty file.
98 changes: 98 additions & 0 deletions RobotControl/bouncebot_control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
from robot_hat import Pin, PWM, Servo
from picarx import Picarx
import time


class BounceBot(Picarx):
"""
Controller for the BounceBot.
"""
def __init__(self):
super().__init__()
# initialize servo control
self.turret_servo = Servo(PWM('P3'))
self.turret_servo.angle(0)

# initialize solenoid control
self.turret_solenoid_1 = Pin("D0")
self.turret_solenoid_2 = Pin("D1")

def activate_solenoid(self, t):
"""
Activate the solenoid for a certain amount of time t.
:param t: time in seconds
:return:
"""
self.turret_solenoid_1.value(1)
self.turret_solenoid_2.value(1)
time.sleep(t)
self.turret_solenoid_1.value(0)
self.turret_solenoid_2.value(0)

def right_turn(self):
pass

def left_turn(self):
pass

def u_turn(self):
pass


def test_controls():
"""
Test the controls.
:return:
"""
bb = BounceBot()

try: # use try/finally to ensure the motors and solenoid are turned off
# drive and steer
bb.forward(30)
time.sleep(0.5)
for angle in range(0, 35):
bb.set_dir_servo_angle(angle)
time.sleep(0.01)
for angle in range(35, -35, -1):
bb.set_dir_servo_angle(angle)
time.sleep(0.01)
for angle in range(-35, 0):
bb.set_dir_servo_angle(angle)
time.sleep(0.01)
bb.forward(0)
time.sleep(1)

# look with camera
for angle in range(0, 35):
bb.set_camera_servo1_angle(angle)
time.sleep(0.01)
for angle in range(35, -35, -1):
bb.set_camera_servo1_angle(angle)
time.sleep(0.01)
for angle in range(-35, 0):
bb.set_camera_servo1_angle(angle)
time.sleep(0.01)
for angle in range(0, 35):
bb.set_camera_servo2_angle(angle)
time.sleep(0.01)
for angle in range(35, -35, -1):
bb.set_camera_servo2_angle(angle)
time.sleep(0.01)
for angle in range(-35, 0):
bb.set_camera_servo2_angle(angle)
time.sleep(0.01)

# test turret
for a in (0, 70, 0, -70):
bb.turret_servo.angle(a)
time.sleep(0.5)
bb.activate_solenoid(0.2)
time.sleep(0.5)

finally:
bb.activate_solenoid(0.1)
bb.forward(0)


if __name__ == "__main__":
test_controls()
18 changes: 18 additions & 0 deletions RobotControl/turret_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from robot_hat import Pin, PWM, Servo
from picarx import Picarx
import time

px = Picarx()
servo_pin = PWM('P3')
sol_pin_a = Pin("D0")
sol_pin_b = Pin("D1") # one pin does not supply enough current, always use both

for a in (0, 70, 0, -70):
Servo(servo_pin).angle(a)
time.sleep(0.3)
sol_pin_a.value(1)
sol_pin_b.value(1)
time.sleep(0.2)
sol_pin_a.value(0)
sol_pin_b.value(0)
time.sleep(0.5)

0 comments on commit 36339fb

Please sign in to comment.