|
After follow Dave's suggestion, I am successful to use RcxCC for Scout
programming, here is the method.
Edit two batch files named rcx.bat and scout.bat in rcxcc directory, the
content of files are as follows:
set NQC_OPTIONS=-TRCX
rcxcc
set NQC_OPTIONS=-TScout
rcxcc
remember to check box of "close window when exit" and select "run in min
window status" in these batch files' property. now you can use rcxcc to
create program both for RCX or Scout, just run different batch file. here is
a sample source that can be run both in RCX and Scout.
/*
* LightSeeker
* ===========
*
* Written by Zhengrong Zang
*
* The light seeker has two motors to drive the rear wheels.
* On the top there is a lightsensor using internal light sensor in Scout).
Finally, there
* is one touch sensor at the front.
*
* The behavior of the robot is as follows:
* It constantly determines the direction of the most light using the light
sensor with spinning right and left.
* Based on the direction of the light it steers the robot towards the
light.
* If the touch sensors touch something for the first time, the robot backs
up a bit.
* If they touch something again, it is assumed the goal is reached.
* This program can be used both in RCX and Scout
* Mapping:
* OUT_A: left wheel
* OUT_C: right wheel (OUT_B in Scout)
* SENSOR_1: touch sensors
* SENSON_2: light sensor (Inernal light sensor in Scout)
*/
#pragma noinit
#define OldFwd(a,b) do {OnFwd(a); SetPower(a,b);} while (false)
#define OldRev(a,b) do {OnRev(a); SetPower(a,b);} while (false)
#ifdef __SCOUT
#define Forward(s, t) OldRev(OUT_A, s); OldRev(OUT_B, s); Wait(t);
#define Backward(s, t) OldFwd(OUT_A, s); OldFwd(OUT_B, s); Wait(t);
#define RotateLeft(s, t) OldFwd(OUT_A, s); OldRev(OUT_B, s); Wait(t);
#define RotateRight(s, t) OldRev(OUT_A, s); OldFwd(OUT_B, s); Wait(t);
#define TurnLeft(s, t) OldRev(OUT_B, s); Float(OUT_A); Wait(t);
#define TurnRight(s, t) OldRev(OUT_A, s); Float(OUT_B); Wait(t);
#define PauseMotor Float(OUT_A+OUT_B);
#define StopMotor Off(OUT_A+OUT_B);
#endif
#ifdef __RCX
#define Forward(s, t) OldRev(OUT_A, s); OldRev(OUT_C, s); Wait(t);
#define Backward(s, t) OldFwd(OUT_A, s); OldFwd(OUT_C, s); Wait(t);
#define RotateLeft(s, t) OldFwd(OUT_A, s); OldRev(OUT_C, s); Wait(t);
#define RotateRight(s, t) OldRev(OUT_A, s); OldFwd(OUT_C, s); Wait(t);
#define TurnLeft(s, t) OldRev(OUT_C, s); Float(OUT_A); Wait(t);
#define TurnRight(s, t) OldRev(OUT_A, s); Float(OUT_C); Wait(t);
#define PauseMotor Float(OUT_A+OUT_C);
#define StopMotor Off(OUT_A+OUT_C);
#endif
int maxlight; // Most light found
int flag; // Flag to change rotation direction, 0 - change rotation
direction
int count; // Count numbers of rotatetion
int direction; // Direction of rotation, 0 - right, 1 - left
int touchnumb; // number of touches
task main()
// Just initialises things
{
// Set up the sensors
#ifdef __RCX
SetSensor(SENSOR_1, SENSOR_TOUCH);
SetSensor(SENSOR_3, _SENSOR_CFG(SENSOR_TYPE_LIGHT, SENSOR_MODE_RAW));
#endif
touchnumb = 0;
// Start it all
start check_light;
start check_touch;
}
task check_touch()
// Checks whether touch sensors are touched and takes action
{
while (true) {
if (SENSOR_1 == 1) {
stop check_light;
if (touchnumb > 1) {
// Stop everything else
StopMotor
PlaySound(SOUND_UP);
Wait(9);
stop check_touch;
}
else {
// backup a bit and try from there
touchnumb += 1;
Backward(7, 100);
Forward(7, 0);
start check_light;
}
}
}
}
task check_light()
// Constantly keeps track of the best light direction
{
Init();
while(true) {
if (SensorValueRaw(2) > maxlight) {
PlaySound(SOUND_CLICK);
// Rotation right
if (direction == 0) {
RotateRight(7, 10);
}
// Rotation leftt
else {
RotateLeft(7, 10);
}
flag -= 1;
// Check numbers of rotation
if (flag == 0) {
// Add numbers of rotation
count += 1;
flag = count;
// Change rotation direction
if (direction == 0) {
direction = 1;
}
else {
direction = 0;
}
}
}
else {
// Forward to light source
Init();
Forward(7, 0);
}
}
}
void Init()
{
maxlight = 500;
flag = 1;
count = 1;
direction = Random(1);
}
Dave Baum wrote:
> In article <3998A849.7008899D@yahoo.com>, Zhengrong Zang
> <legozang@yahoo.com> wrote:
>
> > Hi
> > I have a light-seeker NQC program for RCX, I want to port for Scout,
> > does anyone know how to do it? Then does Scout use external light
> > sensor?
> >
> > BR
> > Zhengrong
>
> The Scout only supports passive sensors externally (touch and
> temperature). The light sensor is supposed to be used as an active
> sensor (although in some cases you can use it passively and get
> reasonable results).
>
> The Scout does have its own built-in light sensor. It is not a
> reflective sensor (like the external RCX light sensor), but just reads
> ambient light levels which rules out some applications. Its position on
> the Scout can also make it a bit of a challenge to use effectively.
>
> Internally, the Scout preprocesses the light sensor reading into one of
> three states: dark, normal, or light (values 0, 1, and 2). You can
> programmatically change the thresholds and hysteresis used in converting
> raw values into these three levels. In many cases this is the best way
> to use the sensor since it also allows you to take advantage of the
> event monitoring capability of the Scout.
>
> Another option is to read the raw values rather than the processed
> values. This will give your program greater resolution. All of the NQC
> calls to do these things are described in the NQC 2.2 documentation (see
> http://www.enteract.com/~dbaum/nqc/beta/index.html). You may also want
> to grab the Scout SDK from www.legomindstorms.com because it contains an
> excellent document on the inner workings of the Scout.
>
> Dave
>
> --
> reply to: dbaum at enteract dot com
|
|
Message has 1 Reply:
Message is in Reply To:
| | Re: About Scout programming
|
| (...) The Scout only supports passive sensors externally (touch and temperature). The light sensor is supposed to be used as an active sensor (although in some cases you can use it passively and get reasonable results). The Scout does have its own (...) (24 years ago, 15-Aug-00, to lugnet.robotics.rcx.nqc, lugnet.robotics.scout)
|
4 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
|
|
|
|