general confusion with remote control car project

Tgrima

New Member
Hi, I'm currently finishing off my AS DT project which is a remote controlled car thing. I've been learning how to use Picaxe chips as I've been building it and I realise in hindsight some things I've done had much easier solutions so I do apologise if I've made any glaringly obvious mistakes.

On the whole, the circuit and Programs I've got are working perfectly 90% of the time although sometimes I get some problems such as the 8 bytes from the transmitter chip being received in the wrong variables so the car will just endlessly accelerate or something. I think I need to use the serin qualifier thing but I can't get my head around how it works. would I set the b0 to say 87 and then make the qualifier 87 so it always starts in the same place?

I'm having another problem where if the joystick is say being pushed forward and you keep it completely still, the program stops accelerating even though the joystick is still being pushed forward and it hasn't reached the value of the acceleration. This isn't too much of a problem because I just move the joystick very slightly the left and right whilst its accelerating and it works fine then.

I think this is a problem with my wiring but the car sometimes behaves strangely if I turn the indicators on and off. Like there are 1-4 second delays when the car doesn't receive anything from the controller. Or sometimes if I turn on the indicator switch on the remote the car doesn't turn them on at all.

Any help would be massively appreciated or if there are any other suggestions for the programs I won't be able to thank you enough!
Sorry if there are any details I haven't included that I need to, I'm still quite new to all of this.

Thanks,
Theo

40X2 Car
Code:
symbol steering = b1
symbol acceleration = b4
symbol light = b6
symbol duty = b29

initialise:
    pause 1000
    output B.4
    output A.3
    low b.4
    low A.3
    setfreq em32
    let duty = 128
    HPWM PWMDIV4, 0, 0, %0100, 32, 0
    pause 4000
    goto main
main:
    do
        high C.4
        serin [6000,disconnected], C.7, n2400, b0,b1,b2,b3,b4,b5,b6,b7
        low C.4
      let b8 = light
        let b8 = light & 4
        if b8 > 0 then 'headlights on
            'high B.7 '
        else
            'low B.7 'Headlights off
        endif
        let b8 = light & 2
        if b8 > 0 then ' left indicator on
            high C.3
        else
            low C.3
        endif
        let b8 = light & 1
        if b8 > 0 then ' right indicator on
            high D.0
        else   
            low D.0
        endif     
        
      if b3 = 1 then
          goto disconnected
      endif
 
      if steering < 75 then
          high A.3
      else
          low a.3
      endif 
        if steering > 180 then
          high B.4
      else
          low b.4         
      endif
      let acceleration = b4
        if acceleration > 140 then 'if joystick forward
        if acceleration > duty then
                duty = duty + 4 MAX acceleration
        endif
      elseif acceleration < 115 then
        if acceleration < duty then
                duty = duty - 4 MIN acceleration
        endif
        endif
        if duty > 127 then 'moving forward
            low D.5
            high D.4 'Motor Forward
            let acceleration = duty - 128
        else 'reversing
            low D.4
            high D.5 'Reverse Motor
            let acceleration = 128 - duty
      endif
      hpwmduty acceleration 'Speed of motor
    loop


disconnected:
    hpwmduty 0
    low B.4, A.3
    low D.0, C.3
    pause 2000
    do until b7 = 1
        high D.0, C.3
        pause 400
        low D.0, C.3
    loop
    do until b7 = 0
        low high D.0, C.3
    loop
    goto initialise
08M2 Steering chip
Code:
initialise:
    input C.4 'Left
    input C.3 'Right
    let b1 = 130
    symbol duty = b1
start:
    do
          if PinC.4 = 1 then
                   duty = duty + 2 MAX 220
        endif
        if PinC.3 = 1 then
                duty = duty - 2 MIN 60
        endif
        pause 10
        servo C.2, duty
    loop
08M2 Lights Chip
Code:
initialise:
    setfreq m32
    input C.3
    Input C.2
main:
    do
        low C.1, C.4
        pause 3500
        if pinC.2 = 1 then
            high C.1
        endif
        if pinC.3 = 1 then
            high C.4
        endif
        pause 3500
    loop
20M2 Controller
Code:
symbol light = b6
initialise:
    setfreq m32
main:
    let b7 = 0
    let b3 = 0
    let light = 0
    if Pinc.5 = 1 then
        let light = light + 1 'left indicator
    Endif
    if Pinc.6 = 1 then
        let light = light + 2 'right indicator
    Endif
    if Pinc.7 = 1 then
        let light = light + 4 'headlights
    Endif
    if PinC.3 = 1 then
        let b3 = b3 + 1
    Endif   
    if PinC.4 = 1 then
        let b7 = b7 + 1
    Endif
    readadc C.1, b1 'acceleration
    readadc C.2, b4 'acceleration
    rfout c.0, (b0,b1,b2,b3,b4,b5,b6,b7)
    goto main

'b1 steering
'b3 stop
'b4 acceleration
'b6 lights
'b7 reset
 

hippy

Technical Support
Staff member
When sending with RFOUT, the corresponding SERIN, presumably from an NKM2401 chip, does not need a qualifier, but you could perhaps add a qualifier within the RFOUT packet and even add a checksum. That way you can check that what is received matches what is sent, for example, if your data is in b1 to b6, to send that b1 to b6 ...
Code:
b0 = $A3
b7 = b0 + b1 + b2 + b3 + b4 + b5 + b6
rfout c.0, (b0,b1,b2,b3,b4,b5,b6,b7)
Then, when you come to receive it you can check that the data is valid and does match before doing something with it ...
Rich (BB code):
serin [6000,disconnected], C.7, n2400, b0,b1,b2,b3,b4,b5,b6,b7
if b0 = $A3 Then
  b0 = b0 + b1 + b2 + b3 + b4 + b5 + b6
  If b0 = b7 Then
    ... packet valid, use b1 to b6 here ... 
  end if
end if
 

Tgrima

New Member
Ah thankyou a lot for your reply, that makes a lot of sense! if the data didn't match up would I then simply receive it again until it does match up? Whenever this has happened its often when I first power up the controller and the car, I was wondering whether it would make a difference which one is powered first.
 

hippy

Technical Support
Staff member
Looking at the code, I am not sure what effects having your SETFREQ M32 / EM32 will be having. It might be worthwhile taking a step back, making sure you have a firm foundation to work on. Your code looks okay but could be improved and simplified.

The 20M2 Controller ...
Code:
#picaxe 20m2
#no_data

initialise:
    ; nothing

main:
  b1 = pinsC ' indicators, lights, whatever
  readadc C.1, b2 'acceleration
  readadc C.2, b3 'acceleration
  b0 = $A3
  b7 = b0 + b1 + b2 + b3 + b4 + b5 + b6
  rfout c.0, (b0,b1,b2,b3,b4,b5,b6,b7)
  pause 1000
  goto main
Then you can use your 40X2 Car to monitor and report what is received, can check that it is responding to the button pushes and pot movements you are making -
Code:
#Picaxe 40x2
#terminal 9600
#no_data
#no_table

initialise:
  pause 2000
  sertxd( "Started", cr, lf )

main:
  sertxd( "Waiting for packet", cr, lf )
  serin [6000,disconnected], C.7, n2400, b0,b1,b2,b3,b4,b5,b6,b7
  if b0 <> $A3 then
    sertxd( "Bad packet", cr, lf )
  else
    b0 = b0 + b1 + b2 + b3 + b4 + b5 + b6
    if b0 <> b7 then
      sertxd( "Incorrect checksum", cr, lf )
    else
      sertxd( "Valid packet", cr, lf )
      b0 = b1 ; so we can use bit0 to bit7
      sertxd("  C.5 Left indicator  = ", #bit5 , cr, lf)
      sertxd("  C.6 Right indicator = ", #bit6 , cr, lf)
      sertxd("  C.7 Headlights      = ", #bit7 , cr, lf)
      sertxd("  C.3 ?               = ", #bit3 , cr, lf)
      sertxd("  C.4 ?               = ", #bit4 , cr, lf)
      sertxd("  C.1 Acceleration    = ", #b2   , cr, lf)
      sertxd("  C.2 Acceleration    = ", #b3   , cr, lf)
      sertxd( cr, lf )
    end if
  end if
  goto main

disconnected:
  sertxd( "Disconnected", cr, lf )
  goto main
Once you have that working well you can then add the 'doing things' to your car to have it do what you want. Add a bit at a time and check that works, then on to the next bit. If things do stop working or working reliably you can then back-up to something you had working, more easily figure out what might be going wrong.
 

Tgrima

New Member
Thats extremely helpful, thankyou! Sorry it took me a while to reply, things have been a bit chaotic recently. I didn't really understand the whole frequency thing and I think when I did it I was just thinking faster = better so why not, I didn't realise it wasn't doing anything :p. Is it normal for there to be a noticeable delay (0.5-1second) when using rf to send signals?
 

hippy

Technical Support
Staff member
Is it normal for there to be a noticeable delay (0.5-1second) when using rf to send signals?
Not normally but, if using the suggested code above, there is a PAUSE 1000 in there intended to slow things down which can be reduced and perhaps even removed.
 
Top