How to use generate_control method in autotest

Best Python code snippet using autotest_python

startfinal.py

Source:startfinal.py Github

copy

Full Screen

...13from PIL import Image14from PIL import ImageOps15from final.final_ui import *16from final.test.interactionMatrix.mouseInteractor import MouseInteractor17def generate_control(_nPts: int):18 _xMin, _xMax, _yMin, _yMax = -1.0, 1.0, -1.0, 1.019 _xStep = (_xMax - _xMin) / (_nPts - 1)20 _yStep = (_yMax - _yMin) / (_nPts - 1)21 _control = [[[_yMin + y * _yStep, _xMin + x * _xStep, 0.0] for x in range(_nPts)] for y in range(_nPts)]22 return _control23nPts = 324controlPoints = generate_control(nPts)25def updateControlPoints(z_axis: list):26 """Calculate function values for all 2D grid points."""27 if not z_axis:28 for row in controlPoints:29 for coord in row:30 coord[2] = random.random()31 else:32 i = 033 for row in controlPoints:34 for coord in row:35 coord[2] = z_axis[i]36 i += 137def casteljau_curve(points, t):38 """Use casteljau to compute a point of a Bezier curve given the control39 points and a fixed parametized t"""40 p, n = points, len(points)41 for r in range(1, n):42 for i in range(n - r):43 p[i] = (1 - t) * p[i] + t * p[i + 1]44 return p[0]45def casteljau_surface(points, u, v):46 """Given control points of a surface and fixing u and v, compute an47 interpolated 3d point of the surface"""48 xis = list()49 yis = list()50 zis = list()51 for ps in points:52 xis.append(casteljau_curve([j[0] for j in ps], u))53 yis.append(casteljau_curve([j[1] for j in ps], u))54 zis.append(casteljau_curve([j[2] for j in ps], u))55 return (casteljau_curve(xis, v), casteljau_curve(yis, v),56 casteljau_curve(zis, v))57def show_axis():58 glDisable(GL_LIGHTING)59 glDisable(GL_LIGHT0)60 glBegin(GL_LINES)61 glColor3f(1.0, 0.0, 0.0)62 glVertex3f(-15.0, 0.0, 0.0)63 glVertex3f(15.0, 0.0, 0.0)64 glColor3f(0.0, 1.0, 0.0)65 glVertex3f(0.0, -15.0, 0.0)66 glVertex3f(0.0, 15.0, 0.0)67 glColor3f(0.0, 0.0, 1.0)68 glVertex3f(0.0, 0.0, -15.0)69 glVertex3f(0.0, 0.0, 15.0)70 glEnd()71dis_con = True72dis_gl_light = False73position = [0.0, 0.0, 1.5, 1.0]74def display_control():75 if dis_con:76 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA)77 glPointSize(10)78 glBegin(GL_POINTS)79 glColor3f(0.0, 1.0, 0.0)80 for row in controlPoints:81 for coord in row:82 glVertex3f(float(coord[0]), float(coord[1]), float(coord[2]))83 glEnd()84 glBegin(GL_LINES)85 glColor3f(1.0, 0.0, 0.0)86 for row in controlPoints:87 for i in range(0, nPts - 1):88 glVertex3f(float(row[i][0]), float(row[i][1]), float(row[i][2]))89 glVertex3f(float(row[i + 1][0]), float(row[i + 1][1]), float(row[i + 1][2]))90 glEnd()91 glBegin(GL_LINES)92 glColor3f(1.0, 0.0, 0.0)93 for j in range(0, nPts):94 for i in range(0, nPts - 1):95 glVertex3f(float(controlPoints[i][j][0]), float(controlPoints[i][j][1]), float(controlPoints[i][j][2]))96 glVertex3f(float(controlPoints[i + 1][j][0]), float(controlPoints[i + 1][j][1]),97 float(controlPoints[i + 1][j][2]))98 glEnd()99def display_surface():100 global position101 if dis_gl_light:102 glEnable(GL_LIGHTING)103 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GLU_TRUE)104 glEnable(GL_LIGHT0)105 glPushMatrix()106 glRotated(spin, 1.0, 0.0, 0.0)107 glLightfv(GL_LIGHT0, GL_POSITION, position)108 glDisable(GL_LIGHTING)109 glTranslated(0.0, 0.0, 1.5)110 glColor3f(0.0, 1.0, 1.0)111 glutSolidCube(0.1)112 glEnable(GL_LIGHTING)113 glPopMatrix()114 cp = controlPoints115 xas = list()116 yas = list()117 zas = list()118 interval = 16119 for u in np.linspace(0.0, 1.0, interval):120 for v in np.linspace(0.0, 1.0, interval):121 p = casteljau_surface(cp, u, v)122 xas.append(p[0])123 yas.append(p[1])124 zas.append(p[2])125 # Draw the two aproximated surfaces126 glBegin(GL_LINES)127 glColor3f(1.0, 1.0, 1.0)128 for i in range(0, len(xas)):129 if (i + 1) % interval == 0:130 continue131 try:132 # OpenGL 3d Line133 glVertex3f(float(xas[i]), float(yas[i]), float(zas[i]))134 glVertex3f(float(xas[i + 1]), float(yas[i + 1]), float(zas[i + 1]))135 except IndexError:136 continue137 glEnd()138 for j in range(0, len(xas)):139 glBegin(GL_LINES)140 glColor3f(1.0, 1.0, 1.0)141 for k in range(j, interval * interval, interval):142 try:143 # OpenGL 3d Line144 glVertex3f(float(xas[k]), float(yas[k]), float(zas[k]))145 glVertex3f(float(xas[k + interval]), float(yas[k + interval]), float(zas[k + interval]))146 except IndexError:147 continue148 glEnd()149 glBegin(GL_QUADS)150 for j in range(len(xas)):151 if (j + 1) % interval == 0:152 continue153 try:154 glColor3f(np.linspace(1.0, 0.0, len(xas))[j], np.linspace(0.5, 0.5, len(xas))[j],155 np.linspace(0.0, 1.0, len(xas))[j])156 glVertex3f(xas[j], yas[j], zas[j])157 glVertex3f(xas[j + 1], yas[j + 1], zas[j + 1])158 glVertex3f(xas[j + interval + 1], yas[j + interval + 1], zas[j + interval + 1])159 glVertex3f(xas[j + interval], yas[j + interval], zas[j + interval])160 except IndexError:161 continue162 glEnd()163spin = 0.0164index_i, index_j = 0, 0165def drag_control(i: int, j: int, mouse):166 if mouse.mouseButtonPressed == GLUT_LEFT_BUTTON:167 glPointSize(25)168 glBegin(GL_POINTS)169 glColor3f(1.0, 1.0, 1.0)170 glVertex3f(controlPoints[i][j][0], controlPoints[i][j][1], controlPoints[i][j][2])171 glEnd()172 glPushMatrix()173 controlPoints[i][j][2] += mouse.wheelDirection * 0.1174 mouse.wheelDirection = 0175 glPopMatrix()176 elif mouse.mouseButtonPressed == GLUT_MIDDLE_BUTTON:177 pass178def keyboard(key, x, y):179 global index_i, index_j, spin, dis_gl_light180 if key == b'q':181 spin += 5.0182 if spin == 360.0:183 spin = 0.0184 dis_gl_light = True185 glutPostRedisplay()186 elif key == b'e':187 dis_gl_light = False188 spin = 0.0189 glDisable(GL_LIGHTING)190 glDisable(GL_LIGHT0)191 glutPostRedisplay()192 elif key == b'k':193 if index_i - 1 >= 0:194 index_i -= 1195 else:196 index_i = nPts - 1197 glutPostRedisplay()198 elif key == b'l':199 if index_j + 1 < nPts:200 index_j += 1201 else:202 index_j = 0203 glutPostRedisplay()204def reshape(w, h):205 glViewport(0, 0, w, h)206 glMatrixMode(GL_PROJECTION)207 glLoadIdentity()208 gluPerspective(45, w / h, 0.1, 100.0)209 glMatrixMode(GL_MODELVIEW)210 glLoadIdentity()211def display():212 global controlPoints213 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)214 glPushMatrix()215 gluLookAt(3, 3, 3, # eye position216 0, 0, 0, # aim position217 0, 0, 1) # up direction218 global mouseInteractor219 mouseInteractor.applyTransformation()220 show_axis()221 display_surface()222 display_control()223 global index_i, index_j224 drag_control(index_i, index_j, mouseInteractor)225 glPopMatrix()226 glutSwapBuffers()227def init():228 glClearColor(0, 0, 0, 1)229 glShadeModel(GL_SMOOTH)230 glEnable(GL_DEPTH_TEST)231 glEnable(GL_MAP2_VERTEX_3)232 glEnable(GL_AUTO_NORMAL)233 glEnable(GL_POINT_SMOOTH)234 global mouseInteractor235 mouseInteractor = MouseInteractor(.01, 1)236class MainWindow(QMainWindow, Ui_Window_4):237 def __init__(self, parent=None):238 super(MainWindow, self).__init__(parent)239 self.setupUi(self)240 self.horizontalSlider.setValue(2)241 self.radioButton_1.toggled.connect(self.horizontalSlider.setEnabled)242 self.radioButton_2.toggled.connect(self.horizontalSlider.setDisabled)243 self.radioButton_1.toggled.connect(self.display_1)244 self.radioButton_2.toggled.connect(self.display_2)245 self.pushButton_1.clicked.connect(self.reset_control)246 self.pushButton_2.clicked.connect(self.random_control)247 self.pushButton_3.clicked.connect(self.read_file)248 self.pushButton_4.clicked.connect(self.save_plot)249 self.horizontalSlider.valueChanged.connect(self.reset_control)250 self.initUI()251 self.initGL()252 def initUI(self):253 self.setWindowTitle("Computer Graphics Final")254 self.setWindowIcon(QIcon("final/04.png"))255 self.move(QPoint(920, 100))256 self.show()257 def initGL(self):258 glutInit(sys.argv)259 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)260 glutInitWindowSize(800, 800)261 glutInitWindowPosition(100, 100)262 glutCreateWindow(sys.argv[0])263 init()264 mouseInteractor.registerCallbacks()265 glutDisplayFunc(display)266 glutReshapeFunc(reshape)267 glutKeyboardFunc(keyboard)268 # glutIdleFunc(animationStep)269 glutMainLoop()270 def display_1(self):271 global dis_con272 dis_con = True273 glutPostRedisplay()274 def display_2(self):275 global dis_con276 dis_con = False277 glutPostRedisplay()278 def reset_control(self):279 global controlPoints, nPts280 nPts = int(self.horizontalSlider.value()) + 1281 controlPoints = generate_control(nPts)282 glutPostRedisplay()283 def random_control(self):284 global controlPoints, nPts285 nPts = int(self.horizontalSlider.value()) + 1286 controlPoints = generate_control(nPts)287 updateControlPoints([])288 glutPostRedisplay()289 def read_file(self):290 fname = QFileDialog.getOpenFileName(self, 'Open File', 'C:\\', "txt files (*.txt)")291 z_axis = list()292 if os.path.isfile(fname[0]):293 with open(fname[0], 'r') as in_file:294 lines = in_file.readlines()295 result = math.sqrt(len(lines))296 if result % 1 == 0:297 for line in lines:298 z_axis.append(eval(line))299 # print(z_axis)300 global controlPoints, nPts301 self.horizontalSlider.setValue(int(result) - 1)302 nPts = int(self.horizontalSlider.value()) + 1303 controlPoints = generate_control(nPts)304 updateControlPoints(z_axis)305 glutPostRedisplay()306 def save_plot(self):307 glPixelStorei(GL_PACK_ALIGNMENT, 1)308 data = glReadPixels(0, 0, 800, 800, GL_RGBA, GL_UNSIGNED_BYTE)309 image = Image.frombytes("RGBA", (800, 800), data)310 image = ImageOps.flip(image)311 image.save('final/glut_out_{}.png'.format(time.strftime("%H-%M-%S")), 'PNG')312 z_axis = list()313 global controlPoints314 for row in controlPoints:315 for coord in row:316 z_axis.append(coord[2])317 with open('final/control_points_save.txt', 'w') as out_file:...

Full Screen

Full Screen

106a_follow_waypoints.py

Source:106a_follow_waypoints.py Github

copy

Full Screen

...7273def dot(a, b):74 return a.x * b.x + a.y * b.y + a.z * b.z7576def generate_control(client, world, vehicle, waypoint, prev_waypoint):7778 forward_dir = vehicle.get_transform().rotation.get_forward_vector()79 p_vehicle = vehicle.get_transform().location80 pd_vehicle = vehicle.get_velocity()81 pdd_vehicle = vehicle.get_acceleration()82 R_vehicle = vehicle.get_transform().rotation.yaw83 Rd_vehicle = distance(vehicle.get_angular_velocity(), carla.Vector3D(0, 0, 0))84 clockwise = False if vehicle.get_angular_velocity().z > 0 else True85 if clockwise:86 Rd_vehicle = -Rd_vehicle8788 if generate_control.prev_yaw is None:89 generate_control.prev_yaw = R_vehicle9091 # This yaw stuff is meant to correct the angles being given in a range [-180, 180] which makes it really discontinuous.92 # However, this correction code does not work.93 if R_vehicle < 0 and generate_control.prev_yaw > 0 and clockwise:94 generate_control.yaw_shift += 36095 elif R_vehicle > 0 and generate_control.prev_yaw < 0 and not clockwise:96 generate_control.yaw_shift -= 36097 R_vehicle += generate_control.yaw_shift9899 p_target = waypoint.position100 pd_target = carla.Vector3D(0, 0, 0)101102 cur_dist_to_tgt = distance(p_target, p_vehicle)103 orig_dist_to_tgt = distance(p_target, prev_waypoint.position)104 frac_dist_to_tgt = 1 - np.clip(cur_dist_to_tgt / (orig_dist_to_tgt), 0, 1)105 R_target = (1 - frac_dist_to_tgt) * prev_waypoint.rotation + frac_dist_to_tgt * waypoint.rotation106 Rd_target = 0107108 Kp_p = 0.2109 Kd_p = 0.25110111 Kp_R = 0.1112 Kd_R = 0113114 control = carla.VehicleControl()115116 travel_vector = p_target - p_vehicle117 # Ignoring perpendicular case for now118 control.reverse = False if dot(travel_vector, forward_dir) > 0 else True119120 control.throttle = Kp_p * distance(p_target, p_vehicle)121 traveld_vector = pd_target - pd_vehicle122 if dot(pdd_vehicle, traveld_vector) > 0:123 control.throttle += Kd_p * distance(pd_target, pd_vehicle)124 else:125 control.throttle -= Kd_p * distance(pd_target, pd_vehicle)126127 if control.throttle < 0:128 control.throttle = -control.throttle129 control.reverse = not control.reverse130 control.throttle = np.clip(control.throttle, 0, 1)131 132 # Need to verify that the derivative control on angle works133 control.steer = np.clip(Kp_R * (R_target - R_vehicle) + Kd_R * (Rd_target - Rd_vehicle) , -1, 1)134135 moving_forward = True if dot(vehicle.get_velocity(), forward_dir) > 0 else False136 if not moving_forward:137 control.steer = -control.steer138139 return control140141generate_control.prev_yaw = None142generate_control.yaw_shift = 0143144def follow_waypoints(client, world, vehicle, waypoints):145 assert(len(waypoints) >= 1)146 current_waypoint_i = 0147 current_waypoint = waypoints[current_waypoint_i]148 prev_waypoint = current_waypoint149150 while True:151 position = vehicle.get_transform().location152 rotation = vehicle.get_transform().rotation.yaw153154 print("")155 print(current_waypoint.position, current_waypoint.rotation)156 print(position, rotation)157 print(current_waypoint.error(position, rotation))158 if current_waypoint.error(position, rotation) < WAYPOINT_ERROR_THRESHOLD \159 and current_waypoint_i + 1 < len(waypoints):160 current_waypoint_i += 1161 prev_waypoint = current_waypoint162 current_waypoint = waypoints[current_waypoint_i]163164 control = generate_control(client, world, vehicle, current_waypoint, prev_waypoint)165 vehicle.apply_control(control)166 167 world.tick()168169170def main(args):171 client = carla.Client(args.host, args.port)172 client.set_timeout(10.0)173174 rng = np.random.default_rng(args.seed)175176 vehicle = None177 try:178 world = client.get_world() ...

Full Screen

Full Screen

custom_targets.py

Source:custom_targets.py Github

copy

Full Screen

1Import("env")2if env['PIOENV'] == "release":3 env.AddCustomTarget(4 "generate_control",5 "$BUILD_DIR/${PROGNAME}.bin",6 "misc/generate_control.py"7 )8else:9 env.AddCustomTarget(10 "generate_control",11 "$BUILD_DIR/${PROGNAME}.bin",12 "true"...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful