View unanswered posts | View active topics It is currently Thu Sep 18, 2014 2:46 pm






Reply to topic  [ 2 posts ] 
automatic control vs manual control servos 
Author Message
Rookie

Joined: Fri Mar 15, 2013 10:54 am
Posts: 1
Post automatic control vs manual control servos
So I have an interesting issue. I have serial input from the arduino enable either manual control or automatic control. the options cycle (ex. 0 or 9 and 0 again etc) however, my issue is the manual code does not make the manual code work per-say. The manual code itself works, as well as the automated control if compiled seperately. however when combining the two, t glitches.

long story short:
1) serial input options are confirmed working. so 0 can be hit then 9 then 0 then 9 etc etc etc
2) automatic control commands (9) works
3) manual control CONDITION is confirmed if selected from serial input but manual control does not work...servos glitch around (twitch).

my buddy mentioned it may be an issue with the variables being declared accross both selections however in my opinion it shouldn't be the problem.


ANY HELP PLEASE? CODE BELOW :) THANKS IN ADVANCE.

_________________________________________________________________



#include <Servo.h>


Servo thumbmain;
Servo thumbmiddle;
Servo thumbtip;

Servo pointermain;
Servo pointermiddle;
Servo pointertip;

Servo middlemain;
Servo middlemiddle;
Servo middletip;

Servo ringmain;
Servo ringmiddle;
Servo ringtip;

Servo pinkymain;
Servo pinkymiddle;
Servo pinkytip;

int times = 0;

int tm = 0;
int tt = 1;
int pm = 2;
int pt = 3;
int mm = 4;
int mt = 5;
int rm = 6;
int rt = 7;
int lm = 8;
int lt = 9;

int vtm;
int vtt;
int vttt;

int vpm;
int vpt;
int vptt;

int vmm;
int vmt;
int vmtt;

int vrm;
int vrt;
int vrtt;

int vlm;
int vlt;
int vltt;



void setup()
{
Serial.begin(9000);
Serial.println("Manual control = 0 , Automated movement = 9");

thumbmain.attach(13);
thumbmiddle.attach(12);
thumbtip.attach(11);

pointermain.attach(10);
pointermiddle.attach(9);
pointertip.attach(8);

middlemain.attach(7);
middlemiddle.attach(6);
middletip.attach(5);

ringmain.attach(4);
ringmiddle.attach(3);
ringtip.attach(2);

pinkymain.attach(44);
pinkymiddle.attach(45);
pinkytip.attach(46);
}

void loop()
{
if (Serial.available())
{

char x = Serial.read();
{
if (x=='0')
{
Serial.println("Manual Control initialized");
vtm = analogRead(tm);
vtm = map(vtm,150,300,0,90);
thumbmain.write(vtm);
delay(1);
vtt = analogRead(tt);
vtt = map(vtt,110,300,0,140);
thumbmiddle.write(vtt);
delay(1);
vttt = analogRead(tt);
vttt = map(vttt,110,300,0,90);
thumbtip.write(vttt);
delay(1);

vpm = analogRead(pm);
vpm = map(vpm,110,300,0,100);
pointermain.write(vpm);
delay(1);
vpt = analogRead(pt);
vpt = map(vpt,110,300,0,140);
pointermiddle.write(vpt);
delay(1);
vptt = analogRead(pt);
vptt = map(vptt,110,300,0,90);
pointertip.write(vptt);
delay(1);

vmm = analogRead(mm);
vmm = map(vmm,110,300,0,100);
middlemain.write(vmm);
delay(1);
vmt = analogRead(mt);
vmt = map(vmt,110,300,0,140);
middlemiddle.write(vmt);
delay(1);
vmtt = analogRead(mt);
vmtt = map(vmtt,110,300,0,90);
middletip.write(vmtt);
delay(1);

vrm = analogRead(rm);
vrm = map(vrm,110,300,0,100);
ringmain.write(vrm);
delay(1);
vrt = analogRead(rt);
vrt = map(vrt,110,300,0,140);
ringmiddle.write(vrt);
delay(1);
vrtt = analogRead(rt);
vrtt = map(vrtt,110,300,0,90);
ringtip.write(vrtt);
delay(1);

vlm = analogRead(lm);
vlm = map(vlm,110,300,0,100);
pinkymain.write(vlm);
delay(1);
vlt = analogRead(lt);
vlt = map(vlt,110,300,0,140);
pinkymiddle.write(vlt);
delay(1);
vltt = analogRead(lt);
vltt = map(vltt,110,300,0,90);
pinkytip.write(vltt);
delay(1);

Serial.println("manual");

}
else if (x=='9')
{
vpm=0;
vmm=0;
vrm=0;
vlm=0;

pointermain.write(vpm);
delay(10);
pointermiddle.write(vpm);
delay(10);
pointertip.write(vpm);
delay(10);

middlemain.write(vmm);
delay(10);
middlemiddle.write(vmm);
delay(10);
middletip.write(vmm);
delay(10);

ringmain.write(vrm);
delay(10);
ringmiddle.write(vrm);
delay(10);
ringtip.write(vrm);
delay(10);

pinkymain.write(vlm);
delay(10);
pinkymiddle.write(vlm);
delay(10);
pinkytip.write(vlm);
delay(10);


do
{
vmm++;
middletip.write(vmm);
delay(5);
middlemiddle.write(vmm);
delay(5);
}
while (vmm !=105);
delay(2000);

do
{
vtm++;
thumbmain.write(vtm);
delay(5);
thumbmiddle.write(vtm);
delay(5);
thumbtip.write(vtm);
delay(5);
}
while (vtm !=105);
delay(200);

do
{
vtm--;
thumbmain.write(vtm);
delay(5);
thumbmiddle.write(vtm);
delay(5);
thumbtip.write(vtm);
delay(5);
}
while (vtm !=0);
delay(200);

do
{
vmm--;
middletip.write(vmm);
delay(5);
middlemiddle.write(vmm);
delay(5);
}
while (vmm !=0);
delay(2000);
Serial.println("auto");
}
}
}

}


Fri Mar 15, 2013 11:18 am
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 576
Post Re: automatic control vs manual control servos
This looks like it is being programmed in Processing. Unfortunately we are only able to provide support for ROBOTC on these forums; you may have better luck posting the question on the Arduino forums.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Fri Mar 15, 2013 6:25 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.