From f27e0079da1a6ad7c1491e754ce200f98aa08259 Mon Sep 17 00:00:00 2001 From: Fisch Date: Wed, 1 Mar 2023 00:31:46 +0100 Subject: [PATCH] use ads115 i2c 4ch ADC for throttle and brake --- Bobbycar_wiring/Bobbycar_wiring.kicad_sch | 198 +++++++++++----------- controller_teensy/platformio.ini | 5 +- controller_teensy/src/main.cpp | 171 ++++++++++++++++--- 3 files changed, 245 insertions(+), 129 deletions(-) diff --git a/Bobbycar_wiring/Bobbycar_wiring.kicad_sch b/Bobbycar_wiring/Bobbycar_wiring.kicad_sch index 8e1f0f0..300d6d2 100644 --- a/Bobbycar_wiring/Bobbycar_wiring.kicad_sch +++ b/Bobbycar_wiring/Bobbycar_wiring.kicad_sch @@ -1632,27 +1632,27 @@ (junction (at 90.17 34.29) (diameter 0) (color 0 0 0 0) (uuid 123968c6-74e7-4754-8c36-08ea08e42555) ) + (junction (at 135.89 158.75) (diameter 0) (color 0 0 0 0) + (uuid 1da8d6a9-fe3b-409f-b8fb-c383a8f14c75) + ) (junction (at 111.76 92.71) (diameter 0) (color 0 0 0 0) (uuid 28904c58-13e1-4674-8bd4-90199e115ee4) ) - (junction (at 130.81 158.75) (diameter 0) (color 0 0 0 0) - (uuid 32979be0-ddcd-4bcc-bdc3-c2d538dd3917) - ) (junction (at 125.73 137.16) (diameter 0) (color 0 0 0 0) (uuid 37e4953b-90f4-4631-b72e-3d8d5b6ad5a4) ) (junction (at 185.42 152.4) (diameter 0) (color 0 0 0 0) (uuid 38f3170a-b54c-4011-af49-381b27b9e9bb) ) + (junction (at 138.43 158.75) (diameter 0) (color 0 0 0 0) + (uuid 3b874771-539e-4f70-97f3-d863f151cc5f) + ) (junction (at 133.35 170.18) (diameter 0) (color 0 0 0 0) (uuid 4c0db086-98b8-45db-ae33-e2ec36947136) ) (junction (at 125.73 90.17) (diameter 0) (color 0 0 0 0) (uuid 6720f220-33c9-45e2-b40a-e33dd15b6570) ) - (junction (at 133.35 158.75) (diameter 0) (color 0 0 0 0) - (uuid 6c991af1-2b26-4d8b-b43c-bcd5bb3794b3) - ) (junction (at 74.93 48.26) (diameter 0) (color 0 0 0 0) (uuid 79451892-db6b-4999-916d-6392174ee493) ) @@ -1777,10 +1777,6 @@ (stroke (width 0) (type default) (color 0 0 0 0)) (uuid 18f1018d-5857-4c32-a072-f3de80352f74) ) - (wire (pts (xy 265.43 135.89) (xy 266.7 135.89)) - (stroke (width 0) (type default) (color 0 0 0 0)) - (uuid 18f11ed8-b9a6-4be1-a669-a98351531627) - ) (wire (pts (xy 177.8 82.55) (xy 162.56 82.55)) (stroke (width 0) (type default) (color 0 0 0 0)) (uuid 1933ede3-fcf0-4253-afc0-01a98d446394) @@ -1912,7 +1908,7 @@ (stroke (width 0) (type default) (color 0 0 0 0)) (uuid 4b0bee11-cc4c-4004-8f2c-c44a6715a0a1) ) - (wire (pts (xy 149.86 170.18) (xy 149.86 135.89)) + (wire (pts (xy 149.86 128.27) (xy 149.86 170.18)) (stroke (width 0) (type default) (color 0 0 0 0)) (uuid 4b792dc0-cc3e-43a8-a700-fcd82fd26433) ) @@ -1948,6 +1944,10 @@ (stroke (width 0) (type default) (color 0 0 0 0)) (uuid 58e8a243-dbf1-46ec-a9ca-62db6c046a4b) ) + (wire (pts (xy 149.86 128.27) (xy 214.63 128.27)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid 58fbb80d-a05f-42b1-b000-203665a084f7) + ) (wire (pts (xy 76.2 116.84) (xy 46.99 116.84)) (stroke (width 0) (type default) (color 0 0 0 0)) (uuid 5a040418-8644-4cf8-9de0-ba3624649e9e) @@ -2047,7 +2047,7 @@ (uuid 7bfba61b-6752-4a45-9ee6-5984dcb15041) ) - (wire (pts (xy 138.43 82.55) (xy 138.43 181.61)) + (wire (pts (xy 138.43 82.55) (xy 138.43 158.75)) (stroke (width 0) (type default) (color 0 0 0 0)) (uuid 7c5f3091-7791-43b3-8d50-43f6a72274c9) ) @@ -2106,10 +2106,6 @@ (stroke (width 0) (type default) (color 0 0 0 0)) (uuid 955cc99e-a129-42cf-abc7-aa99813fdb5f) ) - (wire (pts (xy 130.81 181.61) (xy 130.81 158.75)) - (stroke (width 0) (type default) (color 0 0 0 0)) - (uuid 95da0586-f1ba-4b4b-affc-b687fd99334b) - ) (wire (pts (xy 53.34 99.06) (xy 78.74 99.06)) (stroke (width 0) (type default) (color 0 0 0 0)) (uuid 965dcc1b-b3f1-4059-96bc-33cc40cfb1c9) @@ -2168,18 +2164,10 @@ (stroke (width 0) (type default) (color 0 0 0 0)) (uuid 9a970ac1-63cf-40d6-bc9a-be6411b01438) ) - (wire (pts (xy 266.7 135.89) (xy 266.7 138.43)) - (stroke (width 0) (type default) (color 0 0 0 0)) - (uuid 9c51c73b-3150-47dd-bb34-618d48e6b29c) - ) (wire (pts (xy 179.07 102.87) (xy 214.63 102.87)) (stroke (width 0) (type default) (color 0 0 0 0)) (uuid 9d671c06-86f9-4e89-a7da-6f87b0b7d806) ) - (wire (pts (xy 149.86 135.89) (xy 214.63 135.89)) - (stroke (width 0) (type default) (color 0 0 0 0)) - (uuid 9ef8f73d-a83a-4fab-ae69-3c69a7a8fa5c) - ) (polyline (pts (xy 193.04 22.86) (xy 193.04 48.26)) (stroke (width 0) (type default) (color 0 0 0 0)) (uuid a07b6b2b-7179-4297-b163-5e47ffbe76d3) @@ -2202,6 +2190,10 @@ (uuid a92f3b72-ed6d-4d99-9da6-35771bec3c77) ) + (wire (pts (xy 214.63 130.81) (xy 152.4 130.81)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid a950c719-307b-4a85-b77b-1b65fecb572b) + ) (wire (pts (xy 85.09 137.16) (xy 82.55 137.16)) (stroke (width 0) (type default) (color 0 0 0 0)) (uuid aa130053-a451-4f12-97f7-3d4d891a5f83) @@ -2243,11 +2235,15 @@ (stroke (width 0) (type default) (color 0 0 0 0)) (uuid b66bd561-8b9b-4d7d-a674-bd75e545031f) ) + (wire (pts (xy 138.43 158.75) (xy 138.43 181.61)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid ba24d722-243f-45ee-b521-7865e70d35e3) + ) (wire (pts (xy 273.05 54.61) (xy 189.23 54.61)) (stroke (width 0) (type default) (color 0 0 0 0)) (uuid bd33b194-268e-44c3-b0b1-b7463d83fbac) ) - (wire (pts (xy 130.81 158.75) (xy 130.81 140.97)) + (wire (pts (xy 130.81 140.97) (xy 130.81 181.61)) (stroke (width 0) (type default) (color 0 0 0 0)) (uuid befb4d6e-122e-409d-8dd0-eb4553de6303) ) @@ -2272,7 +2268,7 @@ (uuid c8a44971-63c1-4a19-879d-b6647b2dc08d) ) - (wire (pts (xy 152.4 138.43) (xy 152.4 172.72)) + (wire (pts (xy 152.4 130.81) (xy 152.4 172.72)) (stroke (width 0) (type default) (color 0 0 0 0)) (uuid c9c0254d-2aea-44d0-921d-4f10c1d900d7) ) @@ -2288,10 +2284,6 @@ (stroke (width 0) (type default) (color 0 0 0 0)) (uuid cb9cdea3-d2ff-4b19-845c-07985c9f22e6) ) - (wire (pts (xy 130.81 158.75) (xy 133.35 158.75)) - (stroke (width 0) (type default) (color 0 0 0 0)) - (uuid cc26466d-7d1b-4bc5-bd48-b0279c5b13e2) - ) (wire (pts (xy 130.81 140.97) (xy 267.97 140.97)) (stroke (width 0) (type default) (color 0 0 0 0)) (uuid cd93a1bc-9d41-4f33-a8a6-0ee065143737) @@ -2342,10 +2334,6 @@ (stroke (width 0) (type default) (color 0 0 0 0)) (uuid d8715077-3de6-462f-8157-bd58811f8b11) ) - (wire (pts (xy 266.7 138.43) (xy 152.4 138.43)) - (stroke (width 0) (type default) (color 0 0 0 0)) - (uuid d94423f3-9e5e-452a-a13a-39784938a963) - ) (wire (pts (xy 135.89 172.72) (xy 152.4 172.72)) (stroke (width 0) (type default) (color 0 0 0 0)) (uuid da384d7e-2585-4a93-8461-19ed14a896e3) @@ -2366,6 +2354,10 @@ (stroke (width 0) (type default) (color 0 0 0 0)) (uuid dde8619c-5a8c-40eb-9845-65e6a654222d) ) + (wire (pts (xy 135.89 158.75) (xy 138.43 158.75)) + (stroke (width 0) (type default) (color 0 0 0 0)) + (uuid de1885af-eff1-4774-869f-ad50f9e6fd59) + ) (wire (pts (xy 104.14 137.16) (xy 125.73 137.16)) (stroke (width 0) (type default) (color 0 0 0 0)) (uuid de370984-7922-4327-a0ba-7cd613995df4) @@ -2693,44 +2685,44 @@ (in_bom yes) (on_board yes) (uuid 00000000-0000-0000-0000-00005dece90e) (property "Reference" "U2" (id 0) (at 95.25 144.78 0)) - (property "Value" "" (id 1) (at 93.98 142.24 0)) + (property "Value" "StepDown" (id 1) (at 93.98 142.24 0)) (property "Footprint" "" (id 2) (at 95.25 134.62 0) (effects (font (size 1.27 1.27)) hide) ) (property "Datasheet" "" (id 3) (at 95.25 134.62 0) (effects (font (size 1.27 1.27)) hide) ) - (pin "~" (uuid 289d2381-c24d-462b-86ba-5805292aae5c)) - (pin "~" (uuid 289d2381-c24d-462b-86ba-5805292aae5c)) - (pin "~" (uuid 289d2381-c24d-462b-86ba-5805292aae5c)) - (pin "~" (uuid 289d2381-c24d-462b-86ba-5805292aae5c)) + (pin "~" (uuid 289d2381-c24d-462b-86ba-5805292aae5f)) + (pin "~" (uuid 289d2381-c24d-462b-86ba-5805292aae5f)) + (pin "~" (uuid 289d2381-c24d-462b-86ba-5805292aae5f)) + (pin "~" (uuid 289d2381-c24d-462b-86ba-5805292aae5f)) ) (symbol (lib_id "Bobbycar_components:powerlatch") (at 68.58 133.35 0) (unit 1) (in_bom yes) (on_board yes) (uuid 00000000-0000-0000-0000-00005decec56) (property "Reference" "U1" (id 0) (at 69.215 120.015 0)) - (property "Value" "" (id 1) (at 69.215 122.3264 0)) + (property "Value" "powerlatch" (id 1) (at 69.215 122.3264 0)) (property "Footprint" "" (id 2) (at 68.58 133.35 0) (effects (font (size 1.27 1.27)) hide) ) (property "Datasheet" "" (id 3) (at 68.58 133.35 0) (effects (font (size 1.27 1.27)) hide) ) - (pin "~" (uuid 7672a6d3-c089-44dd-b44a-004517620f41)) - (pin "~" (uuid 7672a6d3-c089-44dd-b44a-004517620f41)) - (pin "~" (uuid 7672a6d3-c089-44dd-b44a-004517620f41)) - (pin "~" (uuid 7672a6d3-c089-44dd-b44a-004517620f41)) - (pin "~" (uuid 7672a6d3-c089-44dd-b44a-004517620f41)) - (pin "~" (uuid 7672a6d3-c089-44dd-b44a-004517620f41)) - (pin "~" (uuid 7672a6d3-c089-44dd-b44a-004517620f41)) + (pin "~" (uuid 7672a6d3-c089-44dd-b44a-004517620f47)) + (pin "~" (uuid 7672a6d3-c089-44dd-b44a-004517620f47)) + (pin "~" (uuid 7672a6d3-c089-44dd-b44a-004517620f47)) + (pin "~" (uuid 7672a6d3-c089-44dd-b44a-004517620f47)) + (pin "~" (uuid 7672a6d3-c089-44dd-b44a-004517620f47)) + (pin "~" (uuid 7672a6d3-c089-44dd-b44a-004517620f47)) + (pin "~" (uuid 7672a6d3-c089-44dd-b44a-004517620f47)) ) (symbol (lib_id "Switch:SW_Push_SPDT") (at 44.45 99.06 0) (unit 1) (in_bom yes) (on_board yes) (uuid 00000000-0000-0000-0000-00005decf526) (property "Reference" "SW1" (id 0) (at 44.45 102.87 0)) - (property "Value" "" (id 1) (at 44.45 94.1324 0)) + (property "Value" "POWERBUTTON" (id 1) (at 44.45 94.1324 0)) (property "Footprint" "" (id 2) (at 44.45 99.06 0) (effects (font (size 1.27 1.27)) hide) ) @@ -2748,10 +2740,10 @@ (property "Reference" "Q1" (id 0) (at 115.6716 88.646 0) (effects (font (size 1.27 1.27)) (justify left)) ) - (property "Value" "" (id 1) (at 117.983 88.646 0) + (property "Value" "BC337" (id 1) (at 117.983 88.646 0) (effects (font (size 1.27 1.27)) (justify left)) ) - (property "Footprint" "" (id 2) (at 118.745 88.9 0) + (property "Footprint" "Package_TO_SOT_THT:TO-92_Inline" (id 2) (at 118.745 88.9 0) (effects (font (size 1.27 1.27) italic) (justify left) hide) ) (property "Datasheet" "http://www.nxp.com/documents/data_sheet/BC817_BC817W_BC337.pdf" (id 3) (at 116.84 83.82 0) @@ -2766,7 +2758,7 @@ (in_bom yes) (on_board yes) (uuid 00000000-0000-0000-0000-00005ded2168) (property "Reference" "R1" (id 0) (at 123.19 69.6722 90)) - (property "Value" "" (id 1) (at 123.19 71.9836 90)) + (property "Value" "220" (id 1) (at 123.19 71.9836 90)) (property "Footprint" "" (id 2) (at 123.19 73.152 90) (effects (font (size 1.27 1.27)) hide) ) @@ -2783,7 +2775,7 @@ (property "Reference" "J16" (id 0) (at 236.9312 37.4396 0) (effects (font (size 1.27 1.27)) (justify left)) ) - (property "Value" "" (id 1) (at 236.9312 39.751 0) + (property "Value" "Serial" (id 1) (at 236.9312 39.751 0) (effects (font (size 1.27 1.27)) (justify left)) ) (property "Footprint" "" (id 2) (at 236.22 36.83 0) @@ -2806,7 +2798,7 @@ (property "Reference" "J12" (id 0) (at 195.2752 158.0642 90) (effects (font (size 1.27 1.27)) (justify right)) ) - (property "Value" "" (id 1) (at 195.2752 160.3756 90) + (property "Value" "Serial3" (id 1) (at 195.2752 160.3756 90) (effects (font (size 1.27 1.27)) (justify right)) ) (property "Footprint" "" (id 2) (at 187.96 161.29 0) @@ -2827,7 +2819,7 @@ (property "Reference" "J13" (id 0) (at 215.5952 158.0642 90) (effects (font (size 1.27 1.27)) (justify right)) ) - (property "Value" "" (id 1) (at 215.5952 160.3756 90) + (property "Value" "Serial2" (id 1) (at 215.5952 160.3756 90) (effects (font (size 1.27 1.27)) (justify right)) ) (property "Footprint" "" (id 2) (at 208.28 161.29 0) @@ -2846,7 +2838,7 @@ (in_bom yes) (on_board yes) (uuid 00000000-0000-0000-0000-00005dee315d) (property "Reference" "F1" (id 0) (at 83.82 48.1838 90)) - (property "Value" "" (id 1) (at 83.82 45.8724 90)) + (property "Value" "AGU Fuseholder" (id 1) (at 83.82 45.8724 90)) (property "Footprint" "" (id 2) (at 83.82 44.958 90) (effects (font (size 1.27 1.27)) hide) ) @@ -2863,7 +2855,7 @@ (property "Reference" "J5" (id 0) (at 46.99 31.75 90) (effects (font (size 1.27 1.27)) (justify left)) ) - (property "Value" "" (id 1) (at 55.88 38.1 90) + (property "Value" "xt60_male" (id 1) (at 55.88 38.1 90) (effects (font (size 1.27 1.27)) (justify left)) ) (property "Footprint" "" (id 2) (at 58.42 33.02 0) @@ -2872,8 +2864,8 @@ (property "Datasheet" "" (id 3) (at 58.42 33.02 0) (effects (font (size 1.27 1.27)) hide) ) - (pin "~" (uuid 5e737bb7-9ff1-43d7-bb29-d92d56c2e82e)) - (pin "~" (uuid 5e737bb7-9ff1-43d7-bb29-d92d56c2e82e)) + (pin "~" (uuid 5e737bb7-9ff1-43d7-bb29-d92d56c2e82f)) + (pin "~" (uuid 5e737bb7-9ff1-43d7-bb29-d92d56c2e82f)) ) (symbol (lib_id "Bobbycar_components:xt60_male") (at 55.88 50.8 90) (unit 1) @@ -2882,7 +2874,7 @@ (property "Reference" "J6" (id 0) (at 46.99 50.8 90) (effects (font (size 1.27 1.27)) (justify left)) ) - (property "Value" "" (id 1) (at 55.88 57.15 90) + (property "Value" "xt60_male" (id 1) (at 55.88 57.15 90) (effects (font (size 1.27 1.27)) (justify left)) ) (property "Footprint" "" (id 2) (at 58.42 52.07 0) @@ -2891,38 +2883,38 @@ (property "Datasheet" "" (id 3) (at 58.42 52.07 0) (effects (font (size 1.27 1.27)) hide) ) - (pin "~" (uuid 283e418a-9a69-45b9-b0eb-506e5b012a18)) - (pin "~" (uuid 283e418a-9a69-45b9-b0eb-506e5b012a18)) + (pin "~" (uuid 283e418a-9a69-45b9-b0eb-506e5b012a19)) + (pin "~" (uuid 283e418a-9a69-45b9-b0eb-506e5b012a19)) ) (symbol (lib_id "Bobbycar_components:xt60_female") (at 92.71 31.75 270) (mirror x) (unit 1) (in_bom yes) (on_board yes) (uuid 00000000-0000-0000-0000-00005def4065) (property "Reference" "J7" (id 0) (at 97.79 31.75 90)) - (property "Value" "" (id 1) (at 97.79 25.4 90)) + (property "Value" "xt60_female" (id 1) (at 97.79 25.4 90)) (property "Footprint" "" (id 2) (at 92.71 31.75 0) (effects (font (size 1.27 1.27)) hide) ) (property "Datasheet" "" (id 3) (at 92.71 31.75 0) (effects (font (size 1.27 1.27)) hide) ) - (pin "~" (uuid abfe2d16-5c1c-42e5-a5b8-7ee7611663a0)) - (pin "~" (uuid abfe2d16-5c1c-42e5-a5b8-7ee7611663a0)) + (pin "~" (uuid abfe2d16-5c1c-42e5-a5b8-7ee7611663a1)) + (pin "~" (uuid abfe2d16-5c1c-42e5-a5b8-7ee7611663a1)) ) (symbol (lib_id "Bobbycar_components:xt60_female") (at 92.71 50.8 270) (mirror x) (unit 1) (in_bom yes) (on_board yes) (uuid 00000000-0000-0000-0000-00005def4204) (property "Reference" "J8" (id 0) (at 97.79 50.8 90)) - (property "Value" "" (id 1) (at 97.79 44.45 90)) + (property "Value" "xt60_female" (id 1) (at 97.79 44.45 90)) (property "Footprint" "" (id 2) (at 92.71 50.8 0) (effects (font (size 1.27 1.27)) hide) ) (property "Datasheet" "" (id 3) (at 92.71 50.8 0) (effects (font (size 1.27 1.27)) hide) ) - (pin "~" (uuid 87069b1b-beb7-4ccb-b34c-3dbae8f09b7d)) - (pin "~" (uuid 87069b1b-beb7-4ccb-b34c-3dbae8f09b7d)) + (pin "~" (uuid 87069b1b-beb7-4ccb-b34c-3dbae8f09b7e)) + (pin "~" (uuid 87069b1b-beb7-4ccb-b34c-3dbae8f09b7e)) ) (symbol (lib_id "Bobbycar_components:xt90antispark_female") (at 116.84 40.64 270) (unit 1) @@ -2931,7 +2923,7 @@ (property "Reference" "J9" (id 0) (at 116.84 53.34 90) (effects (font (size 1.27 1.27)) (justify left)) ) - (property "Value" "" (id 1) (at 116.84 50.8 90) + (property "Value" "xt90antispark_female" (id 1) (at 116.84 50.8 90) (effects (font (size 1.27 1.27)) (justify left)) ) (property "Footprint" "" (id 2) (at 116.84 40.64 0) @@ -2940,23 +2932,23 @@ (property "Datasheet" "" (id 3) (at 116.84 40.64 0) (effects (font (size 1.27 1.27)) hide) ) - (pin "~" (uuid 47077c27-146a-406e-a83a-e467ee31c5e5)) - (pin "~" (uuid 47077c27-146a-406e-a83a-e467ee31c5e5)) + (pin "~" (uuid 47077c27-146a-406e-a83a-e467ee31c5e6)) + (pin "~" (uuid 47077c27-146a-406e-a83a-e467ee31c5e6)) ) (symbol (lib_id "Bobbycar_components:xt90_male") (at 148.59 40.64 90) (mirror x) (unit 1) (in_bom yes) (on_board yes) (uuid 00000000-0000-0000-0000-00005df0861f) (property "Reference" "J11" (id 0) (at 141.1224 28.829 90)) - (property "Value" "" (id 1) (at 141.1224 31.1404 90)) + (property "Value" "xt90_male" (id 1) (at 141.1224 31.1404 90)) (property "Footprint" "" (id 2) (at 148.59 40.64 0) (effects (font (size 1.27 1.27)) hide) ) (property "Datasheet" "" (id 3) (at 148.59 40.64 0) (effects (font (size 1.27 1.27)) hide) ) - (pin "~" (uuid aa0df799-0b67-406d-90cf-6dbd8229053d)) - (pin "~" (uuid aa0df799-0b67-406d-90cf-6dbd8229053d)) + (pin "~" (uuid aa0df799-0b67-406d-90cf-6dbd8229053e)) + (pin "~" (uuid aa0df799-0b67-406d-90cf-6dbd8229053e)) ) (symbol (lib_id "Connector_Generic:Conn_01x04") (at 133.35 186.69 90) (mirror x) (unit 1) @@ -2965,7 +2957,7 @@ (property "Reference" "J10" (id 0) (at 140.6652 183.4642 90) (effects (font (size 1.27 1.27)) (justify right)) ) - (property "Value" "" (id 1) (at 140.6652 185.7756 90) + (property "Value" "Steering Wheel I2C" (id 1) (at 140.6652 185.7756 90) (effects (font (size 1.27 1.27)) (justify right)) ) (property "Footprint" "" (id 2) (at 133.35 186.69 0) @@ -2986,7 +2978,7 @@ (property "Reference" "J2" (id 0) (at 17.78 96.52 90) (effects (font (size 1.27 1.27)) (justify left)) ) - (property "Value" "" (id 1) (at 27.94 105.41 90) + (property "Value" "xt30_male" (id 1) (at 27.94 105.41 90) (effects (font (size 1.27 1.27)) (justify left)) ) (property "Footprint" "" (id 2) (at 22.86 105.41 0) @@ -2995,8 +2987,8 @@ (property "Datasheet" "" (id 3) (at 22.86 105.41 0) (effects (font (size 1.27 1.27)) hide) ) - (pin "~" (uuid a5adf9fc-330f-4cad-bdb2-e0f8fb1b77ad)) - (pin "~" (uuid a5adf9fc-330f-4cad-bdb2-e0f8fb1b77ad)) + (pin "~" (uuid a5adf9fc-330f-4cad-bdb2-e0f8fb1b77ae)) + (pin "~" (uuid a5adf9fc-330f-4cad-bdb2-e0f8fb1b77ae)) ) (symbol (lib_id "Bobbycar_components:xt30_female") (at 22.86 81.28 0) (mirror x) (unit 1) @@ -3005,7 +2997,7 @@ (property "Reference" "J1" (id 0) (at 17.78 83.82 90) (effects (font (size 1.27 1.27)) (justify right)) ) - (property "Value" "" (id 1) (at 27.94 92.71 90) + (property "Value" "xt30_female" (id 1) (at 27.94 92.71 90) (effects (font (size 1.27 1.27)) (justify right)) ) (property "Footprint" "" (id 2) (at 22.86 81.28 0) @@ -3014,15 +3006,15 @@ (property "Datasheet" "" (id 3) (at 22.86 81.28 0) (effects (font (size 1.27 1.27)) hide) ) - (pin "~" (uuid 92c8a67d-ecef-4663-99f5-c2b6e82bc05e)) - (pin "~" (uuid 92c8a67d-ecef-4663-99f5-c2b6e82bc05e)) + (pin "~" (uuid 92c8a67d-ecef-4663-99f5-c2b6e82bc05f)) + (pin "~" (uuid 92c8a67d-ecef-4663-99f5-c2b6e82bc05f)) ) (symbol (lib_id "Bobbycar_wiring-rescue:SW_DPST_x2-Switch") (at 173.99 43.18 0) (unit 1) (in_bom yes) (on_board yes) (uuid 00000000-0000-0000-0000-00005df361c7) (property "Reference" "SW2" (id 0) (at 173.99 37.211 0)) - (property "Value" "" (id 1) (at 173.99 45.72 0)) + (property "Value" "MODESWITCH" (id 1) (at 173.99 45.72 0)) (property "Footprint" "" (id 2) (at 173.99 43.18 0) (effects (font (size 1.27 1.27)) hide) ) @@ -3039,7 +3031,7 @@ (in_bom yes) (on_board yes) (uuid 00000000-0000-0000-0000-00005df36553) (property "Reference" "D1" (id 0) (at 50.8 85.09 0)) - (property "Value" "" (id 1) (at 53.34 90.17 0)) + (property "Value" "POWERLED" (id 1) (at 53.34 90.17 0)) (property "Footprint" "" (id 2) (at 44.45 86.36 0) (effects (font (size 1.27 1.27)) hide) ) @@ -3054,7 +3046,7 @@ (in_bom yes) (on_board yes) (uuid 00000000-0000-0000-0000-00005df45e41) (property "Reference" "D2" (id 0) (at 173.99 24.765 0)) - (property "Value" "" (id 1) (at 173.99 27.0764 0)) + (property "Value" "MODELED_RED/GREEN" (id 1) (at 173.99 27.0764 0)) (property "Footprint" "" (id 2) (at 175.26 35.56 0) (effects (font (size 1.27 1.27)) hide) ) @@ -3070,7 +3062,7 @@ (in_bom yes) (on_board yes) (uuid 00000000-0000-0000-0000-00005df4cd3f) (property "Reference" "R5" (id 0) (at 186.69 59.69 90)) - (property "Value" "" (id 1) (at 185.42 55.88 90)) + (property "Value" "66" (id 1) (at 185.42 55.88 90)) (property "Footprint" "" (id 2) (at 187.198 55.88 90) (effects (font (size 1.27 1.27)) hide) ) @@ -3085,7 +3077,7 @@ (in_bom yes) (on_board yes) (uuid 00000000-0000-0000-0000-00005df4cdeb) (property "Reference" "R4" (id 0) (at 181.61 59.69 90)) - (property "Value" "" (id 1) (at 182.88 55.88 90)) + (property "Value" "20" (id 1) (at 182.88 55.88 90)) (property "Footprint" "" (id 2) (at 184.658 55.88 90) (effects (font (size 1.27 1.27)) hide) ) @@ -3099,10 +3091,10 @@ (symbol (lib_id "Device:R") (at 133.35 163.83 0) (unit 1) (in_bom yes) (on_board yes) (uuid 00000000-0000-0000-0000-00005df4d8f9) - (property "Reference" "R2" (id 0) (at 129.54 162.56 0) + (property "Reference" "R2" (id 0) (at 127.635 162.56 0) (effects (font (size 1.27 1.27)) (justify left)) ) - (property "Value" "" (id 1) (at 127 165.1 0) + (property "Value" "4k7" (id 1) (at 127 165.1 0) (effects (font (size 1.27 1.27)) (justify left)) ) (property "Footprint" "" (id 2) (at 131.572 163.83 90) @@ -3118,10 +3110,10 @@ (symbol (lib_id "Device:R") (at 135.89 163.83 0) (unit 1) (in_bom yes) (on_board yes) (uuid 00000000-0000-0000-0000-00005df4d9c1) - (property "Reference" "R3" (id 0) (at 137.668 162.6616 0) + (property "Reference" "R3" (id 0) (at 139.065 162.56 0) (effects (font (size 1.27 1.27)) (justify left)) ) - (property "Value" "" (id 1) (at 137.668 164.973 0) + (property "Value" "4k7" (id 1) (at 139.065 165.1 0) (effects (font (size 1.27 1.27)) (justify left)) ) (property "Footprint" "" (id 2) (at 134.112 163.83 90) @@ -3138,38 +3130,38 @@ (in_bom yes) (on_board yes) (uuid 00000000-0000-0000-0000-00005dfdc06d) (property "Reference" "J3" (id 0) (at 30.48 31.75 90)) - (property "Value" "" (id 1) (at 33.02 38.1 90)) + (property "Value" "xt60_female" (id 1) (at 33.02 38.1 90)) (property "Footprint" "" (id 2) (at 26.67 31.75 0) (effects (font (size 1.27 1.27)) hide) ) (property "Datasheet" "" (id 3) (at 26.67 31.75 0) (effects (font (size 1.27 1.27)) hide) ) - (pin "~" (uuid c8baad8e-84f6-4984-837a-38ef6d0b77b8)) - (pin "~" (uuid c8baad8e-84f6-4984-837a-38ef6d0b77b8)) + (pin "~" (uuid c8baad8e-84f6-4984-837a-38ef6d0b77b9)) + (pin "~" (uuid c8baad8e-84f6-4984-837a-38ef6d0b77b9)) ) (symbol (lib_id "Bobbycar_components:xt60_female") (at 26.67 50.8 270) (mirror x) (unit 1) (in_bom yes) (on_board yes) (uuid 00000000-0000-0000-0000-00005dfdc2fb) (property "Reference" "J4" (id 0) (at 30.48 50.8 90)) - (property "Value" "" (id 1) (at 33.02 57.15 90)) + (property "Value" "xt60_female" (id 1) (at 33.02 57.15 90)) (property "Footprint" "" (id 2) (at 26.67 50.8 0) (effects (font (size 1.27 1.27)) hide) ) (property "Datasheet" "" (id 3) (at 26.67 50.8 0) (effects (font (size 1.27 1.27)) hide) ) - (pin "~" (uuid a4649d4d-6aa3-4f07-b7a6-0d73d155ec89)) - (pin "~" (uuid a4649d4d-6aa3-4f07-b7a6-0d73d155ec89)) + (pin "~" (uuid a4649d4d-6aa3-4f07-b7a6-0d73d155ec8a)) + (pin "~" (uuid a4649d4d-6aa3-4f07-b7a6-0d73d155ec8a)) ) (symbol (lib_id "Regulator_Linear:L78L33_TO92") (at 209.55 24.13 0) (unit 1) (in_bom yes) (on_board yes) (fields_autoplaced) (uuid 5fed31b2-9dc0-4157-9739-9e2eeac4aede) (property "Reference" "U3" (id 0) (at 209.55 16.51 0)) - (property "Value" "" (id 1) (at 209.55 19.05 0)) - (property "Footprint" "" (id 2) (at 209.55 18.415 0) + (property "Value" "L78L33_TO92" (id 1) (at 209.55 19.05 0)) + (property "Footprint" "Package_TO_SOT_THT:TO-92_Inline" (id 2) (at 209.55 18.415 0) (effects (font (size 1.27 1.27) italic) hide) ) (property "Datasheet" "http://www.st.com/content/ccc/resource/technical/document/datasheet/15/55/e5/aa/23/5b/43/fd/CD00000446.pdf/files/CD00000446.pdf/jcr:content/translations/en.CD00000446.pdf" (id 3) (at 209.55 25.4 0) @@ -3186,7 +3178,7 @@ (property "Reference" "C1" (id 0) (at 181.61 84.2009 0) (effects (font (size 1.27 1.27)) (justify left)) ) - (property "Value" "" (id 1) (at 181.61 86.7409 0) + (property "Value" "100uF" (id 1) (at 181.61 86.7409 0) (effects (font (size 1.27 1.27)) (justify left)) ) (property "Footprint" "" (id 2) (at 178.7652 90.17 0) @@ -3205,7 +3197,7 @@ (property "Reference" "BT?" (id 0) (at 182.88 104.6479 0) (effects (font (size 1.27 1.27)) (justify left)) ) - (property "Value" "" (id 1) (at 182.88 107.1879 0) + (property "Value" "3V" (id 1) (at 182.88 107.1879 0) (effects (font (size 1.27 1.27)) (justify left)) ) (property "Footprint" "" (id 2) (at 179.07 106.426 90) @@ -3224,7 +3216,7 @@ (property "Reference" "U4" (id 0) (at 240.03 59.69 0) (effects (font (size 1.524 1.524))) ) - (property "Value" "" (id 1) (at 240.03 63.5 0) + (property "Value" "Teensy3.2" (id 1) (at 240.03 63.5 0) (effects (font (size 1.524 1.524))) ) (property "Footprint" "" (id 2) (at 240.03 120.65 0) @@ -3337,7 +3329,7 @@ (reference "J9") (unit 1) (value "xt90antispark_female") (footprint "") ) (path "/00000000-0000-0000-0000-00005df0cf60" - (reference "J10") (unit 1) (value "Throttle") (footprint "") + (reference "J10") (unit 1) (value "Steering Wheel I2C") (footprint "") ) (path "/00000000-0000-0000-0000-00005df0861f" (reference "J11") (unit 1) (value "xt90_male") (footprint "") @@ -3358,10 +3350,10 @@ (reference "R1") (unit 1) (value "220") (footprint "") ) (path "/00000000-0000-0000-0000-00005df4d8f9" - (reference "R2") (unit 1) (value "100k") (footprint "") + (reference "R2") (unit 1) (value "4k7") (footprint "") ) (path "/00000000-0000-0000-0000-00005df4d9c1" - (reference "R3") (unit 1) (value "100k") (footprint "") + (reference "R3") (unit 1) (value "4k7") (footprint "") ) (path "/00000000-0000-0000-0000-00005df4cdeb" (reference "R4") (unit 1) (value "20") (footprint "") diff --git a/controller_teensy/platformio.ini b/controller_teensy/platformio.ini index 5b25997..fc71c50 100644 --- a/controller_teensy/platformio.ini +++ b/controller_teensy/platformio.ini @@ -18,4 +18,7 @@ framework = arduino monitor_speed = 115200 build_flags = - -D USB_SERIAL_HID \ No newline at end of file + -D USB_SERIAL_HID + +lib_deps = + robtillaart/ADS1X15@^0.3.9 \ No newline at end of file diff --git a/controller_teensy/src/main.cpp b/controller_teensy/src/main.cpp index a225f64..c76f577 100644 --- a/controller_teensy/src/main.cpp +++ b/controller_teensy/src/main.cpp @@ -1,6 +1,9 @@ #include +#include "ADS1X15.h" + +ADS1115 ADS(0x48); /* Connections: @@ -37,28 +40,38 @@ bool controllers_connected=false; #define PIN_THROTTLE A7 //const uint16_t calib_throttle_min = 420; //better a bit too high than too low //const uint16_t calib_throttle_max = 790; -const uint16_t failsafe_throttle_min = 20; //if adc value falls below this failsafe is triggered -const uint16_t failsafe_throttle_max = 1000; //if adc value goes above this failsafe is triggered -const uint16_t throttleCurvePerMM[] = {414,460,490,511,527,539,548,555,561,567,573,578,584,590,599,611,630,657,697,754,789,795}; //adc values for every unit (mm) of linear travel +const uint16_t failsafe_throttle_min = 4900; //if adc value falls below this failsafe is triggered. old 20 +const uint16_t failsafe_throttle_max = 14000; //if adc value goes above this failsafe is triggered. old 1000 +//const uint16_t throttleCurvePerMM[] = {414,460,490,511,527,539,548,555,561,567,573,578,584,590,599,611,630,657,697,754,789,795}; //adc values for every unit (mm) of linear travel +const uint16_t throttleCurvePerMM[] = {8485,8904,9177,9368,9513,9623,9705,9768,9823,9877,9932,9978,10032,10087,10169,10278,10451,10697,11061,11579,11898,11952}; //adc values for every unit (mm) of linear travel #define PIN_BRAKE A8 -const uint16_t calib_brake_min = 100;//better a bit too high than too low -const uint16_t calib_brake_max = 600; -const uint16_t failsafe_brake_min = 20; //if adc value falls below this failsafe is triggered -const uint16_t failsafe_brake_max = 1000; //if adc value goes above this failsafe is triggered +const uint16_t calib_brake_min = 2000;//better a bit too high than too low +const uint16_t calib_brake_max = 11000; +const uint16_t failsafe_brake_min = 700; //if adc value falls below this failsafe is triggered +const uint16_t failsafe_brake_max = 13000; //if adc value goes above this failsafe is triggered + +uint16_t ads_throttle_A_raw=0; +uint16_t ads_throttle_B_raw=0; +uint16_t ads_brake_raw=failsafe_brake_min; +uint16_t ads_control_raw=0; int16_t throttle_pos=0; int16_t brake_pos=0; -unsigned long last_adcread=0; + +#define ADSREADPERIOD 3 //set slightly higher as actual read time to avoid unnecessary register query #define ADCREADPERIOD 10 -uint16_t throttle_raw=0; +#define BUTTONREADPERIOD 20 +unsigned long last_adsread=0; //needed for failcheck +uint16_t throttle_raw=failsafe_throttle_min; //start at min so that failsafe is not triggered #define THROTTLE_ADC_FILTER 0.15 //higher value = faster response -uint16_t brake_raw=0; +uint16_t brake_raw=failsafe_brake_min; //start at min so that failsafe is not triggered #define ADC_OUTOFRANGE_TIME 100 unsigned long throttle_ok_time=0; unsigned long brake_ok_time=0; bool error_throttle_outofrange=false; bool error_brake_outofrange=false; +bool error_ads_max_read_interval=false; #define REVERSE_ENABLE_TIME 1000 //ms. how long standstill to be able to drive backward #define REVERSE_SPEED 0.25 //reverse driving speed //0 to 1 @@ -181,8 +194,9 @@ float filterMedian(int16_t* values); void writeLogHeader(HardwareSerial &SerialRef); void writeLog(HardwareSerial &SerialRef, unsigned long time, MotorParameter &mpfront, MotorParameter &mprear, SerialFeedback &fbfront, SerialFeedback &fbrear, float currentAll, int16_t throttle, int16_t brake); -void writeLogComment(HardwareSerial &SerialRef, String msg); +void writeLogComment(HardwareSerial &SerialRef, unsigned long time, String msg); +void readADS(); void readADC(); void failChecks(); void sendCMD(); @@ -211,14 +225,14 @@ void SendSerial(SerialCommand &scom, int16_t uSpeedLeft, int16_t uSpeedRight, Ha bool ReceiveSerial(SerialRead &sread, SerialFeedback &Feedback,SerialFeedback &NewFeedback, HardwareSerial &SerialRef) { - bool _result=1; + bool _result=false; //return true if new full data frame received // Check for new data availability in the Serial buffer if ( SerialRef.available() ) { sread.incomingByte = SerialRef.read(); // Read the incoming byte sread.bufStartFrame = ((uint16_t)(sread.incomingByte) << 8) | sread.incomingBytePrev; // Construct the start frame } else { - return 0; + return false; //nothing new } // If DEBUG_RX is defined print all incoming bytes @@ -249,8 +263,9 @@ bool ReceiveSerial(SerialRead &sread, SerialFeedback &Feedback,SerialFeedback &N // Copy the new data memcpy(&Feedback, &NewFeedback, sizeof(SerialFeedback)); sread.lastValidDataSerial_time = millis(); + _result=true; } else { - _result=0; + _result=false; } sread.idx = 0; // Reset the index (it prevents to enter in this if condition in the next cycle) } @@ -300,6 +315,20 @@ void setup() digitalWrite(PIN_LATCH_ENABLE,HIGH); //latch on pinMode(PIN_MODE_SWITCH, INPUT_PULLUP); + delay(2000); + Serial.println("Wait finished. Booting.."); + + //init ADS1115 + if (!ADS.begin()) { + Serial.println("Error:"); delay(2000); Serial.println("ADS1115 Init Error!"); + writeLogComment(Serial1,(unsigned long)millis(), "Error ADS1115 Init"); + } + ADS.setGain(0); + ADS.setDataRate(7);// Read Interval: 7-> 2ms, 6-> 3-4ms , 5-> 5-6ms, 4-> 9ms, 0-> 124ms + // also set ADSREADPERIOD to at least the read interval + ADS.requestADC(0); //Start requesting a channel + delay(10); + setSyncProvider(getTeensy3Time); //See https://www.pjrc.com/teensy/td_libs_Time.html#teensy3 if (timeStatus()!= timeSet) { Serial.println("Unable to sync with the RTC"); @@ -313,10 +342,38 @@ void setup() unsigned long loopmillis; // ########################## LOOP ########################## void loop() { + //Serial.print("Loopduration="); Serial.println(); //loopduration is at max 11ms + loopmillis=millis(); //read millis for this cycle - bool newData2=ReceiveSerial(SerialcomFront,FeedbackFront, NewFeedbackFront, Serial2); + + // ____ Debugging pending serial byted for feedback + static int s2availmax=0; + int _a2=Serial2.available(); + if (_a2>s2availmax) { + s2availmax=_a2; + //Serial.print("new s2availmax"); Serial.println(s2availmax); + String _text="Serial2 Bytes Available Max="; + _text+=s2availmax; + writeLogComment(Serial1,loopmillis, _text); + } + + static int s3availmax=0; + int _a3=Serial3.available(); + if (_a3>s3availmax) { + s3availmax=_a3; + //Serial.print("new s3availmax"); Serial.println(s3availmax); + String _text="Serial3 Bytes Available Max="; + _text+=s3availmax; + writeLogComment(Serial1,loopmillis, _text); + } + // ----- End of debug + + + + bool newData2=ReceiveSerial(SerialcomFront,FeedbackFront, NewFeedbackFront, Serial2); bool newData3=ReceiveSerial(SerialcomRear,FeedbackRear, NewFeedbackRear, Serial3); + //Max (40) or 22 available/pending bytes if (newData2) { updateMotorparams(motorparamsFront,FeedbackFront); @@ -324,14 +381,31 @@ void loop() { if (newData3) { updateMotorparams(motorparamsRear,FeedbackRear); } + + + + if (loopmillis - last_adsread > ADSREADPERIOD) { //read teensy adc and filter + last_adsread=loopmillis; + if (ADS.isBusy() == false) //reads a register on ads + { + readADS(); + }else{ + Serial.println("Unnecessary ADS poll. Increase ADSREADPERIOD"); + } + } + + static unsigned long last_adcread=0; if (loopmillis - last_adcread > ADCREADPERIOD) { //read teensy adc and filter last_adcread=loopmillis; + readADC(); + } + static unsigned long last_buttonread=0; + if (loopmillis - last_buttonread > BUTTONREADPERIOD) { //read digital input states + last_buttonread=loopmillis; readButtons(); - - } @@ -355,6 +429,7 @@ void loop() { leds(); + } @@ -442,21 +517,55 @@ void writeLogComment(HardwareSerial &SerialRef, unsigned long time, String msg) } +void readADS() { //sequentially read ads and write to variable + /*static unsigned long _lastReadADS=0; + Serial.print("readADS Interval="); Serial.println(millis()-_lastReadADS); + _lastReadADS=millis();*/ + static uint8_t ads_input_switch=0; + + int16_t ads_val = ADS.getValue(); //get value from last selected channel + + + switch (ads_input_switch) { + case 0: //Throttle Sensor A + ads_throttle_A_raw=ads_val; + break; + case 1: //Throttle Sensor B + ads_throttle_B_raw=ads_val; + break; + case 2: //Brake + ads_brake_raw=ads_val; + break; + case 3: //Buttons TODO + ads_control_raw=ads_val; + break; + } + + ads_input_switch++; + ads_input_switch%=4; //max 4 channels + ADS.requestADC(ads_input_switch); // request a new one +} + // #### LOOPFUNCTIONS void readADC() { - - uint16_t new_throttle_raw = analogRead(PIN_THROTTLE); - throttle_raw = new_throttle_raw*THROTTLE_ADC_FILTER + throttle_raw*(1-THROTTLE_ADC_FILTER); //apply filter + /*Serial.print(ads_throttle_A_raw); Serial.print('\t'); + Serial.print(ads_throttle_B_raw); Serial.print('\t'); + Serial.print(ads_brake_raw); Serial.print('\t'); + Serial.print(ads_control_raw); Serial.println();*/ + throttle_raw = ads_throttle_A_raw*THROTTLE_ADC_FILTER + throttle_raw*(1-THROTTLE_ADC_FILTER); //apply filter - //maps throttle curve to be linear + //maps throttle curve to be linear throttle_pos=max(0,min(1000,linearizeThrottle(throttle_raw))); //map and constrain - brake_raw = analogRead(PIN_BRAKE); + + brake_raw=ads_brake_raw; brake_pos=max(0,min(1000,map(brake_raw,calib_brake_min,calib_brake_max,0,1000))); //map and constrain //brake_pos = (int16_t)(pow((brake_pos/1000.0),2)*1000); + + if (throttle_pos>0 || meanSpeedms>0.5 || (!reverse_enabled && brake_pos>0)) { //reset idle time on these conditions (disables reverse driving) last_notidle=loopmillis; reverse_enabled=false; @@ -505,6 +614,7 @@ void failChecks() { if (controllerFront_connected) { //just got disconnected controllerFront_connected=false; writeLogComment(Serial1,loopmillis, "Controller Front feedback timeout"); + //Serial.println("Controller Front feedback timeout"); } }else if(!controllerFront_connected && loopmillis > FEEDBACKRECEIVETIMEOUT) { //not timeouted but was before controllerFront_connected=true; @@ -515,6 +625,7 @@ void failChecks() { if (controllerRear_connected) { //just got disconnected controllerRear_connected=false; writeLogComment(Serial1,loopmillis, "Controller Rear feedback timeout"); + //Serial.println("Controller Rear feedback timeout"); } }else if(!controllerRear_connected && loopmillis > FEEDBACKRECEIVETIMEOUT) { //not timeouted but was before controllerRear_connected=true; @@ -531,7 +642,9 @@ void failChecks() { if (!error_throttle_outofrange) { error_throttle_outofrange=true; writeLogComment(Serial1,loopmillis, "Error Throttle ADC Out of Range"); + } + //Serial.print("Error Throttle ADC Out of Range="); Serial.println(throttle_raw); } if ((brake_raw >= failsafe_brake_min) & (brake_raw <= failsafe_brake_max)) { //outside safe range. maybe wire got disconnected brake_ok_time=loopmillis; @@ -540,12 +653,20 @@ void failChecks() { if(!error_brake_outofrange) { error_brake_outofrange=true; writeLogComment(Serial1,loopmillis, "Error Brake ADC Out of Range"); + } + //Serial.print("Error Brake ADC Out of Range="); Serial.println(brake_raw); + } + #define ADS_MAX_READ_INTERVAL 100 + if (loopmillis-last_adsread > ADS_MAX_READ_INTERVAL) { + if (!error_ads_max_read_interval) { + error_ads_max_read_interval=true; + writeLogComment(Serial1,loopmillis, "Error ADS Max read interval"); + } + //Serial.print("Error ADS Max read interval=");Serial.println(loopmillis-last_adsread); } - - - if (!controllers_connected || error_brake_outofrange || error_throttle_outofrange) { //any errors? + if (!controllers_connected || error_brake_outofrange || error_throttle_outofrange || error_ads_max_read_interval) { //any errors? throttle_pos=0; brake_pos=0; }