S2 code? if s2.get_adc_results(s2#ADC_IMOT) > 210
Hi all,
We've got an S2 that is blinking red for all three LED's and we're trying to figure out the above code we can know what's wrong.
Can anyone tell us what ADC_IMOT measures and what we should do next? This is happening on a S2 that we've had less than a year.
Thanks!
Bob Irving
Porter-Gaud School
Charleston, SC
We've got an S2 that is blinking red for all three LED's and we're trying to figure out the above code we can know what's wrong.
Can anyone tell us what ADC_IMOT measures and what we should do next? This is happening on a S2 that we've had less than a year.
Thanks!
Bob Irving
Porter-Gaud School
Charleston, SC
Comments
Anybody?
Bob Irving
Porter-Gaud School
Charleston, SC
Could you include the full code? There might be a bug somewhere else.
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
'_CLKFREQ = 5_000_000
LINE_THLD = 50
OBSTACLE_CHECK = TRUE
SPKR_VOL = 35
BAR_THLD = 32
VAR
long LeftMotor, RightMotor, MoveTime, pLeftMotor, pRightMotor, pMoveTime, FMStack[50]
word WheelSpace, FullCircle
byte Self , LineThld , ResetCount, LineCount , LeftLine, RightLine, Line_Reader
OBJ
s2 : "S2"
'---[Start of Program]
PUB Main
\setUpRobot
\moveTheRobot
' this is the end of the main code
PRI moveTheRobot
MoveWheels(128, 128, 3000)
s2.delay_tenths(10) ' this pauses 1/10 of a second
MoveWheels(-100, -255, 5000)
s2.delay_tenths(30)
MoveWheels(0, 0, 100)
' Students try to make a square
PRI exploreRobots
PRI playMusicaAndMakeSound
'PlayNote(duration, freq1, freq2) both can go up to 255
PlayNote(187, 391, 0)
PlayNote(187, 523, 0)
PlayNote(187, 659, 0)
PlayNote(187, 783, 0)
PlayNote(187, 0, 0)
PlayNote(187, 659, 0)
PlayNote(1125, 783, 0)
PlayNote(152, 783, 0)
PlayNote(35, 0, 0)
PlayNote(187, 783, 0)
PlayNote(187, 659, 0)
PlayNote(187, 880, 0)
PlayNote(375, 783, 0)
PlayNote(375, 659, 0)
PRI objectDetection
s2.set_leds(S2#RED,S2#OFF,S2#OFF,S2#OFF)
repeat
if (s2.obstacle(s2#LEFT, 0) == true )
s2.set_leds(S2#RED,S2#OFF,S2#OFF,S2#OFF)
PRI LEDlights ' YELLOW, GREEN, BLUE, ORANGE, RED, ALT_RED_GREEN, BLINK_RED, BLINK_BLUE
s2.set_led(s2#LEFT, s2#ORANGE) 'Set left light LED to ORANGE.
s2.delay_tenths(30)
s2.set_led(s2#CENTER, s2#GREEN) 'Set center LED to ORANGE.
s2.delay_tenths(30)
s2.set_led(s2#RIGHT, s2#ALT_RED_GREEN) 'Set RIGHT light LED to BLINK RED & GREEN.
s2.delay_tenths(30)
s2.set_led(s2#LEFT, s2#BLINK_RED)
s2.delay_tenths(30)
s2.set_led(s2#LEFT, s2#BLINK_GREEN)
'OR all at once
s2.set_leds(S2#GREEN,S2#YELLOW,S2#GREEN,S2#BLUE) 'set left=green, center=yellow, right=green, and power=blue
s2.delay_tenths(30)
s2.set_leds(S2#GREEN,S2#NO_CHANGE,S2#GREEN,S2#OFF) 'set left=green, center=yellow, right=green, and power=blue
'OR Crazy people only
's2.set_leds(s2#BLINK_RED,s2#BLINK_RED,s2#BLINK_RED,s2#OFF)
PRI lightDetection
s2.set_led(s2#POWER, s2#BLINK_BLUE)
repeat
if (s2.light_sensor_raw(s2#CENTER) > 230)
s2.set_led(s2#LEFT, s2#BLINK_RED) 'Set center LED to RED.
if (s2.light_sensor_raw(s2#CENTER) > 150 )
s2.set_led(s2#CENTER, s2#RED) 'Set center LED to RED.
if ( s2.light_sensor_raw(s2#CENTER) < 50)
s2.set_led(s2#RIGHT, s2#RED) 'Set center LED to OFF .
PRI MoveWheels(lmotor, rmotor, timer)
MoveTime := timer #> 0
LeftMotor := lmotor #> -256 <# 256
RightMotor := rmotor #> -256 <# 256
if (LeftMotor <> pLeftMotor or RightMotor <> pRightMotor or MoveTime <> pMoveTime or pMoveTime <> 0)
if (MoveTime)
s2.move_now(LeftMotor * MoveTime * FullCircle / 1_024_000, RightMotor * MoveTime * FullCircle / 1_024_000, MoveTime << 1, (||LeftMotor #> ||RightMotor <# 255) >> 4, 0)
s2.wait_stop
else
s2.wheels_now(LeftMotor, RightMotor, 0)
waitcnt(cnt + clkfreq / 10)
pLeftMotor := LeftMotor
pRightMotor := RightMotor
pMoveTime := MoveTime
PRI PlayNote(duration, freq1, freq2)
s2.play_tone(duration - 1 #> 1, freq1, freq2)
s2.play_tone(1, 0, 0)
PRI batteryCheck
Self := cogid
cognew(FaultMonitor, @FMStack)
PRI FaultMonitor : value
value := $ffff
waitcnt(cnt + 80_000_000)
repeat
value <#= s2.get_adc_results(s2#ADC_VBAT)
if value > constant((700*2550)/(400*33)) '7.0V
s2.set_led(s2#POWER,s2#BLUE)
elseif value > constant((600*2550)/(400*33)) '6.0V
s2.set_led(s2#POWER,$20)
else
s2.set_led(s2#POWER,s2#BLINK_BLUE)
if s2.get_adc_results(s2#ADC_IMOT) > 210
cogstop(Self)
s2.stop_now
s2.set_leds(s2#BLINK_RED,s2#BLINK_RED,s2#BLINK_RED,s2#OFF)
repeat
PRI ReadBars | w0, w1, barcount, midwidth, t
LineCount := 0
if (s2.line_sensor(s2#LEFT, BAR_THLD) or s2.line_sensor(s2#RIGHT, BAR_THLD))
return
t := cnt
repeat until s2.line_sensor(s2#RIGHT, BAR_THLD)
if (cnt - t > 80_000_000)
return
ifnot (w1 := ReadBarWidth)
return
ifnot (w0 := ReadBarWidth)
return
midwidth := (w0 + w1) >> 1
repeat barcount from 1 to 5
if (barcount =< 4)
LineCount <<= 1
if (w0 > midwidth)
Linecount |= 1
ifnot (w0 := ReadBarWidth)
LineCount := 0
return
if (LineCount & %1000)
LineCount := (Linecount >< 3) | %1000
'---[Read the Width of One Dark Bar Code Bar]
PRI ReadBarWidth | t
t := cnt
repeat while s2.line_sensor(s2#RIGHT, BAR_THLD)
if ((cnt - t) > 80_000_000)
return 0
t := cnt
repeat until s2.line_sensor(s2#RIGHT, BAR_THLD)
if ((cnt - t) > 80_000_000)
return 0
return cnt - t
PRI CheckLine | left, right
left := 1 + s2.line_sensor(s2#LEFT, LineThld)
right := 1 + s2.line_sensor(s2#RIGHT, LineThld)
if (left == LeftLine and right == RightLine)
LineCount := (LineCount + 1) <# 8
else
LineCount := 1
LeftLine := left
RightLine := right
PRI setUpRobot
s2.start
s2.start_motors
s2.start_tones
s2.set_volume(SPKR_VOL)
s2.set_voices(s2#SAW, s2#SAW)
long[@WheelSpace] := s2.get_wheel_calibration
S2.set_led(s2#POWER, s2#BLUE)
if (s2.get_line_threshold <> s2#DEFAULT_LINE_THLD)
LineThld := s2.get_line_threshold
else
LineThld := LINE_THLD
Self := cogid
cognew(FaultMonitor, @FMStack)
'---[Main Program: Green]
I have no idea what that does... is it detecting a fault in the motors?
Seems to point to a motor current fault of some kind... 210 must be the maximum allowed current value that Parallax estimated would keep the S2 healthy.
dgately
Does that mean that there is something irreparably wrong with the motor? We're just wondering if we need to replace these, but not knowing exactly what it's measuring and what that means makes it difficult to do that.
Bob Irving
Looks like you are into the Spin code. It's better to use the Spin Tool "File>Archive" to upload the program as an attachment. The indentation gets lost in the forum software.
If I can get an archive I will test the code.
You're in excellent hands with Jim (Publison).
I've attached the archived file. Thanks!
Bob
What to check always first, new fully charged batteries.
Second, debris hanging up in the wheel/servo area causing binding.
I would run the Calibration program from the S2 GUI, if that doesn't work, restore the Factory program from the GUI and test all the demo modes.
Standing by.
I've never taken one of these apart, so I'll try that next.
Then calibration and factory reset....
Also, how do you implement the calibration program? It says it hasn't been implemented?
Sorry. Parallax never did the calibration program for the S2. I was thinking of the ActivityBot.
Do a Factory Reset and test all the demos to see if those run correctly.