registered authors login here For more on PMWiki, see pmwiki.org |
I am wondering if there are notes on how to be more specific with the movement of the servo? I don't quite get how the range of movement is set, and also if the server starts in the exact same place when it resets. I want to translate the movement of the servo to a straight path to go to a position, pause for about 1 minute and return to the start position. there's really nothing more to say than that you need to modify the pulsewidth. Try taking out the if-then block of the example and putting in specific values. Keep in mind that you need a pulse every 20 ms no matter what. Try something like this:
x var word
x = 0
' add in other pre-main loop code and main loop label here
' set to a position:
pulsewidth = 150
' stay at that position for 2000 x 20ms
for x = 0 to 2000
pulsout portc.3, pulsewidth
pause 20
next
'set to another position:
pulsewidth = 200
' stay at that position for 2000 x 20ms
for x = 0 to 2000
pulsout portc.3, pulsewidth
pause 20
next
' and so forth.
I finally got the servo motor working with the pot. Here was my error. I was cutting and pasting code together and I realized that I was initializing variables before the start: code block, before the min/max constants had been declared. I wasn't sure what start: was. At first I thought it was a subroutine, but then it didn't look like the subroutines we learned before. It seems like it is similar to the setup code block we learned last week in processing-- is this right? I need to read further in the PIC Basic Docs. It's a total newbie error, but I'm posting this here for other newbs to look out for. Here's the documentation (posted retroactively) it is similar to setup() in Processing. Remember when I mentioned that any word that's not in the PicBasic Pro manual is either a variable or a label, and if it's on a line by itself with a colon after it, PicBasic Pro interprets it as a label. So "start:" is a label. A label can mark the beginning of a main routine or a subroutine, or just a place in the code that you want to refer to. You might use a "start" label if there was a time in your code when you wanted to re-initialize variables back to what they were at the beginning, for example, in a game, when the game's over and you want to reset the game. Can someone tell me how to go about sending a freqout two pins simultaneously? Is it even possible? I've tried setting TRISB to output and then saying "freqout portb, pitch, pitch," but I'm not getting any response. Do I have to do something tricky like alternating each pin for a short time to give the illusion of simultaneity? not strictly possible, but if you have two short freqout commands (less than 20ms duration each) right after each other, they can seem like a simultaneous freqout to the ear. I determined how to control my servo by trial and error. I started with 50 & 250 as minimum and maximum, but found 250 to be a little too high for my particular servo. After taking it down to 200, the whole thing worked significantly better. Good! That's the kind of systematic experimentation you need to engage in whenever debugging a project. A tip for anyone whose servo won't stay in one place... I spent a while trying to make nice brackets for my servo to hold it down to my project before remembering duct tape's sassy cousin: double-sided foam tape squares. Now my servo isn't going anywhere. I've got more of the stuff too - find me if you need any. Otherwise, Duane Reade and Radio Shack should both have some in stock. For no good reason, except to entertain myself, I strung some thread from my servo motor, through loops I attached to the arms of my glasses, to some rubber hooks that I put in the corner of my mouth. Then, when I turn the pot, the servo rotates, pulls the thread and winches up the corners of my mouth - bingo! - instant fake smile. Except it was more of a grimace. And then it broke. Please don't let me forget to ask a question about using CASE instead of IF THEN in PIC Basic Pro tomorrow. I'm trying to set it up, but I'm not sure exactly how to translate my If then statement to the case scenario. Thanks to Robert for introducing me to CASE, but I still don't know how to operate without an ELSE IF. ''Are you looking for something like this?"
SELECT CASE myVar
CASE 1
SEROUT2 PORTC.6, 16468, ["One", 13,10]
CASE 2, 3
SEROUT2 PORTC.6, 16468, ["Two or Three", 13,10]
CASE IS > 5
SEROUT2 PORTC.6, 16468, ["Greater than 5", 13,10]
CASE ELSE
SEROUT2 PORTC.6, 16468, ["Four, Five, or Zero", 13,10]
END CASE
Case can sometimes be easier than multiple if statements. I've never tried compound statements like "CASE (IS > 5) AND (IS <10)" but all of the other statements above work. Ed, can I do the same with my nose if I give you credit? I loved Bewitched when I was a kid. This week's lab strayed a bit, but it might be interesting to others- Instead of working with servos, I worked with an RGB LED. The principle is the same, more or less- use pulsout to manipulate different colors instead of a motor. You can find documentation and code here. The LED was bought from http://www.superbrightleds.com I forgot to post this week. I did the basic lab, but also hacked into the servo. The continuous motion of the motor by way of the reading from the pot is due to the servo's "stoppage" mechanism being disabled. the other working's of the servo will have to be researched further. More possibilities? More problems? We'll soon see. Andrew Schneider A week late, but finally got around to playing with servos. I can't call it mastery but was quite pleased with the results of the modifications to tom's pwm codes. After loading the code up with a blinking indicator light and simultaneously sending info to hyperterminal via the serial connection, I had to tweak all the pauses in the program so that the servo wouldn't step. There must be a way to isolate the code for the debugging features.... I ended the evening by combining the peak level program from tom's code library with the pwm programs in an effort to make the light following dial from part 3 or the lab. I was able to make pretty decent working code, but it's not perfect. Still it's very exciting to make something that's actually following your movement. I've posted the code for my Binary_Glove_Teacher for those of you who asked to see how it was accomplished. Summer and I did this lab together. I just got around to posting the documentation but could not locate our code. lab #4 |