Subject:
|
Re: balancing bot
|
Newsgroups:
|
lugnet.robotics
|
Date:
|
Thu, 30 Dec 2004 18:55:27 GMT
|
Viewed:
|
1065 times
|
| |
| |
>
> You may have a look to YAL: http://news.lugnet.com/robotics/?n=22181
...and here is a NQC sample code that works on YAL, using Dick Swan's fast
firmware.
Try it on a clear color surface (not necessarily even, some patterns help
stabilize position) with overhead diffuse lighting. YAL must be started balanced
(sensor calibration).
Philo
-----------------------------------------------
#include "swan.nqh"
#define Front_S SENSOR_1
#define Rear_S SENSOR_3
#define Right_M OUT_A
#define Right_Pwr 0
#define Left_M OUT_C
#define Left_Pwr 2
#define a 15
#define b 5
#define c 5
int Offset;
int OldDif;
int NewDif, MotCmd, OldMotCmd, MotPwr;
int DispDbg;
task main ()
{
SetUserDisplay (DispDbg,0);
SetSensor (Front_S, SENSOR_LIGHT);
SetSensor (Rear_S, SENSOR_LIGHT);
SetSensorMode (Front_S, SENSOR_MODE_RAW);
SetSensorMode (Rear_S, SENSOR_MODE_RAW);
bFloatDuringInactiveMotorPWM = false;
nMotorTransitionDelay = 0;
Wait(10);
Offset = Front_S - Rear_S;
OldDif = 0;
motorPower128(Right_Pwr) = 0;
motorPower128(Left_Pwr) = 0;
OnFwd (Right_M + Left_M);
OldMotCmd = 1;
while (true)
{
NewDif = Front_S - Rear_S - Offset;
MotCmd = (a * NewDif + b * (NewDif - OldDif)) / c;
OldDif = NewDif;
DispDbg=MotCmd;
MotPwr = (MotCmd > 0) ? MotCmd : -MotCmd;
if(MotPwr > 127) MotPwr = 127;
motorPower128(Right_Pwr) = MotPwr;
motorPower128(Left_Pwr) = MotPwr;
if(MotCmd > 0) OnFwd (Right_M + Left_M);
else OnRev (Right_M + Left_M);
}
}
--------------------------------------------------
|
|
Message has 2 Replies: | | Re: balancing bot
|
| this looks similar to the logic I got working. I tweaked the parameters (equiv. to a,b,c in your code) and it's much more stable now. Interestingly, I have to set 'b' very high, about 2X of what 'a' is set to -- most code I've seen is just the (...) (20 years ago, 31-Dec-04, to lugnet.robotics)
| | | Re: balancing bot
|
| I recently implemented a new motor control "source" specifically targeted at PID algorithms in the new firmware. It takes a signed number in the range -128 to +128 and converts it into a motor control command. -128 to -1 is reverse direction and (...) (20 years ago, 31-Dec-04, to lugnet.robotics)
|
Message is in Reply To:
8 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|