BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Fri Oct 19, 2018 9:50 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Signed verus Unsigned values in Arduino Library
PostPosted: Tue Sep 16, 2014 6:53 am 
Offline
Citizen

Joined: Sun Oct 20, 2013 5:22 am
Posts: 16
It seems like all the 'signed' functions in the Arduino library take "unit_32" as values.

For example:
Code:
bool SpeedM1(uint8_t address, uint32_t speed);

Sending 'negative' values to this function is supposed to run the motor backwards according to the manual:

Quote:
35 - Drive M1 With Signed Speed
Drive M1 using a speed value. The sign indicates which direction the motor will turn. This command is used to drive the motor by quad pulses per second. Different quadrature encoders will have different rates at which they generate the incoming pulses. The values used will differ from one encoder to another.


But the header files for all the functions that should take signed values are cast as unsigned ints. ????

So which is it? The Arduino library is incorrect (all 'uint's should be 'ints') or the Manual is incorrect and we shouldn't send negative values to the various methods?

Should we simply 'find-and-replace' 'unit_32' with 'int_32' (or 'long' for Arduino 32bit signed ints) in the relative code or leave it alone?


Top
 Profile  
 
 Post subject: Re: Signed verus Unsigned values in Arduino Library
PostPosted: Tue Sep 23, 2014 4:20 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 7:00 pm
Posts: 1316
Location: Temecula, CA
A signed variable is not converted in any way when put in an unsigned argument. An unsigned argument is a safe place to store the users value before it is broken up into bytes to be transmitted to the roboclaw. So whether the function takes a signed value(eg speed) or not the functions in the library used unsigned variable storage so no unforeseen conversions will take place.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 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
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO