Help in flags for python
Hi all, I am new to Python programming and I being tasked to create codes by my supervisor but I have no clue how to.
I am doing a project on robots for my internship and he asked me to implement flags for different kind of 'modes' on the robot. He told me to add the flags in front line 5 so that the 'modes' can be easily detected. Example of a mode being like 'Manual Driving'.
def callback(self, vel):
x = format(vel.linear.x, '+.2f')
z = format(vel.angular.z, '+.2f')
##############################
pck = b':' + x + b',' + z
rospy.loginfo("Data Transmitting %s", pck)
# Check the number of bytes to fit the format
# b':+X.XX,+X.XX' => 12bytes ;)
This is what I am given. Any help would be greatly appreciated! :)
Hi @kamui123, what are you trying to do in this instruction:
pck = b':' + x + b',' + z
. That wil not be interpreted properly by any python interpreter. Does your flags depend on the robot velocity? Why are you using as a check methond the number of bytes? If you want some flags you can just read the callback msg use a global variable to store the "mode" and then use this global variable in yourmain
.@Weasfas if I am not wrong, that instruction is to package the command to format <magnitude><angular>
@kamui123, that line must be converted in something like:
That will give literally:
b':+X.XX,+X.XX'
and will not contain 12 bytes but 45. In fact the size will only depend on the integer part of the inputs, so my doubt is why you want to decode the inputs to produce in-flag codes like that when you can have an input flag (1,2,3 or "Auto', 'Manual', etc.) that generates the operating mode on your system.@Weasfas I am very sorry, I am new to Python programming and these codes is not done by me. It was from previous batch of interns. That's why I resorted to forums to ask for help. How do you go about implementing flags? Could you give me an example?