https://www.automationdirect.com/adc/home/home
(VID-BS-0003) A robotic arm project for the new Programming Merit Badge. This was used at the National Jamboree.
AutomationDirect donated time and equipment for the creation of these Boy Scouts of America Merit Badge videos.
robotics is an awesome way to learn programming because you get to see your efforts in real world action that's fun before we get started with the programming let's get familiar with the robot pick up the controller and do what i do the left joystick controls the waist and shoulder pivots try it move it left right to rotate the waist and move it forward and backwards to move the shoulder joint go slow this robot can do some damage this joystick controls the elbow and the wrist forward backwards the elbow left right is the wrist rotation try it but again be careful we're going to use this example to satisfy requirement 5a whereas a minimum you can simply modify an existing program our goal we're going to add a routine that somebody else wrote to control the wrist and we'll modify that wrist routine to limit the rotation of the wrist we'll be using a c programming language called easy c it's the regular c programming language but it takes care of all that nasty syntax for you and it uses a simple drag and drop user interface to get you up and running quickly click on this tab right here and you'll see the main program this is called a while loop this loop runs over and over and over again as long as the stuff in parentheses never turns to zero well we have a one there so this is going to run forever until you turn the power off on the robot what's it going to do over and over and over again it's going to run the routine that controls the waist a routine that controls the shoulder another routine that controls the elbow and another routine that controls the claw these were all written for us by somebody else but something's missing isn't it there's no wrist routine is there let's download this program to the robot and make sure that there is no wrist action to do that hit build and download build and download go ahead and do that ezc takes all of this stuff that we did here and converts it into code that the robot can understand it says right here that that was successful do we want to download it to the robot sure that gives us a dialog that looks like this and you can see the program being downloaded to the robot that program is going from the computer through this orange cable to the joystick the joystick is then transmitting the code wirelessly down to the processor that file was successfully downloaded so now if you pick up the joystick and move that right joystick left and right nothing happens the wrist doesn't move does it exactly what we expected so let's add that wrist routine in kill this dialog and all you have to do is come over here to this list of user functions grab the wrist routine and drag it onto this line right here let's go ahead and put it between the elbow and the clogs that makes sense drop it in say ok and boom we just added the wrist routine to our robot go ahead and build and download build and download it'll compile the project again that was successful do we want to download it yes we do you should see this dialog pop up and the code starts downloading to the robot while it's downloading these green check marks tell me the easy css check to make sure that the correct firmware is in both the robot and the joystick it's also telling me that the battery voltages are good in the robot and the joystick we're not using the backup battery so it's zero right now okay that was successful so we say okay okay now pick up the joystick and move that right joystick left and right does your wrist work awesome so we just added the wrist routine to the robot but there's still a problem isn't there the wrist moves too far to the left and too far to the right well let's go take a look at that routine kill this dialog double click on the wrist routine right here this is the routine that controls the wrist this line says read joystick number one channel one and put the answer in this memory location look on the joystick channel 1 is this joystick moving left and right which we know is the wrist right perfect suppose we wanted this other joystick left right to control the wrist well we would simply tell it to read channel 4. easy now where did this come from well over here on the left we just grabbed this joystick function and dropped it on this line over here this line says read the potentiometer that's plugged into slot 4. that's this red thing right here on the robot and here's slot 4 on the processor most people call a potentiometer a pot just because it's easier to say the pot changes its value as the claw rotates this utility lets me see what the pot is doing if i manually move the wrist you can see this value right here change so in the center of the wrist is about 400 if i rotate it all the way this way the wrist goes up over a thousand and i rotate the wrist back this way and the pot goes to zero i can tell exactly where the wrist is it's somewhere between zero which is rotated all the way one way and a thousand which is rotated all the way the other way which means the center would be around oh 500 or so right now skip this stuff for a second and down here you can see we simply take the joystick value that we read from the joystick up here and we use that to set the speed of motor number six which is our wrist motor now the only problem with that is since the joystick is setting the speed of the motor that motor could keep rotating forever which would twist up all the wires and eventually rip them right out of the robot that would be a bad thing so we have to limit how far the motor can turn and that's what all this stuff is up here to do that we just read the potentiometer and when it reaches a certain value we tell the motor to stop so this if statement says if the potentiometer is getting close to zero and the joystick is negative that is is trying to tell the motor to go in that direction we set the joystick to zero it tells the motor to stop on the other end we say else if the potentiometer is getting really really big is getting close to that 1000 we saw and the joystick is positive it's telling the motor to go in the positive direction then we set the joystick to zero so now down here the motor will be set to zero if the claw tries to go too far one way or the other so in this example the wrist turns almost all the way one way and almost all the way the other way let's limit it so the wrist can't go quite so far let's limit it's right around the middle so i'm going to change this one from 100 to something just under 500 how about about 300. and this one let's limit him the other way so let's take that 900 down to 700. so in theory we just limited how far that risk can turn try it you can do build and download build download or better yet just hit f7 it's quicker successfully built let's download that to our robot here's that dialog and it was successfully downloaded to the robot pick up the joystick and see if the wrist rotation doesn't turn as far as before move the wrist slowly so that the wrist doesn't overshoot our set point and sure enough we've limited how far risk can turn perfect suppose we want the wrist to rotate slower than it does well that's easy since the joystick value that we read back here controls the speed of motor 6 we just double click on this and we divide that by whatever factor we want let's try and slow it down by a factor of 3. hit f7 to compile the project it's successful we do want to download it to the robot here's our download dialog and we'll wait for that to finish okay the download was successful pick up the joystick and see if the claw rotates slower now and sure enough it moves a lot slower so that's all there is to it we just took an existing program over in the main program we added the wrist routine then we changed that wrist routine to limit the motion of the claw and slow the claw down now what if i wanted to change oh say the waste routine how do you think that works well it rotates right and it rotates when you move the joystick and it's its motion is limited it can't go all the way around well gosh that sounds a lot like what we just did doesn't it well let's go take a look at that waste routine get this picture in your head double click on this and look it's the exact same routine isn't it we read the joystick we read the potentiometer we limit the motion of the waste based on the potentiometer value and we send the potentiometer value out to the motor in this case it's motor 1 instead of motor 6 and in this case we're reading joystick channel 4 instead of channel 1 but otherwise it's the exact same code isn't it and that's how it usually goes with programming once you know one thing you can apply it to lots of other things well that's enough to give you a feel for robotics programming and now that you have an idea of what it takes to program a robot you should see if there's a robotics team at your school and go check it out it's a lot of fun and having robotics on your college resume opens a lot of doors some of the robotics competitions even offer college scholarships so go check that out we want to thank vex robotics for supporting this mirror patch you can learn more about vex robotics at vectrobotics.com and the vector robotics competitions at robotevents.com
Voted #1 mid-sized employer in Atlanta
Check out our
job openings