Problem understanding NBC

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
aagruntpuddock
Posts: 33
Joined: 14 Dec 2010, 13:09
Location: Scotland
Contact:

Problem understanding NBC

Post by aagruntpuddock »

Trying to re-do an existing NXT-G program in NBC through Bricx Command Center as a way of learning the language but not having a lot of success!

I need to measure the rotation of the NXT motor in port A, it can be turning in either direction. I don't want to get involved in working out whether the motor has swung past the zero point between the first and final measurements so thought I would set it to zero before starting.

Trying to do it by setting the sensor type or mode but just can't understand any of the guides on this subject and keep getting different compile errors.

Not even sure if I have to zero it or whether it would automatically give me just the difference.

Any comments/ assistance would be gratefully appreciated!




subroutine get_h_move ; Measure how far the head has to turn between shots

ClearScreen()
TextOut (0,4,"SET RIGHT EDGE")
TextOut (0,6,"HIT LEFT BUTTON")
PlayFile ('!Attention.rso')
Wait(2000)

call SetSensorType(OUT_A,IN_TYPE_ROTATION)
call SetSensorMode(OUT_A,SENSOR_MODE_RAW) ; IN_MODE_RAW ???

getout rotation_start_A, OUT_A, RotationCount ; Initial reading Port A

; BUT WHAT IF IT IS NOT ZERO ?????

nopress_2: ; Jump back to here if button not pressed for first edge

call get_left_button ; Left button pressed?
brcmp NEQ nopress_2, left_pressed, b_true ; Button not pressed, go back
wait (2000)

ClearScreen()
TextOut (0,4,"SET LEFT EDGE")
TextOut (0,6,"HIT RIGHT BUTTON")
PlayFile ('!Attention.rso')
Wait(2000)

nopress_3: ; Jump back to here if button not pressed for second edge

call get_right_button ; Right button pressed?
brcmp NEQ nopress_3, right_pressed, b_true ; Button not pressed, go back
wait (2000)

getout rotation_end_A, OUT_A, RotationCount ; Final reading Port A

sub h_fov, rotation_start_A, rotation_end_A

; NOW GET THE ABS VALUE & TAKE ACCOUNT OF 'PAST 360'

mul h_move, h_fov, h_overlap ; Amount head has to turn between shots

return

ends ; End of subroutine get_h_move -----------------------------------------
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Problem understanding NBC

Post by HaWe »

does it really have to be NBC?
If yes - I can't help unfortunately.
but if no: NXC (also supported by Bricxcc) is much easier to learn, it mimicris the C language (in some respects ;) )
aagruntpuddock
Posts: 33
Joined: 14 Dec 2010, 13:09
Location: Scotland
Contact:

Re: Problem understanding NBC

Post by aagruntpuddock »

Thanks, but as a lazy b'd I objected to typing in all these stupid semicolons!

Had a look through the manual for the other program and it did not shed any light on the subject anyway. At least, not to someone who has never done any low-level programming since converting a disassembler from basic to assembly language for my Oric Atmos!

As a Scot, I grudge spending £20 or more on a book from Amazon when I can't be sure it will give me the answers anyway.

I have been trawling the 'net and even looked through a couple of published programs but to no avail.

I might just have to leave that bit of code out for the moment and run a few tests to see if it is necessary.
aagruntpuddock
Posts: 33
Joined: 14 Dec 2010, 13:09
Location: Scotland
Contact:

Re: Problem understanding NBC

Post by aagruntpuddock »

Think I've found it in a NQC program from Mindsensors.

Just used the same statement and the compiler has accepted it!
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 1 guest