I'm working on a project for obstacle avoidance on my air bagged S10 pickup. I have all the hardware bench tested and assembled but my coding skills leave much to be desired. Is there someone available to look over the code I have made and help me correct and simply it so I can finish the install? Thank you in advance. Hardware im running is 10 infrared sensor boards, 9 switches, 4 duel relay boards, arduino mega (not clone).
Do you mean a RC model, or a real truck? One of those has very real liability concerns.
IIRC, real autos use radar or cameras for obstacle avoidance, IR has too many problems.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@zander this is a show truck that is trailered to shows and back. The start of the problem was a rogue rock in the parking lot that damaged the powdercoat on my frame as I was crusing to the trailer and was a little low. The idea is to hopefully get the truck to see obstacles when slowly moving around if I'm distracted by the nice ladys on display and auto inflate the bag on that corner. Just something cool I thought of and decided to tackle since none of the other vehicles I see have that option.
@gunn Thanks for the answer. I will have to decline due to safety and liability issues. I will tell you though the IR sensors are not the best choice as they can false alarm and not alarm due to things like black body radiation and ambient temps. I am currently using the RCWL0516 but the range might be too much for you, I am getting a good 20 ft. Some of the cameras might be a better choice, that is what my 2017 F450 uses for obstacles. Good luck.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@zander thanks for the info. I'm not trying to avoid vehicles or people, just things in the parking lot that can damage the under carage. I feel like cameras would be overkill since I only need a range of 10". The sensors will be under the bumpers, along the frame rails, and in front of the engine. Always shaded and measuring the distance to the pavement. If it sees a rock or speed bump, it will slow lift. I agree that this could be tricky if it was on a street truck. Mine is not that. I'm not sure its seen 15 mph since I finished the build.
@gunn Gotcha. One thing to keep in mind, different materials used for parking lot surfaces and speed bumps will have different thermal properties so a reading of x might mean something is y away and a second later the same distance is represented by a reading of z. This will work much more reliably with sonic. Are you old enough to remember Polaroid cameras? The focusing sensor in them is what many robots use for obstacle avoidance sensors. IIRC, the signal returned can be programatically analyzed for distance but that is my gut talking, I haven't used them. Just search YT for "robot avoidance sensor"
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@zander great! I'll be on that after work today. I do remember the Polaroid cameras but was to young to appreciate the functionality of them. Just wanted to shake the picture. That said, are they as easy to adjust the "trigger" hight as the ir sensors (pot on board)? I'd definitely give them a shot. And would that change the code since I'm basically using it for a switch?
@gunn I don't think the code would change much. Since you already have the IR solution all set up, you should check what I said in the real world. I am just applying common sense engineering.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@zander if you wouldn't mind, give my code a once over maybe help correct syntax and see if I'm on the right track. I've spent about 100 hours watching videos from tons of great instructional channels. But like all babies, new languages are not mastered in hours alone. //input pins
const int lfp = 52;
const int rfp = 53;
const int lrp = 50;
const int rrp = 51;
const int lfd = 48;
const int rfd = 46;
const int lrd = 49;
const int rrd = 47;
const int ir1 = 44;
const int ir2 = 45;
const int ir3 = 42;
const int ir4 = 43;
const int ir5 = 40;
const int ir6 = 41;
const int ir7 = 38;
const int ir8 = 39;
const int ir9 = 36;
const int ir10 = 37;
// output pins
const int lfpmc = 34;
const int rfpmc = 35;
const int lrpmc = 32;
const int rrpmc = 33;
const int lfdmc = 30;
const int rfdmc = 31;
const int lrdmc = 28;
const int rrdmc = 29;
void setup() {
pinMode (28,OUTPUT);
pinMode (29,OUTPUT);
pinMode (30,OUTPUT);
pinMode (31,OUTPUT);
pinMode (32,OUTPUT);
pinMode (33,OUTPUT);
pinMode (34,OUTPUT);
pinMode (35,OUTPUT);
pinMode (36,INPUT);
pinMode (37,INPUT);
pinMode (38,INPUT);
pinMode (39,INPUT);
pinMode (40,INPUT);
pinMode (41,INPUT);
pinMode (42,INPUT);
pinMode (43,INPUT);
pinMode (44,INPUT);
pinMode (45,INPUT);
pinMode (46,INPUT);
pinMode (47,INPUT);
pinMode (48,INPUT);
pinMode (49,INPUT);
pinMode (50,INPUT);
pinMode (51,INPUT);
pinMode (52,INPUT);
pinMode (53,INPUT);
}
const int Read_ir = digitalRead ir1; digitalRead ir2; digitalRead ir3; digitalRead ir4; digitalRead ir5; digitalRead ir6; digitalRead ir7; digitalRead ir8; digitalRead ir9; digitalRead ir10;
void loop() {
digitalRead ir1;
while (ir1 = LOW) {digitalWrite lfdmc = LOW && digitalWrite lfpmc = HIGH; digitalRead ir1}
else {digitalWrite lfpmc = LOW}
digitalRead ir2;
while (ir2 = LOW) {digitalWrite rfdmc = LOW && digitalWrite rfpmc = HIGH; digitalRead ir2}
else {digitalWrite rfpmc = LOW}
digitalRead ir3;
while (ir3 = LOW) {(digitalWrite lrdmc = LOW) && (digitalWrite lrpmc = HIGH); digitalRead ir3}
else {digitalWrite lrpmc = LOW}
digitalRead ir4;
while (ir4 = LOW) {(digitalWrite rrdmc = LOW) && (digitalWrite rrpmc = HIGH); digitalRead ir4}
else {digitalWrite rrpmc = LOW}
digitalRead ir5;
while (ir5 = LOW) {(digitalWrite lfdmc = LOW) && (digitalWrite rfdmc = LOW) && (digitalWrite lfpmc = HIGH) && (digitalWrite rfpmc = HIGH); digitalRead ir5}
else {digitalWrite lfpmc = LOW && rfpmc = LOW}
digitalRead ir6;
while (ir6 = LOW) {(digitalWrite lrdmc = LOW) && (digitalWrite rrdmc = LOW) && (digitalWrite lrpmc = HIGH) && (digitalWrite rrpmc = HIGH); digitalRead ir6}
else {digitalWrite lrpmc = LOW && digitalWrite rrpmc = LOW}
digitalRead ir7; digitalRead ir9;
while (ir7 = LOW || ir9 = LOW) {(digitalWrite lfdmc = LOW) && (digitalWrite lrdmc = LOW) && (digitalWrite lfpmc = HIGH) && (digitalWrite lrpmc = HIGH); digitalRead ir7; digitalRead ir9;}
else {digitalWrite lfpmc = LOW && digitalWrite lrpmc = LOW}
digitalRead ir8; digitalRead ir10;
while (ir8 = LOW || ir10 = LOW) {(digitalWrite rfdmc = LOW) && (digitalWrite rrdmc = LOW) && (digitalWrite rfpmc = HIGH) && (digitalWrite rrpmc = HIGH); (digitalRead ir8); (digitalRead ir10);}
else {digitalWrite rfpmc && rrpmc = LOW}
Read_ir;
if() (lfd = HIGH) && (ir1 = LOW) || (ir7 = LOW) || (ir5 =LOW);
{digitalWrite lfdmc = LOW};
else if (lfd = HIGH) && (ir1 = HIGH) && (ir7 = HIGH) && (ir5 = HIGH);
{digitalWrite lfdmc = HIGH; digitalRead lfd; Read_ir;}
Read_ir;
if() (rfd = HIGH) && (ir2 = LOW) || (ir8 = LOW) || (ir5 = LOW);
{digitalWrite rfdmc = LOW};
else if (rfd = HIGH) && (ir1 = HIGH) && (ir7 = HIGH) && (ir5 = HIGH);
{digitalWrite rfdmc = HIGH; digitalRead rfd; Read_ir;}
Read_ir;
if() (lrd = HIGH) && (ir3 = LOW) || (ir9 = LOW) || (ir6 = LOW);
{digitalWrite lrdmc = LOW};
else if (lrd = HIGH) && (ir3 = HIGH) && (ir9 = HIGH) && (ir6 = HIGH);
{digitalWrite lrdmc = HIGH; digitalRead lrd; Read_ir}
Read_ir;
if() (rrd = HIGH) && (ir4 = LOW) || (ir10 = LOW) || (ir6 = LOW);
{digitalWrite rrdmc = LOW};
else if (rrd = HIGH) && (ir1 = HIGH) && (ir7 = HIGH) && (ir6 = HIGH);
{digitalWrite lfdmc = HIGH; digitalRead rrd; Read_ir};
if() (lfp = HIGH); {digitalWrite lfpmc = HIGH};
else {digitalWrite lfpmc = LOW};
if() (rfp = HIGH); {digitalWrite rfpmc = HIGH};
else {digitalWrite rfpmc = LOW};
if() (lrp = HIGH); {digitalWrite lrpmc = HIGH};
else() (digitalWrite lrpmc = LOW};
if() (rrp = HIGH); {digitalWrite rrpmc = HIGH};
else() {digitalWrite rrpmc = LOW};
}}
Example: r= right or rear, l= left, f= front, p= pump, d= dump, mc= motor controller (relay), ir= infrared. I'm replacing the switch box that came in the bag kit so the dump will stop if the truck is too close to an obstacle when lowering and switch will not work when ir is active.
@gunn I will let one of the other guys look at it, I don't have the time right now.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@robotbuilder i wrote it based on many example videos i watched. Its not finished as far as I can tell, could stand to be shortened by someone with better skills than me. Its basically the first draft.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@zander if you wouldn't mind, give my code a once over maybe help correct syntax and see if I'm on the right track. I've spent about 100 hours watching videos from tons of great instructional channels. But like all babies, new languages are not mastered in hours alone.
The code you include in this message will not be usable by either the compiler nor the other members of the forum. The code you write is intended to tell the compiler what operations you wish to perform on what assets and in what order., so they need to be clearly presented and that means that you need to be clear in your own mind what you intend to do and how you intend to do it.
From your other replies, it seems that you have never written any code before for the Arduino or anything else, so we can start at the beginning.
Writing a program requires that yo analyze your particular program, decide what information you will need, decide how to collect that information and then decide how to use it to effect your final product. You'll then present the compiler with a sequenced list of statements and commands which will cause it to collect your information, process it according to your instructions and then cause an output in some form that meets your requirements.
However, the compiler is very limited and requires that all statements and commands be structured in a very precise manner. As this appears to be your first foray into programming, it's not surprising that the commands you input are not acceptable to the compiler.
It appears that you have read and understood the parts about declaring the pins that you'll be using (the "const int xx = 99" statements) so well done on that.
You have also done a creditable job on declaring the pins as INPUT and OUTPUT. The comment from others about using INPUT_PULLUP refers to the capability of the Arduino to insert a 10K pulp resistor into the circuit for any pins declared as INPUT. What this does is effectively tie the pin to 5V so that it will always read HIGH unless specifically connected to GND. This is most useful in buttons and switches where the button is connected on one side to a pin and on the other side to GND, so that the pin will be dragged to LOW when the button is pressed.
However, thereafter the compiler is unable to interpret most of your commands because you're not using an acceptable (to the compiler) former the command.
For instance, according to the Arduino reference for digitalWrite() (at https://www.arduino.cc/reference/en/language/functions/digital-io/digitalwrite/) the command format is ...
digitalWrite(pin, value);
whereas you are using "digitalWrite lfpmc = LOW && digitalWrite lrpmc = LOW"
Similarly for digitalRead (at https://www.arduino.cc/reference/en/language/functions/digital-io/digitalread/) the command format is
value = digitalRead(pin);
whereas you are using "digitalRead ir2;"
Similarly for the while command (at https://www.arduino.cc/reference/en/language/structure/control-structure/while/ the format is
while (logical condition) {
// Statements to execute
}
Note here that the brace brackets are only needed if MORE THAN ONE statement is required.
whereas you are using
while (ir1 = LOW) {digitalWrite lfdmc = LOW && digitalWrite lfpmc = HIGH; digitalRead ir1}
else {digitalWrite lfpmc = LOW}
digitalRead ir2;
Not only are there loose statements not included in the brackets, but you've introduced an extraneous "else" which is not even in an if statement.
The proper form for an "else" (at https://www.arduino.cc/reference/en/language/structure/control-structure/else/ the format is
if (condition) {
// Handle statements for case condition=true
} else if (another_condition) {
// Handle statements for case another_condition=true
} else {
// Handle case where NEITHER condition nor another_condition is true
}
Because your code is so different from the required structure, the compiler can't interpret it. Also, since the other members of the forum also expect the commands and statements to be in the same format as the compiler expects, we can't understand what you mean either.
So, we'll be mostly unable to help you until YOU rewrite the code in a more acceptable form. Don't hesitate to ask specific questions, but we probably won't be able to assist until the code is more explicit.
Anything seems possible when you don't know what you're talking about.
Hi @gunn,
I am sorry, but at present you do not seem to understand the basic syntax of a C/C++ program, and as such will find it very hard to make progress.
This may sound very harsh, but I honestly believe you will make faster progress in the long run if you take a step back and get some experience building, coding and modifying at least a few programs with a board some LEDs, switches and so on. You probably have enough hardware for some simple examples.
Bill on this forum has some excellent examples to try.
And there are others on the web, such as, Paul McWhorter AKA toptechboy has entire free courses
I think a few hours working through some of the simpler examples will easily repay the investment in time.
If when you try one, but maybe get stuck or don't understand something, then by all means start a new quetion thread ... giving all of the information that someone will need to understand your position, as well as your query.
Note, just watching videos will probably get you nowhere ... you might as well watch a gangster film ... you have to actually do it yourself, type the code, don't copy and paste, play with the code, make small changes and so on. You don't learn by just watching someone else ... you learn by making mistakes and fixing them!
Please note, I do not wish to be dispiriting and I wish you luck with your project.