Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
Without some kind of external input (analog or digital / photoresistor or basic switch) you can't have anything but preprogrammed movements. Getting the preprogrammed movements to work seems to be a prerequisite to making the movements work in relation some sort of external input.
What the code does. Imagine the two windshield wipers on a car. Imagine you've got two servos, one for each windshield wiper. The first sequence will make the two wipers move from left to right and back, at the same time. It will take 10 seconds to move from left to right and another 10 seconds to move from right to left. When that's done the two servos will start moving in the opposite directions (one "wiper" moves from left to right, the other "wiper" moves from right to left). This will happen 4 times faster then the first example!
Center servoLoop Forever for 500 milliseconds servo1 turn right servo2 turn left pause for 250 milliseconds FOR 250 milliseconds servo2 go right servo1 center End
Build C:\My_Robots\ARM 13\Servo Center\Servo_Seq\Servo_Seq for device 16F684Using driver C:\Program Files\HI-TECH Software\PICC\LITE\9.60\bin\picl.exedelay.obj is up-to-dateServo_Seq vSoR.obj is up-to-dateExecuting: "C:\Program Files\HI-TECH Software\PICC\LITE\9.60\bin\picl.exe" -oServo_Seq.cof -mServo_Seq.map delay.obj "Servo_Seq vSoR.obj" --chip=16F684 -P -q -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s" *****Error [499] ; . undefined symbol: _Delay (Servo_Seq vSoR.obj) ***************** Build failed! **************
#include <pic.h>#include "delay.h"__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT & BORDIS & IESODIS & FCMDIS);// This routine takes two parameters, from 0 to 250, that will represent 250 possible positions// for every one of the two servos.void servopulse(unsigned char PulseRA2, unsigned char PulseRA1) { // First pulse RA2 RA2=1; DelayMs(1); DelayMs(PulseRA2); DelayMs(PulseRA2); DelayMs(PulseRA2); DelayMs(PulseRA2); RA2=0; // Now pulse RA1 RA1=1; DelayMs(1); DelayMs(PulseRA1); DelayMs(PulseRA1); DelayMs(PulseRA1); DelayMs(PulseRA1); RA1=0; // Wait for a while; The delay is shorter then the // original delay to account both 2ms pulses DelayMs(16); }// This is one possible first sequence for the servos. Both servos will move at the same time// to the same positions. I want the full swing from left to right to take about 10 seconds; Since I'll// have 250 steps for each servo, the servo will need to hold each of those 250 steps for// (20 * 1000) / 250 = 40 ms. Since the "servopulse" routine takes about 20 ms I'll call that routine// twice for each of the 250 positions.void sequence1(void) { unsigned char pos; // swing from left to right for(pos=0;pos<250;pos++) { servopulse(pos,pos); servopulse(pos,pos); } // swing from right to left for (pos=250;pos>0;pos--) { servopulse(pos,pos); servopulse(pos,pos); }}// This second sequence will make the servos move in oposite directions. This time I want the swing// to take about 2.5 seconds; If I'd stop at each of the 250 possible positions along the way// I'd need to make each position hold for only 10ms. This is not possible because the "servopulse"// routine takes about 20ms to run, so I'll simply skip steps.void sequence2(void) { unsigned char pos; unsigned char pos2; // First swing for (pos=0;pos<250;pos=pos+2) { pos2=250-pos; servopulse(pos,pos2); } // Reverse swing for (pos=0;pos<250;pos=pos+2) { pos2=250-pos; servopulse(pos2,pos); }}main(){ TRISA = 0b11111001; // Make RA2 and RA1 outputs // Do the first sequence once sequence1(); // Look pthe second sequence for ever while(1 == 1) sequence2(); }
#include <pic.h>#include "delay.h"__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT & BORDIS & IESODIS & FCMDIS);// This routine takes two parameters, from 0 to 250, that will represent 250 possible positions// for every one of the two servos.void servopulse(unsigned char PulseRA2) { // First pulse RA2 RA2=1; DelayMs(1); DelayMs(PulseRA2); DelayMs(PulseRA2); DelayMs(PulseRA2); DelayMs(PulseRA2); RA2=0; // Wait for a while; The delay is shorter then the // original delay to account both 2ms pulses DelayMs(16); }void servopulse2(unsigned char PulseRA2) { RA2=1; DelayMs(2); DelayMs(PulseRA2); DelayMs(PulseRA2); DelayMs(PulseRA2); DelayMs(PulseRA2); RA2=0; // Wait for a while; The delay is shorter then the // original delay to account both 2ms pulses DelayMs(16); }// This second sequence will make the servos move in oposite directions. This time I want the swing// to take about 2.5 seconds; If I'd stop at each of the 250 possible positions along the way// I'd need to make each position hold for only 10ms. This is not possible because the "servopulse"// routine takes about 20ms to run, so I'll simply skip steps.void sequence2(void) { unsigned char pos; unsigned char pos2; // First swing for (pos=0;pos<250;pos=pos+2) { pos2=250-pos; servopulse(pos,pos2); } // Reverse swing for (pos=250;pos>250;pos=pos+2) { pos2=250-pos; servopulse2(pos2); }}main(){ TRISA = 0b1111011; // Make RA2 and RA1 outputs // Loop the second sequence for ever while(1 == 1) sequence2(); }
#include <pic.h>#include "delay.h"__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT & BORDIS & IESODIS & FCMDIS);void servopulse(unsigned char PulseRA2) { // First pulse RA2 RA2=1; DelayMs(1); DelayMs(PulseRA2); DelayMs(PulseRA2); DelayMs(PulseRA2); DelayMs(PulseRA2); RA2=0; DelayMs(40); }void servopulse2(unsigned char PulseRA2) { RA2=1; DelayMs(2); DelayMs(PulseRA2); DelayMs(PulseRA2); DelayMs(PulseRA2); DelayMs(PulseRA2); RA2=0; DelayMs(40); }void sequence(void) { unsigned char pos; // swing from left to right for(pos=0;pos<250;pos++) { servopulse(pos); servopulse(pos); } // swing from right to left for (pos=250;pos>0;pos--) { servopulse2(pos); servopulse2(pos); }}main(){ TRISA = 0b1111011; // Make RA2 an output while(1 == 1) { sequence (); }}
Open up the "delay.h" file and edit the first line, that's where the MCU clock speed is set up. Change that to read "4Mhz" (don't tuch the zeroes, change the "16" with "4")
#include <pic.h>#include "delay.h"__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT & BORDIS & IESODIS & FCMDIS);// This routine takes two parameters, from 0 to 250, that will represent 250 possible positions// for every one of the two servos.void servopulse(unsigned char PulseRA2, unsigned char PulseRA1) { // First pulse RA2 RA2=1; DelayMs(1); DelayMs(PulseRA2); DelayMs(PulseRA2); DelayMs(PulseRA2); DelayMs(PulseRA2); RA2=0; // Now pulse RA1 RA1=1; DelayMs(1); DelayMs(PulseRA1); DelayMs(PulseRA1); DelayMs(PulseRA1); DelayMs(PulseRA1); RA1=0; // Wait for a while; The delay is shorter then the // original delay to account both 2ms pulses DelayMs(16); }// This is one possible first sequence for the servos. Both servos will move at the same time// to the same positions. I want the full swing from left to right to take about 10 seconds; Since I'll// have 250 steps for each servo, the servo will need to hold each of those 250 steps for// (20 * 1000) / 250 = 40 ms. Since the "servopulse" routine takes about 20 ms I'll call that routine// twice for each of the 250 positions.void sequence1(void) { unsigned char pos; // swing from left to right for(pos=0;pos<250;pos++) { servopulse(pos,pos); servopulse(pos,pos); } // swing from right to left for (pos=250;pos>0;pos--) { servopulse(pos,pos); servopulse(pos,pos); }}// This second sequence will make the servos move in oposite directions. This time I want the swing// to take about 2.5 seconds; If I'd stop at each of the 250 possible positions along the way// I'd need to make each position hold for only 10ms. This is not possible because the "servopulse"// routine takes about 20ms to run, so I'll simply skip steps.void sequence2(void) { unsigned char pos; unsigned char pos2; // First swing for (pos=0;pos<250;pos=pos+2) { pos2=250-pos; servopulse(pos,pos2); } // Reverse swing for (pos=0;pos<250;pos=pos+2) { pos2=250-pos; servopulse(pos2,pos); }}main(){ TRISA = 0b11111001; // Make RA2 and RA1 outputs // Do the first sequence once sequence1(); // Look pthe second sequence for ever while(1 == 1){ sequence2(); } }
#include <pic.h>#include "delay.h"__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT & BORDIS & IESODIS & FCMDIS);int j;main(){ TRISA = 0b111110; while (1) { for(j=0;j<500;j++) { RA0 = 1; DelayUs(250); DelayUs(250); DelayUs(250); RA0 = 0; DelayMs(18); } for(j=500;j>0;j--) { RA0 = 1; DelayMs(2); DelayUs(250); DelayUs(100); RA0 = 0; DelayMs(18); } } // End WHILE}