Problem understanding NBC
Posted: 29 Dec 2010, 16:18
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 -----------------------------------------
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 -----------------------------------------