Subject:
|
Re: NBC with NXT - crash!
|
Newsgroups:
|
lugnet.robotics.nxt
|
Date:
|
Sat, 21 Oct 2006 20:08:12 GMT
|
Viewed:
|
12264 times
|
| |
| |
In lugnet.robotics.nxt, Ross Crawford wrote:
> Hi, I wrote the following program, and it causes my NXT to crash!
Running this program on my NXT does not cause mine to crash. Are you definitely
running the 1.03 firmware? You can see the version using Settings|NXT Version
on the NXT or from the Diagnostic window in BricxCC. My brick shows
01.1240/01.03 in the Diagnostic window. My NXT is a beta so perhaps it behaves
differently from a retail NXT.
Unfortunately, there isn't any built-in mechanism in the standard NXT firmware
to start and stop threads like you can in the standard RCX firmware (and in the
proprietary Robolab 2.9/RobotC alternate firmware). And there isn't any
mechanism for acquiring resources such as motors for exclusive access. So in
both NXT-G and NBC it is possible to write programs which have concurrent
threads which try to control motors simultaneously. The result could be
catastrophic, depending on how the virtual machine in the standard firmware
handles such things. But on my NXT, at least, there isn't a crash but the
motors do not operate as you might hope they would.
The way to handle this in NBC is to use a global variable as a semaphore to
protect access to the motors. Like this:
#include "NXTDefs.h"
#define MOVE_TIME 800
#define TURN_TIME 200
#define ReadSensor(port,value) mov value, InputIOScaledValue(port)
dseg segment
m1 mutex
value sword 0
buf byte[]
motor_semaphore byte
dseg ends
thread main
precedes move_square, check_sensors
SetSensorTouch(IN_1)
exit
endt
thread move_square
SquareLoop:
brtst NEQ, SquareLoop, motor_semaphore
OnFwd(OUT_BC,100)
wait MOVE_TIME
OnRev(OUT_C,100)
wait TURN_TIME
jmp SquareLoop
endt
thread check_sensors
SensorLoop:
set motor_semaphore, FALSE
ReadSensor(IN_1,value)
//numtostr buf,Switch
//TextOut(0,0,1,buf,10)
brtst EQ, SensorLoop, value
set motor_semaphore, TRUE
OnRev(OUT_BC,100)
wait 50
Off(OUT_C)
wait 85
OnFwd(OUT_C,100)
jmp SensorLoop
endt
Another thing to remember with respect to NBC vs NQC is that wait times in NBC
are in milliseconds while in NQC they are in centiseconds. So a wait time of
200 in NQC means 2 seconds but in NBC it means 0.2 seconds.
John Hansen
|
|
Message has 1 Reply: | | Re: NBC with NXT - crash!
|
| (...) Settings shows FW 1.03, AVR 1.01, BC4 1.01, Build 2803060845 Diags window shows 01.1240/01.03 (...) Thanks John, but as you may have suspected, this program was going to be an example of how to use mutex variables in the NBC tutorial - this (...) (18 years ago, 21-Oct-06, to lugnet.robotics.nxt)
|
Message is in Reply To:
| | NBC with NXT - crash!
|
| Hi, I wrote the following program, and it causes my NXT to crash! If I remove the ReadSensor() call from thread check_sensors, it doesn't crash. If I put a call to ReadSensor() in thread main, it doesn't crash. I tried putting mutexes around all the (...) (18 years ago, 21-Oct-06, to lugnet.robotics.nxt)
|
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
|
|
|
|