ROBOTC.net forums
http://robotc.net/forums/

wanting someone to check my basic velocity control code
http://robotc.net/forums/viewtopic.php?f=11&t=13142
Page 1 of 1

Author:  Haywire183 [ Sat Jan 16, 2016 11:18 am ]
Post subject:  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)
}
}

Author:  CARBOT [ Sat Jan 16, 2016 3:36 pm ]
Post subject:  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.

Author:  Haywire183 [ Sat Jan 16, 2016 3:42 pm ]
Post subject:  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.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/