Skip to content

Commit df64388

Browse files
committed
Added sinwave strategy for wet test
Should range from [-4, 4] in x and travel forward 16pi meters. That should be plenty to see if its working
1 parent 4198990 commit df64388

File tree

4 files changed

+84
-5
lines changed

4 files changed

+84
-5
lines changed

TESTING.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
class Visualizer(object):
2+
def __init__(self):
3+
import cv2
4+
self.cv2 = cv2
5+
from numpy import zeros
6+
7+
self.counter = 0
8+
self.position_graph = zeros((800, 800, 3), dtype = 'uint8')
9+
10+
def position(self, x, y, z, every = 100):
11+
if self.counter%every is 0:
12+
blue = 255 + 50*z# color represents depth
13+
self.cv2.circle(self.position_graph, (int(10*x) + 400, 800 - int(10*y)), 5, (blue, 255, 0), -1)
14+
self.cv2.imshow('position', self.position_graph)
15+
self.cv2.waitKey(1)
16+
17+
self.counter += 1
18+
19+
def main(simulating = False):
20+
if simulating:
21+
from main_module.gyro.simulation import Simulated as Gyro
22+
from main_module.odometer.simulation import Simulated as Odometer
23+
from main_module.propulsion.simulation import Simulated as Propulsion
24+
from main_module.planning.s2018 import coach
25+
26+
gyro = Gyro(30.0)
27+
odometer = Odometer(30.0)
28+
propulsion = Propulsion(gyro, 30.0)
29+
30+
strategy = coach.list_of_strategies()[2]
31+
strategy = coach.initialize(strategy, gyro, odometer)
32+
33+
visualizer = Visualizer()
34+
35+
while True:
36+
try:
37+
strategy.run(propulsion, [])
38+
# print(odometer.position.xyz)
39+
visualizer.position(odometer.position.x, odometer.position.y, odometer.position.z)
40+
except KeyboardInterrupt:
41+
break
42+
43+
else:
44+
from main_module.gyro.ros_gyro import ROS_Gyro as Gyro
45+
from main_module.odometer.ros_odometer import ROS_Odometer as Odometer
46+
from main_module.propulsion.robot2018 import Robot2018 as Propulsion
47+
48+
49+
if __name__ == '__main__':
50+
main(simulating = True)

main_module/paths/curve.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def independent_variable(self):
2626
2727
usage example:
2828
my_func = lambda t: [t, t**2, t**3]
29-
my_curve = P_Curve(my_func, 0.0, 3.0)
29+
my_curve = Curve(my_func, 0.0, 3.0)
3030
3131
while my_curve.increment(0.5):
3232
print(my_curve.target)

main_module/planning/s2018/coach.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from ..strategy import Strategy as AbstractStrategy
2-
from .test import TestA, TestB
2+
from .test import TestA, TestB, SinWave
33

44
def list_of_strategies(also_return_names = False):
5-
if also_return_names: return ((TestA, TestA.name), (TestB, TestB.name))
6-
else: return (TestA, TestB)
5+
if also_return_names: return ((TestA, TestA.name), (TestB, TestB.name), (SinWave, SinWave.name))
6+
else: return (TestA, TestB, SinWave)
77

88
def initialize(Strategy, gyro, odometer):# TODO use this issubclass pattern everywhere
99
if issubclass(Strategy, AbstractStrategy): return Strategy(gyro, odometer)

main_module/planning/s2018/test.py

+30-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
sys.path.append('..')
33

44
from main_module.paths.cubic_spline import CubicSpline
5-
from main_module.planning.strategy import *
5+
from ..strategy import *
66
class TestA(Strategy):
77

88
name = 'Skewed Figure-Eight'
@@ -87,3 +87,32 @@ def _say_goodbye(propulsion, subsystems, call_count):
8787
print('Running Event:')
8888
print('Goodbye!')
8989
print('')
90+
91+
from math import sin
92+
from main_module.paths.curve import Curve
93+
class SinWave(Strategy):
94+
95+
name = 'sin wave'
96+
97+
def __init__(self, gyro, odometer):
98+
import sys
99+
version = sys.version_info[0]
100+
if version == 2: super(SinWave, self).__init__(gyro, odometer)# Python 2
101+
else: super().__init__(gyro, odometer)# Python 3
102+
del sys
103+
"""
104+
use this space to set instance variables that
105+
get_leash or get_events may depend on
106+
107+
also use this space to set odometer origin
108+
"""
109+
# now ready to init
110+
self.init()
111+
112+
def _get_leash(self):
113+
my_lambda = lambda t: [4.0*sin(t), 2.0*t, -3]
114+
path0 = Curve(my_lambda, 0.0, 8*3.1415)
115+
return Leash([path0], 0.75, 0.01)
116+
117+
def _get_events(self):
118+
return Events([], [])

0 commit comments

Comments
 (0)