It is currently Sat Nov 28, 2020 12:42 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Arduino’s map() Function
PostPosted: Fri Apr 10, 2020 6:46 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jul 07, 2013 11:35 am
Posts: 579
Location: Canada
Hello everyone,

While I'm working on Steering behaviors "Arrival" I have found a video explaining it (See https://www.youtube.com/watch?v=2CL1maXeQCI). It use a Map() function to calculate the speed reduction in relation to the distance to the target point. After some research I have found an implementation that I have converted into a Macro for PB.

Code:
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : MappingValues
; File Name : MappingValues.pb
; File version: 1.0.0
; Programming : OK
; Programmed by : StarBootics
; Date : 10-04-2020
; Last Update : 10-04-2020
; PureBasic code : V5.72
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Programming notes
;
; Based on a code found here :
;
; https://www.jetmore.org/john/blog/2011/09/arduinos-map-function-and-numeric-distribution/
;
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Macro MappingValues(x, in_min, in_max, out_min, out_max)

  ((x - (in_min)) * ((out_max) - (out_min)) / ((in_max) - (in_min)) + (out_min))
 
EndMacro

CompilerIf #PB_Compiler_IsMainFile
 
  For Index = 0 To 100
    Debug StrF(MappingValues(Index, 0.0, 100.0, 0.0, 15.0), 4)
  Next
 
CompilerEndIf

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<


Best regards
StarBootics

_________________
The Stone Age did not end due to a shortage of stones !


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 30 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye