Memory handling for a simulated robot sensor

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK NO HELP I WONDER WHY THIS ISSDDADSSDASDC ANDDNOYING WRDJDLWEAMFDADWDD

Last Edited: Tue. Oct 6, 2020 - 11:47 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why do you need to store all readings?

Don't you just want to keep track of the minimum value and the angle at which they occurred?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes i do but im not sure how to do it without storing the values since i need to store and convert from string to float to read and compare them

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
     String incomingByte = Serial.readString();
     IRvalue[m] = incomingByte.toFloat();

Two things:

 

1) incomingByte is a pretty dreadful name for this - it's not really a "byte" - it's a variable number of bytes.

 

2) Why do you need it inside the for() loop anyway. You just need one instance of incomingByte that you keep re-using. Once you have taken the float out of it simply clear it for next time ( incomingByte.clear() ), actually create it outside the for() loop.

 

Like Kartman I wonder why you store all the floats then look for min/max later ? You can do all that as you go along receiving the things. Same goes for testing below 25. Also as a reader of this code I have no idea what the significance of the value 25 us anyway. You might want to add a comment to tell the reader why that value and what units it is in perhaps?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

SOLVED THANK BROTHER  FROM THY OTHER MOTHER :)(dmeifnd

Last Edited: Tue. Oct 6, 2020 - 11:47 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

jazzamate wrote:
Is there any better way of reading serial numbers quickly? 
The "Long work" is probably not the reception time - that is simply dictated by the baud rate and a handful of cycles to then collect the inbound bytes - it's probably the actual float conversion that takes a long time. Can't you get the "other end" to preprocess the data and send integer in the first place (if it's a more powerful PC it will take the heavy work away from the AVR). Better yet you might be able to send binary not ASCII so no ascii-to-float or even ascii-to-int conversion is needed at the AVR end at all.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why are you using float?????  That seems a bit ridiculous or poor planning.  Pay attention.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jazzamate wrote:
and serial.readstrings timeout function

 

You can reduce this with: https://www.arduino.cc/reference.... The timeout is only really useful if it's a human typing the characters. Or use: https://www.arduino.cc/reference...

 

Arduino String objects are trainer wheels. Horribly inefficient and memory hungry, but useful until you learn how do things 'properly' with chars and C-style char arrays.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

obdevel wrote:
Arduino String objects are trainer wheels.

they seem to be (somewhat) different from standard C++ strings: https://www.avrfreaks.net/commen... ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Yes: https://github.com/arduino/Ardui...

 

There is some attempt to minimise memory reallocation and fragmentation, with a method to reserve a buffer: https://www.arduino.cc/reference...

 

Of course, it's easy to take potshots at Arduino and we should remember the original purpose and target audience for the project, regardless of how that has changed over the years.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am a bit puzzled about what the OP means by "simulated robot sensor". Is the sensor  simulated? Is the robot simulated? From the postings, it sound like there is real hardware, not simulated.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!