250 likes | 477 Views
Robotics. Coordinates, position, orientation kinematics. HTML5 reading file. Homework: Prepare for lab. Postings. Coordinate system. Method of providing system for specifying points / positions / vectors in a given N-dimensional space.
E N D
Robotics Coordinates, position, orientation kinematics. HTML5 reading file. Homework: Prepare for lab. Postings
Coordinate system • Method of providing system for specifying points / positions / vectors in a given N-dimensional space. • This space, typically, is a line (1D), plane (2D), or space (3D). • The most common coordinate system is Cartesian: 3 orthogonal, linear dimensions; fixed origin • Position of origin needs to be specified • Orientation of axes needs to be defined • Right-hand rule is convention involving relationship of x, y and z • Another common system for the plane is polar (angle and distance), cylindrical (polar + height) or spherical (3D vector + distance) for space.
Polar x = d * cos(a) y = d * sin (a) a= atan(y/x) need to specify quadrant—computer atan function may do this. d = sqr(x*x+y*y) d y a x
Note • May be easier to collect positions in polar coordinates and then convert them, as needed, to something else. • REPEAT: critical issue is defining the origin.
Addition (of moves) Robot moved … and moved again. • Adding [cartesian] vectors • (x1, y1) + (x2,y2) IS (x1+x2, y1+y2) • Need to be aware of when something is a position and when it is a displacement • Adding polar coordinates • Convert to cartesian and convert back!
Position • … of what? • Robot wheel base • Robot ultrasonic sensor • Robot bumper or touch sensor itself • Robot light sensor
Orientation • Where is robot facing? • Plane: 2 positional degrees of freedom and 1 angle • Space: 3 positional degrees of freedom and 3 angles.
Reference • Neat Flash animation on vectors • Ocean, bottle, current http://ephysics.physics.ucla.edu/newkin/html/position_velocity_ship.htm http://ephysics.physics.ucla.edu/newkin/html/position_velocity_ship.htm
Kinematics • For linked/jointed structures, calculating the position of the end-point, given the position/angle of each joint. • Easy (easier) problem
Inverse kinematics • Given jointed/linked structure, what are positions of joints/angles to make endpoint be at a given point? • May be no answer or multiple answers • Easy for IBM Box frame robot: links were not coupled. • For articulated mechanisms, various approaches, often requiring iterative techniques.
Challenge: mapping • Program the robot to provide map of the room • More precisely, provide coordinates of positions of walls/barriers/lines (points)(think about connecting points later) • Upload using Mindstorms to Desktop. HTML5 program draws points. • (Later) send file (single position is 2 numbers) to other robot using Bluetooth • (Later) automatically upload file to computer
HTML5 JavaScript • reads in whole file • HTML5 file API. More general / more features than used for this example. • Note: asynchronous action. Set up function for the event of indicating the file AND set up function for the event of reading in the text data. • program detects line breaks • program converts from text to number • draws on canvas • blue dot is the center • red dots are calculated positions • Note: draws based on standard, not upside down!, coordinates.
testpairs.txt file 0 50 20 60 120 35 200 60 300 40
HTML5 program drawing positions • http://faculty.purchase.edu/jeanine.meyer/robotics/mapdata.html • Works in Firefox • Two sample files: • textpairs.txt • textpairs3.txt
HTML5 functions • init • readInData • receivedText • drawpositions • drawdot
HTML5 outline <html> <head><script>….</script></head> <body onload="init();"> Name the file: <input type="file" id="fileinput" " /> <canvas id="canvas" width="900" height="600"> The browser does not recognize canvas. </canvas> </body> </html>
global data and init function var ctx; var center = [450,300]; var rad = 5; var data; function init() { ctx = document.getElementById("canvas").getContext("2d"); drawdot(center[0],center[1],"blue"); document.getElementById("fileinput").addEventListener('change',readInData,false); }
function readInData(ev) { var input = document.getElementById("fileinput"); if (!input.files) { alert("browser doesn't seem to support files "); return; } else if (!input.files[0]) { alert("please select a file"); return; } else { file = input.files[0]; fr = new FileReader(); fr.onload = receivedText; fr.readAsText(file); } }
function receivedText() { var i; data = fr.result.split("\n"); for (i=0;i<data.length;i++) { data[i] = Number(data[i]); } drawpositions(); }
function drawpositions() { //uses info in data array var i; var angle; var dist; var x; var y; for(i=0;i<data.length;i=i+2) { angle = (data[i]/180)*Math.PI; dist = data[i+1]; x = center[0]+dist*Math.cos(angle); y = center[1]-dist*Math.sin(angle); drawdot(x,y,"red"); } }
function drawdot(x,y,color) { ctx.fillStyle = color; ctx.beginPath(); ctx.arc(x,y,rad,0,2* Math.PI,true); ctx.fill(); ctx.closePath(); }
Lab: Mapping • One group of strategies is to generate any number of points along walls. • Leave it to other program to connect dots • Another strategy is to measure walls • Walk along walls, mark points or lengths • You can make assumptions (constraints) on shape of room • "Build" room using books or other obstacles.
Homework • Postings • Start/Continue work on mapping strategy / strategies • What sensor(s)? • How to specify origin? • Amount of travel versus walls versus ????