bonjour
je débute avec picaxe .
mon robot mr général ne réagit pas comme il faut .
voici mon programme , pourriez vous me dire si quelque chose ne va pas .
merci d avance .
première partie initialisation
#picaxe 28X1
#no_data
#no_table
' .---------------------------------------------------------------------------.
' | Define constants |
' `---------------------------------------------------------------------------'
symbol LRscalefactor = 10 'Left/Right scale factor used to control pan servo speed
symbol UDscalefactor = 14 'Up/Down scale factor used to control tilt servo speed
symbol distancemax = 200 'object must be withing this distance to track
symbol bestdistance = 550 'robot tries to maintain this distance when tracking
symbol neckLRcenter = 130 'servo center position
symbol neckUDcenter = 160 'servo center position
symbol leftmotorstop = 146 'servo center position
symbol rightmotorstop = 142 'servo center position
symbol LRmax = neckLRcenter+50 'maximum pan value
symbol LRmin = neckLRcenter-50 'minimum pan value
symbol UDmax = neckUDcenter+90 'maximum tilt value
symbol UDmin = neckUDcenter-60 'minimum tilt value
' .---------------------------------------------------------------------------.
' | Define Input and Output Pins |
' `---------------------------------------------------------------------------'
symbol IRleft = 1 'analog input
symbol IRright = 3 'analog input
symbol IRup = 2 'analog input
symbol IRdown = 0 'analog input
symbol leftmotor = 0 'servo output
symbol rightmotor = 1 'servo output
symbol neckupdown = 2 'servo output
symbol neckleftright = 3 'servo output
symbol IRleds = 4 'digital output
symbol Speaker = 5 'Audio output
' .---------------------------------------------------------------------------.
' | Define Variables Used |
' `---------------------------------------------------------------------------'
symbol time = b0 'program loop counter used to measure time / boredom
symbol boredom = b1 'boredom counter for personality
symbol pan = b2 'neck LR position
symbol tilt = b3 'neck UD position
symbol panscale = b4 'scale factor for pan calculations
symbol tiltscale = b5 'scale factor for tilt calculations
symbol leftspeed = b6 'stores value for left motor speed/direction
symbol rightspeed = b7 'stores value for right motor speed/direction
symbol lightchaser = b8 'value represents which LEDs are lit
symbol edge = b9 'input being tested for edge detection
symbol edgesensors = b10 'data from all edge detection sensors
symbol distance = w6 'b12:b13 average of analog IR inputs
symbol temp = w7 'b14:b15 temporary value used in calculations
symbol updown = w8 'b16:b17 scaled diferential value of up and down sensors
symbol leftright = w9 'b18:b19 scaled diferential value of left and right sensors
symbol leftIRvalue = w10 'b20:b21 raw data from left IR sensor
symbol rightIRvalue = w11 'b22:b23 raw data from right IR sensor
symbol upIRvalue = w12 'b24:b25 raw data from upper IR sensor
symbol downIRvalue = w13 'b26:b27 raw data from lower IR sensor
Initialise:
{
' .---------------------------------------------------------------------------.
' | Initialise program |
' `---------------------------------------------------------------------------'
setfreq em16 'set clock speed to external 16MHz resonator
dirsc=%00001111 'configure port C
pan=neckLRcenter 'set neck left/right to center
tilt=neckUDcenter 'set neck up/down to center
panscale=15 'scale factor to prevent servo overcorrection
tiltscale=15 'scale factor to prevent servo overcorrection
servo neckleftright,neckLRcenter 'initialise servo output
servo neckupdown,neckUDcenter 'initialise servo output
leftspeed=leftmotorstop 'set left motor to stop
rightspeed=rightmotorstop 'set right motor to stop
servo leftmotor,leftspeed 'initialise servo output
servo rightmotor,rightspeed 'initialise servo output
pause 4000 'wait 1 second
play speaker,3 'plays "happy birthday" to test speaker
}
je débute avec picaxe .
mon robot mr général ne réagit pas comme il faut .
voici mon programme , pourriez vous me dire si quelque chose ne va pas .
merci d avance .
première partie initialisation
#picaxe 28X1
#no_data
#no_table
' .---------------------------------------------------------------------------.
' | Define constants |
' `---------------------------------------------------------------------------'
symbol LRscalefactor = 10 'Left/Right scale factor used to control pan servo speed
symbol UDscalefactor = 14 'Up/Down scale factor used to control tilt servo speed
symbol distancemax = 200 'object must be withing this distance to track
symbol bestdistance = 550 'robot tries to maintain this distance when tracking
symbol neckLRcenter = 130 'servo center position
symbol neckUDcenter = 160 'servo center position
symbol leftmotorstop = 146 'servo center position
symbol rightmotorstop = 142 'servo center position
symbol LRmax = neckLRcenter+50 'maximum pan value
symbol LRmin = neckLRcenter-50 'minimum pan value
symbol UDmax = neckUDcenter+90 'maximum tilt value
symbol UDmin = neckUDcenter-60 'minimum tilt value
' .---------------------------------------------------------------------------.
' | Define Input and Output Pins |
' `---------------------------------------------------------------------------'
symbol IRleft = 1 'analog input
symbol IRright = 3 'analog input
symbol IRup = 2 'analog input
symbol IRdown = 0 'analog input
symbol leftmotor = 0 'servo output
symbol rightmotor = 1 'servo output
symbol neckupdown = 2 'servo output
symbol neckleftright = 3 'servo output
symbol IRleds = 4 'digital output
symbol Speaker = 5 'Audio output
' .---------------------------------------------------------------------------.
' | Define Variables Used |
' `---------------------------------------------------------------------------'
symbol time = b0 'program loop counter used to measure time / boredom
symbol boredom = b1 'boredom counter for personality
symbol pan = b2 'neck LR position
symbol tilt = b3 'neck UD position
symbol panscale = b4 'scale factor for pan calculations
symbol tiltscale = b5 'scale factor for tilt calculations
symbol leftspeed = b6 'stores value for left motor speed/direction
symbol rightspeed = b7 'stores value for right motor speed/direction
symbol lightchaser = b8 'value represents which LEDs are lit
symbol edge = b9 'input being tested for edge detection
symbol edgesensors = b10 'data from all edge detection sensors
symbol distance = w6 'b12:b13 average of analog IR inputs
symbol temp = w7 'b14:b15 temporary value used in calculations
symbol updown = w8 'b16:b17 scaled diferential value of up and down sensors
symbol leftright = w9 'b18:b19 scaled diferential value of left and right sensors
symbol leftIRvalue = w10 'b20:b21 raw data from left IR sensor
symbol rightIRvalue = w11 'b22:b23 raw data from right IR sensor
symbol upIRvalue = w12 'b24:b25 raw data from upper IR sensor
symbol downIRvalue = w13 'b26:b27 raw data from lower IR sensor
Initialise:
{
' .---------------------------------------------------------------------------.
' | Initialise program |
' `---------------------------------------------------------------------------'
setfreq em16 'set clock speed to external 16MHz resonator
dirsc=%00001111 'configure port C
pan=neckLRcenter 'set neck left/right to center
tilt=neckUDcenter 'set neck up/down to center
panscale=15 'scale factor to prevent servo overcorrection
tiltscale=15 'scale factor to prevent servo overcorrection
servo neckleftright,neckLRcenter 'initialise servo output
servo neckupdown,neckUDcenter 'initialise servo output
leftspeed=leftmotorstop 'set left motor to stop
rightspeed=rightmotorstop 'set right motor to stop
servo leftmotor,leftspeed 'initialise servo output
servo rightmotor,rightspeed 'initialise servo output
pause 4000 'wait 1 second
play speaker,3 'plays "happy birthday" to test speaker
}