PureBasic Forum http://forums.purebasic.com/english/ |
|
Arduino’s map() Function http://forums.purebasic.com/english/viewtopic.php?f=12&t=75071 |
Page 1 of 1 |
Author: | StarBootics [ Fri Apr 10, 2020 6:46 pm ] |
Post subject: | Arduino’s map() Function |
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 |
Page 1 of 1 | All times are UTC + 1 hour |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |