-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* moved object detection into own folder
* added installation instructions to README.md * make BounceBot class to provide an interface to control the Picar and the turret
- Loading branch information
1 parent
c5209ce
commit 36339fb
Showing
10 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |