View unanswered posts | View active topics It is currently Fri Jul 19, 2019 9:31 pm






Reply to topic  [ 3 posts ] 
wanting someone to check my basic velocity control code 
Author Message
Rookie

Joined: Fri Jan 15, 2016 9:33 am
Posts: 2
Post wanting someone to check my basic velocity control code
Can I start by saying I know that the code is not completely accurate and will flag up a lot of syntax error, but the computer with the robotC software is in my school.
I would be grateful if someone could just look over my code meant to create a constant speed of 8m/s.

Int target =1835;
Int TicksL = 0;
Int endcoderCurrentL = 0;
Int encoderLastL = 0;
Int errorL = 0;
Int integratorL = 0;
Int powerL = 0;
Float constant = 0.05
Int endcoderCurrentR = 0;
Int encoderLastR = 0;
Int errorR = 0;
Int integratorR = 0;
Int TicksR = 0;
Int powerR = 0;

Task main ()
{
While(btn5u==1)
{
EndcoderCurrentR = sensorvalue [right_encoder]
EndcoderCurrentL = sensorvalue[left_encoder]
TicksR = endcoderCurrentR - encoderLastR
TicksL = endcoderCurrentL - encoderLastL
ErrorR = target - TicksR
ErrorL = target - TicksL
IntegratorR += (errorR × constant)
IntegratorL += (errorL × constant)
If (integratorR > 127)
{
IntegratorR = 127
}
If (integratorR  < 0)
{
IntegratorR = 0
}
If (integratorL > 127)
{
IntegratorL = 127
}
If (integratorL  < 0)
{
IntegratorL = 0
}
PowerR = integratorR
PowerL = integratorL
Motor [leftfly] = powerL
Motor [rightfly] = powerR
Wait1Msec  (20)
}
}


Sat Jan 16, 2016 11:18 am
Profile
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 151
Post Re: wanting someone to check my basic velocity control code
You may want another WHILE statement.
The program will do nothing unless btn5u is pressed.


Sat Jan 16, 2016 3:36 pm
Profile
Rookie

Joined: Fri Jan 15, 2016 9:33 am
Posts: 2
Post Re: wanting someone to check my basic velocity control code
Sorry please explain. Do you mean put the loop inside another while loop?
I think in the final program it will be an if statement within an infinite loop if that's what you mean.


Sat Jan 16, 2016 3:42 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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.