PDA

View Full Version : newbie help : subsumption



jimbobjones
- 7th April 2007, 11:49
i'm new to pic basic and i'm trying to setup a simple subsumption architecture...
can anyone help with this code :

start:

go_command = command_none
stop_command = empty


if go_command <> command_none then motor_output = go_command
if stop_command <> command_none then motor_output = stop_command

select case motor_output
case stop_command
portb = %00001100
case go_command
portb = %00000011
end select

goto start



basicly i'm just trying to select the correct state based on when go/stop_command(s) are not command_none.

I can't seem to select the second case, go_command, it always just assigns 00001100 to port b :(

can anyone help

thanks

HenrikOlsson
- 7th April 2007, 14:09
Hi,
If you're using MELABS PicBasicPro then you can't have the IF statement like:


if go_command <> command_none then motor_output = go_command

You'll have to do:


if go_command <> command_none then
motor_output = go_command
Endif


HTH

/Henrik Olsson.

jimbobjones
- 7th April 2007, 14:24
thanks for the help :D i've now got it working
i have one last issue..

the code as it stands :



'manually select
Seek_output = backward '1
Evade_output = idle '2
Panic_output = idle '3
settle_output = idle '4

start:

'subsumption
'if x is not in idle mode assign the output from that layer
'if the layer is idle then move to the next..

if Seek_output <> idle then
motor_actuator = Seek_output 'state 1

elseif Evade_output <> idle then
motor_actuator = Evade_output 'state 2

elseif Panic_output <> idle then
motor_actuator = Panic_output 'state 3

elseif settle_output <> idle then
motor_actuator = settle_output 'state 4
end if

' motor case statement only selects with numbers
' need to use text for clarity

gosub motor_control

goto start

motor_control:

select case motor_actuator
case left
portb = %00000001
case right
portb = %00000010
case forward
portb = %00000011
case backward
portb = %00000100
end select
return


now the motor control case statement selects ok when i use numbers but i would much prefer to use text, can anyone help..

HenrikOlsson
- 7th April 2007, 16:07
Hi,

now the motor control case statement selects ok when i use numbers but i would much prefer to use text, can anyone help..

I'm not sure I understand that correctly but let's say that this work


motor_control:

select case motor_actuator
case 1
portb = %00000001
case 2
portb = %00000010
end select
return


Then set up some constants matching those numbers, like:


Left CON 1
Right CON2
Forward CON 4
Reverse CON 8

select case motor_actuator
case Left
portb = %00000001
case Right
portb = %00000010
'and so on.....
end select
return


Sorry if I misunderstood.
/Henrik Olsson.

jimbobjones
- 8th April 2007, 19:50
that works !

thanks for you help