答:
There are a few tests that will help in this sort of situation.  Try either of these.

Test 1.  Get a logic probe (a simple low-cost device that will serve you for many years!) and use it carefully on the L293D.  Test each of the two Enable pins and each of the four Input pins, and make sure each of those pins reads either High or Low as you would expect.  This is the most certain way to find a poor connection or incorrect wires.

(Note about the logic probe: always make sure the probe tip is placed centrally and firmly on top of the IC pin you are testing; if you slip sideways and "short" the probe tip between two pins, you could damage an output pin on the Raspberry Pi, depending on the situation.)

Test 2.  First disconnect the Raspberry Pi completely and put it aside.  Take the wires that go to the motor controller inputs, and physically connect each of these to power, either zero volts or the VCC connection.  You are effectively sending the signals by hand instead of by software. If the motor now works as expected, then perhaps your Raspberry Pi has a damaged output pin.  If not, either you have misunderstood the connections of there is a problem with the driver.

(As you probably don't have a logic prove, I suggest you at least try test 2 in the first instance. That alone will probably help.)

Title: L293D won't turn motor backwards

Body:
My small robot has two motors controlled by an L293D and that is controlled via a Raspberry Pi. They will both go forwards but only one will go backwards.

I've tried different motors and tried different sockets in the breadboard, no luck. Either the L293D's chip is broken (but then it wouldn't go forwards) or I've wired it wrong.

I followed the tutorial, Controlling DC Motors Using Python With a Raspberry Pi, exactly.

Here is a run down of what works. Let the 2 motors be A and B:

When I use a python script (see end of post) both motors go "forwards". When I change the values in the Python script, so the pin set to HIGH and the pin set to LOW are swapped, motor A will go "backwards", this is expected. However, motor B will not move at all.

If I then swap both motors' wiring then the original python script will make both go backwards but swapping the pins in the code will make motor A go forwards but motor B won't move.

So basically, motor A will go forwards or backwards depending on the python code but motor B can only be changed by physically changing the wires.

This is forwards.py

```<code>import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BOARD)

Motor2A = 23
Motor2B = 21
Motor2E = 19

Motor1A = 18
Motor1B = 16
Motor1E = 22

GPIO.setup(Motor1A, GPIO.OUT)
GPIO.setup(Motor1B, GPIO.OUT)
GPIO.setup(Motor1E, GPIO.OUT)

GPIO.setup(Motor2A, GPIO.OUT)
GPIO.setup(Motor2B, GPIO.OUT)
GPIO.setup(Motor2E, GPIO.OUT)

print("ON")
GPIO.output(Motor1A, GPIO.HIGH)
GPIO.output(Motor1B, GPIO.LOW)
GPIO.output(Motor1E, GPIO.HIGH)

GPIO.output(Motor2A, GPIO.HIGH)
GPIO.output(Motor2B, GPIO.LOW)
GPIO.output(Motor2E, GPIO.HIGH)
</code>```

And this is backwards.py

```<code>import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BOARD)

Motor2A = 21
Motor2B = 23
Motor2E = 19

Motor1A = 16
Motor1B = 18
Motor1E = 22

GPIO.setup(Motor1A, GPIO.OUT)
GPIO.setup(Motor1B, GPIO.OUT)
GPIO.setup(Motor1E, GPIO.OUT)

GPIO.setup(Motor2A, GPIO.OUT)
GPIO.setup(Motor2B, GPIO.OUT)
GPIO.setup(Motor2E, GPIO.OUT)

print("ON")
GPIO.output(Motor1A, GPIO.HIGH)
GPIO.output(Motor1B, GPIO.LOW)
GPIO.output(Motor1E, GPIO.HIGH)

GPIO.output(Motor2A, GPIO.HIGH)
GPIO.output(Motor2B, GPIO.LOW)
GPIO.output(Motor2E, GPIO.HIGH)
</code>```

If you see this diff https://www.diffchecker.com/skmx6084, you can see the difference:

Below are some pictures. You can use the colour of the cables to link them between pictures

enter image description here


问:
Determine robot's position in a nearby room
Scenario

I have 2 roaming robots, each in different rooms of a house, and both robots are connected to the house wifi. Each robot only has access to the equipment on itself.

Question

How can the robots be aware of each other's exact position using only their own equipment and the house wifi?

EDIT: Additional Info

Right now the robots only have:

RGBDSLAM via Kinect

No initial knowledge of the house or their location (no docks, no mappings/markings, nada)

Can communicate via wifi and that part is open ended

I'm hoping to be able to stitch the scanned rooms together before the robots even meet. Compass + altimeter + gps will get me close but the goal is to be within an inch of accuracy which makes this tough. There IS freedom to add whatever parts to the robots themselves / laptop but the home needs to stay dynamic (robots will be in a different home every time).

答:
Basically you can utitilize one global frame for both robots since each robot has its own SLAM. SLAM provides an estimate for a robot's pose (i.e. location and direction). If you unify the global frame for both SLAMs, then you can determine the poses of the two robots. I've drawn a picture to illustrate my approach.

As you can see from the above picture, two robots are placed in one global frame. Once they start running, there is one landmark in this picture. Each SLAM will utilize this landmark to estimate the robot's pose, therefore, since the robots can communicate with each other, each robot can have an estimate for the other robot's pose.

ContentLicense: CC BY-SA 3.0


问:
it's worth to make a line follower using a raspberry pi and a web cam?
I wonder if this would be a competitive robot compared with one made with a traditional approach using a microcontroller and infrared sensors. I suppose that raspberry can perform an edge detection to tell the dynamic of the line far away, much more that the infrared sensor, but how fast can the raspberry do this process? should be a relative simple process in terms of computational requirements , an edge detection in a high contrast arena. Probably the bigger issue would be get the relative position of the robot respect to the line, may be a combination of the camera with some infrared sensors would work better, and what about the size? the robot will be significantly bigger when is used a camera and a raspberry for the control.</p>

答: I did a project based on RPi2 + Pi-Camera + ROS jade + OpenCV to make a line following rover. Two methods are used, one is to find contour of the track, the other is to use Hough-transform for edge detection. Under well-controlled environment (even light sources, less noises, etc.) the performance is good, and I use RANSAC to find preferred edges under noisy environment. Pi-Camera is set to capture 320x240 RGB in 30fps. I overclock my RPi2 to 1.0Ghz, finding contour can process frames in 18-23 fps, and hough-transform is about 17fps (in a bit noisy environment.) For these two methods, Canny filter and Hough transform is the major bottleneck. I built this as a test platform, a cheap rover chassis is used with 2 geared DC motors. My codes in github: https://github.com/alexhuang888/roscar</p>


问:
PID Tuning for an Unbalanced Quadcopter: When do I know if the I-gain I've set is too high?
Good day,

I am working on an autonomous flight controller for a quadcopter ('X' configuration) using only angles as inputs for the setpoints used in a single loop PID controller running at 200Hz (PID Implementation is Here: Quadcopter PID Controller: Derivative on Measurement / Removing the Derivative Kick). For now I am trying to get the quadcopter to stabilize at a setpoint of 0 degrees. The best I was able to come up with currently is +-5 degrees which is bad for position hold. I first tried using only a PD controller but since the quadcopter is inherently front heavy due to the stereo cameras, no amount of D or P gain is enough to stabilize the system. An example is the image below which I added a very small I gain:

As you can see from the image above (at the second plot), the oscillations occur at a level below zero degrees due to the quadcopter being front heavy. This means that the quad oscillates from the level postion of 0 degrees to and from a negative angle/towards the front. To compensate for this behaviour, I discovered that I can set the DC level at which this oscillations occur using the I gain to reach the setpoint. An image is shown below with [I think] an adequate I gain applied:

I have adjusted the PID gains to reduce the jitters caused by too much P gain and D gain. These are my current settings (Which are two tests with the corresponding footage below):

Test 1: https://youtu.be/8JsraZe6xgM

Test 2: https://youtu.be/ZZTE6VqeRq0

I can't seem to tune the quadcopter to reach the setpoint with at least +-1 degrees of error. I noticed that further increasing the I-gain no longer increases the DC offset.

When do I know if the I-gain I've set is too high? How does it reflect on the plot?

EDIT:
The Perr in the graphs are just the difference of the setpoint and the CF (Complementary Filter) angle.
The Derr plotted is not yet divided by the deltaTime because the execution time is small ~ 0.0047s which will make the other errors P and I hard to see.
The Ierr plotted is the error integrated with time.

All the errors plotted (Perr, Ierr, Derr) are not yet multiplied by the Kp, Ki, and Kd constants

The 3rd plot for each of the images is the response of the quadcopter. The values on the Y axis correspond to the value placed as the input into the gpioPWM() function of the pigpio library. I had mapped using a scope the values such that 113 to 209 pigpio integer input corresponds to 1020 to 2000ms time high of the PWM at 400Hz to the ESC's

EDIT:

Here is my current code implementation with the setpoint of 0 degrees:

```<code>cout << "Starting Quadcopter" << endl;

float baseThrottle = 155; //1510ms
float maxThrottle = 180; //This is the current set max throttle for the PITCH YAW and ROLL PID to give allowance to the altitude PWM. 205 is the maximum which is equivalent to 2000ms time high PWM
float baseCompensation = 0; //For the Altitude PID to be implemented later

delay(3000);

float startTime=(float)getTickCount();
deltaTimeInit=(float)getTickCount(); //Starting value for first pass

while(1){
//Read Sensor Data
readGyro(&gyroAngleArray);
readAccelMag(&accelmagAngleArray);

//Time Stamp
//The while loop is used to get a consistent dt for the proper integration to obtain the correct gyroscope angles. I found that with a variable dt, it is impossible to obtain correct angles from the gyroscope.

while( ( ((float)getTickCount()-deltaTimeInit) / ( ((float)getTickFrequency()) ) ) < 0.005){ //0.00209715|0.00419
       deltaTime2=((float)getTickCount()-deltaTimeInit)/(((float)getTickFrequency())); //Get Time Elapsed
       cout << " DT endx = " << deltaTime2 << endl;
}
//deltaTime2=((float)getTickCount()-deltaTimeInit)/(((float)getTickFrequency())); //Get Time Elapsed
deltaTimeInit=(float)getTickCount(); //Start counting time elapsed
cout << " DT end = " << deltaTime2 << endl;

//Complementary Filter
float pitchAngleCF=(alpha)*(pitchAngleCF+gyroAngleArray.Pitch*deltaTime2)+(1-alpha)*(accelmagAngleArray.Pitch);
float rollAngleCF=(alpha)*(rollAngleCF+gyroAngleArray.Roll*deltaTime2)+(1-alpha)*(accelmagAngleArray.Roll);
float yawAngleCF=(alpha)*(yawAngleCF+gyroAngleArray.Yaw*deltaTime2)+(1-alpha)*(accelmagAngleArray.Yaw);

//Calculate Orientation Error (current - target)
float pitchError = pitchAngleCF - pitchTarget;
pitchErrorSum += (pitchError*deltaTime2);
float pitchErrorDiff = pitchError - pitchPrevError;
pitchPrevError = pitchError;

float rollError = rollAngleCF - rollTarget;
rollErrorSum += (rollError*deltaTime2);
float rollErrorDiff = rollError - rollPrevError;
rollPrevError = rollError;

float yawError = yawAngleCF - yawTarget;
yawErrorSum += (yawError*deltaTime2);
float yawErrorDiff = yawError - yawPrevError;
yawPrevError = yawError;

//PID controller list
float pitchPID = pitchKp*pitchError + pitchKi*pitchErrorSum + pitchKd*pitchErrorDiff/deltaTime2;
float rollPID = rollKp*rollError + rollKi*rollErrorSum + rollKd*rollErrorDiff/deltaTime2;
float yawPID = yawKp*yawError + yawKi*yawErrorSum + yawKd*yawErrorDiff/deltaTime2;

//Motor Control - Mixing
//Motor Front Left (1)
float motorPwm1 =  -pitchPID + rollPID - yawPID + baseThrottle + baseCompensation;

//Motor Front Right (2)
float motorPwm2 =  -pitchPID - rollPID + yawPID + baseThrottle + baseCompensation;

//Motor Back Left (3)
float motorPwm3 = pitchPID + rollPID + yawPID + baseThrottle + baseCompensation;

//Motor Back Right (4)
float motorPwm4 = pitchPID - rollPID - yawPID + baseThrottle + baseCompensation;

 //Check if PWM is Saturating - This method is used to fill then trim the outputs of the pwm that gets fed into the gpioPWM() function to avoid exceeding the earlier set maximum throttle while maintaining the ratios of the 4 motor throttles.
    float motorPWM[4] = {motorPwm1, motorPwm2, motorPwm3, motorPwm4};
    float minPWM = motorPWM[0];
    int i;
    for(i=0; i<4; i++){ // Get minimum PWM for filling
        if(motorPWM[i]<minPWM){
            minPWM=motorPWM[i];
        }
    }

    cout << " MinPWM = " << minPWM << endl;

    if(minPWM<baseThrottle){
        float fillPwm=baseThrottle-minPWM; //Get deficiency and use this to fill all 4 motors
        cout << " Fill = " << fillPwm << endl;
        motorPwm1=motorPwm1+fillPwm;
        motorPwm2=motorPwm2+fillPwm;
        motorPwm3=motorPwm3+fillPwm;
        motorPwm4=motorPwm4+fillPwm;
    }

    float motorPWM2[4] = {motorPwm1, motorPwm2, motorPwm3, motorPwm4};
    float maxPWM = motorPWM2[0];
    for(i=0; i<4; i++){ // Get max PWM for trimming
        if(motorPWM2[i]>maxPWM){
            maxPWM=motorPWM2[i];
        }
    }

    cout << " MaxPWM = " << maxPWM << endl;

    if(maxPWM>maxThrottle){
        float trimPwm=maxPWM-maxThrottle; //Get excess and use this to trim all 4 motors
        cout << " Trim = " << trimPwm << endl;
        motorPwm1=motorPwm1-trimPwm;
        motorPwm2=motorPwm2-trimPwm;
        motorPwm3=motorPwm3-trimPwm;
        motorPwm4=motorPwm4-trimPwm;
    }

//PWM Output
    gpioPWM(24,motorPwm1);  //1
    gpioPWM(17,motorPwm2);  //2
    gpioPWM(22,motorPwm3);  //3
    gpioPWM(18,motorPwm4);  //4
</code>```

答:
What does your code look like that you use to calculate your errors? I had suggestions to revise your code, but you're just linking back to your earlier questions so I don't know if that's current or not.

If you are calculating your error terms correctly, you could try an experimental tuning method like Ziegler-Nichols, but again, this relies on your error terms to be calculated correctly.

In general, the integral term is used to "accumulate" error such that there is ultimately no steady state error. If the integral gain is too low then it will take a long time to reach (near) zero steady state error, but if it's too high then you will experience overshoot and oscillations as your controller overreacts to minor error accumulation.


问:
Software real-time of ROS system
As far as I know, a hardware real-time robot control system requires a specific computing unit to solve the kinematics and dynamics of a robot such as interval zero RTX, which assigns CPU cores exclusively for the calculation, or a DSP board, which does exactly the same calculation. This configuration makes sure that each calculation is strictly within, maybe, 1 ms.

My understanding is that ROS, which runs under Ubuntu, doesn't have a exclusive
computing unit for that. Kinematics and dynamics run under different threads of the same CPU which operates the Ubuntu system, path plan, and everything else.

My question is that how does ROS achieve software-real time? Does it slow down the sampling time to maybe 100ms and makes sure each calculation can be done in time? Or the sampling time changes at each cycle maybe from 5ms, 18ms, to 39ms each time in order to be as fast as possible and ROS somehow compensates for it at each cycle?

答:
Short answer: it doesn't compensate at all.

ROS is generally not considered a real-time OS. You usually need specialized hardware and software to implement a real-time OS. The communication line and bus needs to be specifically designed to minimize lag, and the software needs to be written to be 'clock centric'. A real-time OS is built to do things at certain times, not to do as many calculations as it can in a certain amount of time. Unless you're running ROS on a real-time variant of Linux, and on hardware designed to operate with it, ROS won't operate in real time. Even then, you would probably have to modify or redesign ROS and the packages you want to use to operate primarily by the clock, instead of 'at their leisure'

Generally, you do not need an real-time OS for robotics. Usually, you only see it in aerospace applications, specifically rocket motor control. Getting from point A to point B using a rocket motor requires split second timing. If the motor goes for even a half second too long or too short, it will miss it's target velocity (and so, overshoot or undershoot it's target). Robots do not usually require this level accuracy in timing. We're more concerned about our creations doing it right, instead of doing it fast.

Title: Software real-time of ROS system


问:
Optimal location of the center of mass for an inverted pendulum
I'm building an inverted pendulum to be controlled by DC motors, but I've run across a conundrum.  Personal life experience tells me that it's better to have a lower center of mass to maintain balance.  On the other hand, the greater the moment of inertia (e.g. the higher the center of mass), the easier it is to maintain balance as well.

These two views both seem plausible, and yet also seem contradictory.   For an inverted pendulum, is there an optimal balance between the two perspectives?  Or is one absolutely right while the other absolutely wrong?  If one is wrong, then where is the error in my thinking?

答:
You can answer this by considering the equations of motion of an inverted pendulum:  $$\ddot{\Theta} = \frac{g}{l} \sin(\Theta)$$

If you agree that the easiest system to control is that which has the smallest $\ddot \Theta$ for you to compensate, then you have three options:

Control the pendulum on the moon to lower $g$

Keep the pendulum close to $\Theta = 0$, because $\sin(\Theta) \rightarrow \Theta$ for small values of $\Theta$.

Make $l$ as large as possible.  $l$ is the distance to the center of mass along the link.


答:
Lower centers of mass are more stable, but an inverted pendulum is inherently unstable; any perturbation will set it off.

The height to center of mass depends on how much track you have available, your reaction time, how you're measuring displacement/force, etc.

:EDIT:

To elaborate on my statement above, say you're estimating pendulum position by the reaction force on the carriage, where the force on the carriage is

$$F_{\mbox{reaction}} = (mg)L\sin{\theta}$$

Well, in that instance, if the reaction force is constant (say you're evaluating the minimum detectable force), then the angle associated with that force declines as the pendulum length $L$ increases.

Similarly, if you've got a rotary/angular encoder that has some minimum detectable angle, then the reaction force that puts on your carriage increases as the pendulum length increases.

In addition to the minimum detectable cases, consider the kinetic energy of the pendulum. This is an inverted pendulum, so the portion of the potential energy that is converted to kinetic energy is given by:

$$ \mbox{KE} = \mbox{PE}_{\mbox{initial}} -  \mbox{PE}_{\mbox{final}} \\
\mbox{KE} = mgL - mgL\cos{\theta} \\
\mbox{KE} = (mg)*L(1-\cos{\theta}) \\
$$

(All of this assumes $\theta=0$ when the pendulum is vertical, by the way, just in case there's any confusion)

So, here again, for a constant $\theta$, the longer the pendulum length is the more kinetic energy the pendulum has. Assuming that you are again considering the minimum detectable case, this means that the longer the pendulum length is, the more kinetic energy the system has before you get a chance to respond.

So now, in addition to the fact that you're traversing more track ($\Delta x = L\sin{\theta} \approx L\theta$), the pendulum also has a higher starting kinetic energy, which means now you have to take a larger control action to damp the motion and return to steady state.

So, in summary:

If you're measuring the angle of the pendulum directly, a shorter pendulum length would be preferred because it minimizes the kinetic energy of the pendulum by the time you detect motion.

If you're estimating the angle of the pendulum by measuring reaction force on the carriage, a longer pendulum length would be preferred because this corresponds to a smaller angle, which in turn corresponds to lower initial kinetic energy.

I made a short spreadsheet to generate some plots to show the differences:

Title: Optimal location of the center of mass for an inverted pendulum

Body:
I'm building an inverted pendulum to be controlled by DC motors, but I've run across a conundrum.  Personal life experience tells me that it's better to have a lower center of mass to maintain balance.  On the other hand, the greater the moment of inertia (e.g. the higher the center of mass), the easier it is to maintain balance as well.

These two views both seem plausible, and yet also seem contradictory.   For an inverted pendulum, is there an optimal balance between the two perspectives?  Or is one absolutely right while the other absolutely wrong?  If one is wrong, then where is the error in my thinking?


答:
The two views are not contradictory; they apply to two different situations, which you are treating as a single one.

Your personal experience about having a low center of mass applies to situations where there is a stable position -- a local minimum height for the center of mass.  For example, if you have a vase on a shelf, the height of the vase's center of mass (in relation to the width of its base) determines how far it can wobble from side to side without tipping over.  Shown here with trucks:

The wobbling of a vase represents the tendency of the vase's center of mass to return to that local minimum height. If it tips over too far, the center of mass will find a different (and undesirable) minimum height.

The inverted pendulum situation has no "stable" position -- no local minimum for the center of mass.  This shouldn't be surprising, because it rests on a single point.

So in the vase example, once the vase begins its inevitable fall, the height of the vase's center of mass affects how much time it will take to complete that movement.  In the case of the inverted pendulum, this affects how much time you have to correct for that undesired outcome.

So if either one of these is the "absolutely wrong" way to look at an inverted pendulum, it's the "resting in a stable position" situation.


答:
Based on the videos, it looks like the answer is, unfortunately, "the test setup you have might be insufficient to say one way or the other".

There is too much slack in the tethers to draw any meaningful conclusions about whether your code is doing the right thing.  The quadcopter seemed to be reacting somewhat correctly to the way it was being tugged by the ropes.  There were some moments where it looked incorrect as well, but they were not isolated enough to point to a specific logic error.

Spend some time on the quality and stability of your test setup so that you can rigidly constrain two axes while letting the other move freely.  (For example, disable one pair of motors and hang the quadcopter from strings around those propeller shafts.)  That will let you troubleshoot one axis at a time in a very reasonable way, and provide more accurate feedback on the correctness of your PID values.

Looking at your setup, another problem seems to be that you're attaching the tether too low and creating an "inverted pendulum" effect.  (See also, this question on quadcopter center of lift).

You need to create a mounting bracket for your tether that will rigidly mount it to the quadcopter body at the level of the center of lift that the propellers provide.  It would also help to use something structural (like a metal post vertically attached to a sturdy base), instead of just rope or wire.

Title: PID Tuning for an Unbalanced Quadcopter: When do I know if the I-gain I've set is too high?

Body:
Good day,

I am working on an autonomous flight controller for a quadcopter ('X' configuration) using only angles as inputs for the setpoints used in a single loop PID controller running at 200Hz (PID Implementation is Here: Quadcopter PID Controller: Derivative on Measurement / Removing the Derivative Kick). For now I am trying to get the quadcopter to stabilize at a setpoint of 0 degrees. The best I was able to come up with currently is +-5 degrees which is bad for position hold. I first tried using only a PD controller but since the quadcopter is inherently front heavy due to the stereo cameras, no amount of D or P gain is enough to stabilize the system. An example is the image below which I added a very small I gain:

As you can see from the image above (at the second plot), the oscillations occur at a level below zero degrees due to the quadcopter being front heavy. This means that the quad oscillates from the level postion of 0 degrees to and from a negative angle/towards the front. To compensate for this behaviour, I discovered that I can set the DC level at which this oscillations occur using the I gain to reach the setpoint. An image is shown below with [I think] an adequate I gain applied:

I have adjusted the PID gains to reduce the jitters caused by too much P gain and D gain. These are my current settings (Which are two tests with the corresponding footage below):

Test 1: https://youtu.be/8JsraZe6xgM

Test 2: https://youtu.be/ZZTE6VqeRq0

I can't seem to tune the quadcopter to reach the setpoint with at least +-1 degrees of error. I noticed that further increasing the I-gain no longer increases the DC offset.

When do I know if the I-gain I've set is too high? How does it reflect on the plot?

EDIT:
The Perr in the graphs are just the difference of the setpoint and the CF (Complementary Filter) angle.
The Derr plotted is not yet divided by the deltaTime because the execution time is small ~ 0.0047s which will make the other errors P and I hard to see.
The Ierr plotted is the error integrated with time.

All the errors plotted (Perr, Ierr, Derr) are not yet multiplied by the Kp, Ki, and Kd constants

The 3rd plot for each of the images is the response of the quadcopter. The values on the Y axis correspond to the value placed as the input into the gpioPWM() function of the pigpio library. I had mapped using a scope the values such that 113 to 209 pigpio integer input corresponds to 1020 to 2000ms time high of the PWM at 400Hz to the ESC's

EDIT:

Here is my current code implementation with the setpoint of 0 degrees:

```<code>cout << "Starting Quadcopter" << endl;

float baseThrottle = 155; //1510ms
float maxThrottle = 180; //This is the current set max throttle for the PITCH YAW and ROLL PID to give allowance to the altitude PWM. 205 is the maximum which is equivalent to 2000ms time high PWM
float baseCompensation = 0; //For the Altitude PID to be implemented later

delay(3000);

float startTime=(float)getTickCount();
deltaTimeInit=(float)getTickCount(); //Starting value for first pass

while(1){
//Read Sensor Data
readGyro(&gyroAngleArray);
readAccelMag(&accelmagAngleArray);

//Time Stamp
//The while loop is used to get a consistent dt for the proper integration to obtain the correct gyroscope angles. I found that with a variable dt, it is impossible to obtain correct angles from the gyroscope.

while( ( ((float)getTickCount()-deltaTimeInit) / ( ((float)getTickFrequency()) ) ) < 0.005){ //0.00209715|0.00419
       deltaTime2=((float)getTickCount()-deltaTimeInit)/(((float)getTickFrequency())); //Get Time Elapsed
       cout << " DT endx = " << deltaTime2 << endl;
}
//deltaTime2=((float)getTickCount()-deltaTimeInit)/(((float)getTickFrequency())); //Get Time Elapsed
deltaTimeInit=(float)getTickCount(); //Start counting time elapsed
cout << " DT end = " << deltaTime2 << endl;

//Complementary Filter
float pitchAngleCF=(alpha)*(pitchAngleCF+gyroAngleArray.Pitch*deltaTime2)+(1-alpha)*(accelmagAngleArray.Pitch);
float rollAngleCF=(alpha)*(rollAngleCF+gyroAngleArray.Roll*deltaTime2)+(1-alpha)*(accelmagAngleArray.Roll);
float yawAngleCF=(alpha)*(yawAngleCF+gyroAngleArray.Yaw*deltaTime2)+(1-alpha)*(accelmagAngleArray.Yaw);

//Calculate Orientation Error (current - target)
float pitchError = pitchAngleCF - pitchTarget;
pitchErrorSum += (pitchError*deltaTime2);
float pitchErrorDiff = pitchError - pitchPrevError;
pitchPrevError = pitchError;

float rollError = rollAngleCF - rollTarget;
rollErrorSum += (rollError*deltaTime2);
float rollErrorDiff = rollError - rollPrevError;
rollPrevError = rollError;

float yawError = yawAngleCF - yawTarget;
yawErrorSum += (yawError*deltaTime2);
float yawErrorDiff = yawError - yawPrevError;
yawPrevError = yawError;

//PID controller list
float pitchPID = pitchKp*pitchError + pitchKi*pitchErrorSum + pitchKd*pitchErrorDiff/deltaTime2;
float rollPID = rollKp*rollError + rollKi*rollErrorSum + rollKd*rollErrorDiff/deltaTime2;
float yawPID = yawKp*yawError + yawKi*yawErrorSum + yawKd*yawErrorDiff/deltaTime2;

//Motor Control - Mixing
//Motor Front Left (1)
float motorPwm1 =  -pitchPID + rollPID - yawPID + baseThrottle + baseCompensation;

//Motor Front Right (2)
float motorPwm2 =  -pitchPID - rollPID + yawPID + baseThrottle + baseCompensation;

//Motor Back Left (3)
float motorPwm3 = pitchPID + rollPID + yawPID + baseThrottle + baseCompensation;

//Motor Back Right (4)
float motorPwm4 = pitchPID - rollPID - yawPID + baseThrottle + baseCompensation;

 //Check if PWM is Saturating - This method is used to fill then trim the outputs of the pwm that gets fed into the gpioPWM() function to avoid exceeding the earlier set maximum throttle while maintaining the ratios of the 4 motor throttles.
    float motorPWM[4] = {motorPwm1, motorPwm2, motorPwm3, motorPwm4};
    float minPWM = motorPWM[0];
    int i;
    for(i=0; i<4; i++){ // Get minimum PWM for filling
        if(motorPWM[i]<minPWM){
            minPWM=motorPWM[i];
        }
    }

    cout << " MinPWM = " << minPWM << endl;

    if(minPWM<baseThrottle){
        float fillPwm=baseThrottle-minPWM; //Get deficiency and use this to fill all 4 motors
        cout << " Fill = " << fillPwm << endl;
        motorPwm1=motorPwm1+fillPwm;
        motorPwm2=motorPwm2+fillPwm;
        motorPwm3=motorPwm3+fillPwm;
        motorPwm4=motorPwm4+fillPwm;
    }

    float motorPWM2[4] = {motorPwm1, motorPwm2, motorPwm3, motorPwm4};
    float maxPWM = motorPWM2[0];
    for(i=0; i<4; i++){ // Get max PWM for trimming
        if(motorPWM2[i]>maxPWM){
            maxPWM=motorPWM2[i];
        }
    }

    cout << " MaxPWM = " << maxPWM << endl;

    if(maxPWM>maxThrottle){
        float trimPwm=maxPWM-maxThrottle; //Get excess and use this to trim all 4 motors
        cout << " Trim = " << trimPwm << endl;
        motorPwm1=motorPwm1-trimPwm;
        motorPwm2=motorPwm2-trimPwm;
        motorPwm3=motorPwm3-trimPwm;
        motorPwm4=motorPwm4-trimPwm;
    }

//PWM Output
    gpioPWM(24,motorPwm1);  //1
    gpioPWM(17,motorPwm2);  //2
    gpioPWM(22,motorPwm3);  //3
    gpioPWM(18,motorPwm4);  //4
</code>```


问:
What does "6 degrees of freedom" mean?
I am looking at this page that describes various characteristics of gyroscopes and accelerometers. Close to the end (where they speak about IMUs), the names of the items have something like this:

9 degrees of freedom

6 degrees of freedom

Can anyone explain what does this mean?

答:
The page is using some imprecise language, bordering on confusing.  This quote especially:

To measure those and other variables many people combine the two sensors, to create an inertial measurement unit (IMU) which provides two to six degrees of freedom (DOF).

They are saying "two to six degrees of freedom" when they mean "two to six measurements of independent variables".  Alternatively, they might have meant to say "which provides measurements of a system with two to six degrees of freedom".

That is to say, "Degrees of freedom" can't really be "provided" by a measurement device.  You would select a measurement device that can capture the data from every degree of freedom that your system has.

Title: What does "6 degrees of freedom" mean?


问:
Do walking robots use accelerometers?
My understanding of walking robots (e.g. https://www.youtube.com/watch?v=xJlkBBdyBYI) is that they use a gyroscope to determine the current orientation of the robot, or each joint of the robot. This is because if you just put encoders on each joint, the cumulative error over the entire robot will be too large to maintain stability. Therefore, a gyroscope measures the "real" orientation, and this is used for feedback when the robot is walking.

However, I'm also aware that some walking robots use accelerometers to maintain stability. What would be the benefit of using an accelerometer in this case? Would it be used instead of a gyroscope, or together with a gyroscope?

My guess is that gyroscopes do not measure acceleration directly (unless you were to numerically calculate this based on lots of orientation readings), but accelerometers do measure it directly (and more reliably than this numerical method). Know the acceleration as well as the position then enables to robot to more accurately predict its future position, and hence the feedback loop is more robust. Is this correct, or am I missing the point?

答:
The short answer is "yes".

Accelerometers can be used to improve stability by measuring slight changes in movement.  But most importantly, they can tell a walking robot which direction is down.

Title: Do walking robots use accelerometers?


答:
You can use Orocos RTT with ROS to achieve some real time performance. In order to use this you need to patch the Linux kernel with a real time patch like PREEMPT_RT or run a real time kernel like Xenomai.

You question about changing the sample time seems to actually miss the point of real time computing. Real time is not about doing calculations fast, it is about doing calculations within the required time frame. A rocket control system probably needs an update rate of several kHz, whereas a nuclear power plant is working more in the Hz range. Nevertheless, the power plant definitely needs real time computation. Basically it is up to you to set the required update rate, then the system can tell you if it can meet those demands. If you are working with hard real time, missing the deadline means a failure of the program and it should start a shut down procedure. Soft real time accepts some deviation but will know when the deadlines are not satisfied.

If you are working with balancing robots, e.g. segways, you will probably want update rates around 1 kHz hard real time. If you are doing trajectory following with a stable robot 100 Hz soft real time seems reasonable.

Title: Software real-time of ROS system

Body:
As far as I know, a hardware real-time robot control system requires a specific computing unit to solve the kinematics and dynamics of a robot such as interval zero RTX, which assigns CPU cores exclusively for the calculation, or a DSP board, which does exactly the same calculation. This configuration makes sure that each calculation is strictly within, maybe, 1 ms.

My understanding is that ROS, which runs under Ubuntu, doesn't have a exclusive
computing unit for that. Kinematics and dynamics run under different threads of the same CPU which operates the Ubuntu system, path plan, and everything else.

My question is that how does ROS achieve software-real time? Does it slow down the sampling time to maybe 100ms and makes sure each calculation can be done in time? Or the sampling time changes at each cycle maybe from 5ms, 18ms, to 39ms each time in order to be as fast as possible and ROS somehow compensates for it at each cycle?


问:
A simple function plotter project
To plot any curve or a function on a paper we need points of that curve, so to draw a curve, I will store a set of points in the processor and use motors, markers and other mechanism to draw straight lines attaching these points and these points are so close to each other that the resultant will look an actual curve.

So I am going to draw the curve with a marker or a pen.

Yes to do this project I need motors which would change the position of a marker but which one?

With my knowledge stepper motor and servo motors are appropriate but not sure whether they are appropriate since I have never used them, so will they work?

The dimension of paper on which I will be working on is 30x30 cms.

I have two ideas for this machine

a. A rectangular one as shown

I would make my marker holder movable with help of rack and pinion mechanism but I am not sure that this would be precise and I may have to alter to some other mechanism and if you know such then that can really help me.

b. A cylindrical one

Here I would roll a paper on this cylinder and this paper will get unrolled as the cylinder rotates and even the marker holder is movable but only in X direction and the rolling of paper is nothing but change of Y position.

Which one of the above two methods is good?

I know about microcontrollers and I want to control the motors using them so I decided to go with Atmega 16 microcontroller. But here i might need microstepping of signals how would I be able to do that with microcontrollers?

If you know the answer to atleast one of the questions then those answers are always welcomed.
If you need any clarifications about these then please leave a comment.

Thankyou for your time.

Your sincerely,
Jasser

Edit : To draw lines of particular slope I would have to know the slope between two points and the depending on the slope I would rotate motors with particular speed so that marker will move in a straight fashion with that slope.

答:
For the range of motion you are talking about, I would recommend stepper motors. Motion control will be easier to implement because they move a fixed distance per step.

Assuming the drum (idea B) is larger than the gear/pulley you would use for idea A, then I would say idea A is better. This is because the motor you use will turn some finite angle $\theta$, which means the carriage or drum will traverse a distance $r\theta$ - whichever device has a shorter radius (pulley or drum) will result in smaller motions, giving you a smoother curve. Also, putting paper correctly indexed on the drum (and holding it there!!) will be considerably more difficult than laying it flat in a frame. For example, if your stepper motor has a step size of 1.8 deg (0.0314 rad), and you use it on a pulley for a carriage where the pulley radius is 1cm, then your minimum motion on that axis is (0.0314 * 1)cm = 0.314mm. However, if your drum is big enough to hold the 30x30cm paper (perimeter = 30cm), then the drum radius is about 4.75cm, so your new minimum motion is (0.0314*4.75)cm = 1.5mm, or almost 5 times the distance between points!

Typically you won't controller the stepper motors directly from the microcontroller; you'll use a stepper driver to run the motors. The microcontroller then tells the driver what size steps to take (full, half, quarter, etc.) and how many steps to take and the driver does all of the power electronics and phasing for you.

As a reminder - you'll need a mechanism to raise and lower the pen or your entire drawing will be one connected line.

:EDIT:

Finding a mechanism to raise and lower the pen frame is outside the scope of this site [shopping recommendation], but I would try a spring-loaded pen attached to a servo motor.

Regarding micro-stepping, I'm not sure what your question is. For the driver I linked above, you set two bits for full [0,0], half [1,0], quarter [0,1] or eighth [1,1] stepping. That's it. You would use GPIO pins to do this, wired to the MS2 and MS1 pins on the stepper driver. When you want to take a step, you send a pulse to the STEP pin on the driver. The driver takes care of everything else.

Title: A simple function plotter project


问:
GPS tracking device
I'm looking for a GPS tracking device without screen or apps. I just need it to look for the current position of a bus and send it to a server through TCP/IP protocol. This process must be constant so I can have a real-time tracking. The bus already has a wireless access point.

What device can be useful? Do I need another piece of hardware to send the coordinates to the server? I have no experience but... can something like an arduino connected to the gps send the data?

答:
I'm assuming you mean a passenger bus instead of a data bus. I'm also assuming you have access to a 12V output from the bus as well. If not you'll also need a battery.

Grab a Garmin GPS unit and an Arduino with Ethernet and USB. The Garmin outputs strings with the latitude and longitude over USB, which the Arduino can read in. Copy those strings to Ethernet packets and send it off via the TCP/IP connection. Easy as pie and one of the first projects I ever did with a microcontroller.

Title: GPS tracking device


问:
Reference request: Path accuracy algorithm in the joint angle space
I am currently reviewing a path accuracy algorithm. The measured data are points in the 7 dimensional joint space (the robot under test  is a 7 axes Robot, but this is not of importance for the question). As far as I know path accuracy is measured and assessed in configuration (3 D) space. Therefore I am wondering if a path accuracy definition in joint angle space has any practical value. Sure, if one looks at the joint angle space as a 7 dimensional vector space in the example (with Euclidean distance measure) one can do formally the math. But this seems very odd to me. For instance, an angle discrepancy between measured and expected for the lowest axis is of much more significance than a discrepancy for the axis near the actuator end effector.

So here is my Question: Can anyone point me to references where path accuracy in joint space and/or algorithms for its calculation is discussed ?

(I am not quite sure what tags to use. Sorry if I misused some.)

答:
The forward kinematics of the manipulator will correctly identify the larger displacements of the end effector for small rotations of the proximal joints, as opposed to the smaller displacements of the end effector for small rotations of the distal joints.  When these motions are due to errors - all real mechanical systems have them - the established process for relating joint errors to task-space errors involves analytical perturbation analysis, and/or physical calibration of the system.

A good starting point would be Siciliano and Khatib, Handbook of Robotics.  Check out the end of Chapter 14 (they only hit upon the topic but the references will certainly help).  You can also look at the papers which describe 3D sensors for robot calibration.  Those papers frequently derive the perturbation analysis, then show how the new sensor allowed the end effector errors to be reduced after calibration.  I recommend many of the editions of Lenarcic's Advances in Robot Kinematics.  The 2000 edition with Stanisic has a paper by Khalil et al regarding calibration techniques.  Or a web search will find many such papers, e.g.,

http://www.columbia.edu/~yly1/PDFs2/wu%20recursive.pdf

http://lup.lub.lu.se/luur/download?func=downloadFile&recordOId=535825&fileOId=625590

http://math.loyola.edu/~mili/Calibration/index.html (follow the references in this one).

Hope this helps.


问:
Connecting a CC3D board with Raspberry Pi to get telemetry data
I want to get telemetry data in my Raspberry Pi that will be connected to a CC3D board either via USB cable or Serial communication. How can I get the data? I plan to have wifi communication between the Pi and my Laptop. Also OPLink modems will be used both in the Pi and the CC3D for the telemetry. Does anyone have a python example that may help to build an interface or output in the Linux shell to get raw telemetry data in RPi? </p>

答:
I am trying to do the same project.

I asked this question in the LibrePilot forum (the new community which gives support to the OpenPilot project) and they told me about the UAVTalk protocol, an object oriented protocol that is used to exchange telemetry data.

I give you some links about the protocol and also some modules programmed in Python to use it as interface with the protocol.
By now I haven't test those modules but they seems to work properly.

If you achieve something, please let me know.
Here are the links

https://bitbucket.org/alessiomorale/librepilot/commits/812babc4406e8063f04997e9f5214efe66ca4cac?at=next

https://librepilot.atlassian.net/wiki/display/LPDOC/UavTalk


问:
Sensors for identifying stacked books
I am working on a robotics application that involves moving objects (e.g. books) between several (around 10) stacks. To measure the performance, I'd like to be able to measure which book is located on each of the stacks. The order is not important I just want to know if a book is on one of the stacks.

The stacks are separated by at least one meter and the height of the stacks is less than 30cm (< 8 Books).

If have thought of putting an RFID card in every book and fixing RFID readers above (or below) the stack positions. Several readers could be attached via SPI or I2C to some arduinos or RPis.

What to you think about this approach? Is there a simpler way? Could someone maybe recommend a sensor that could solve this problem?

// Update:
I can modify the books (e.g. add a QR-Marker) to some extent, but can't guarantee that the orientation on the stack is fixed.

答:
You might want to look at optical glyph tracking.  I'm not sure how many unique glyphs there are and how many books you have, but it would provide a somewhat simple way to accomplish all this with a camera.

I say "simple" because you'd be able to visually debug it by just looking at the augmented reality video to see what glyphs are being detected.

Title: Sensors for identifying stacked books


问:
CTL port in a motor controller
When I look at my 160A motor controller, it has a port that is called "CTL."
What does CTL stand for? Is that a sort of protocol like RS232?</p>

答:
From that page,

This speed adjuster plugs into the radio control inputs of the motor controllers.

So my guess would be that CTL is short for "Control".  Without a better picture or a user manual, only the vendor would be able to say for sure.

Title: CTL port in a motor controller


问:
Automatic sliding window shutter
I want to build an automatic sliding window shutter and need help
with part selection and dimensioning.

Some assumptions:

window width 1.4 m

sliding shutter weight 25 kg

max speed 0.07 m/s

max acceleration 0.035 m/s^2

pulley diameter 0.04m.

Leaving out friction I need a motor with about 0.02 Nm of torque and a rated speed of 33 rpm.

What I would like to use:

motor controller with soft-start and jam protection,

dc motor 24V,

Pulleys and timing belts.

Would you suggest other components or a different setup?
How do I connect motor and pulleys (clamping set?)?
Do I need additional bearings because of the radial load?

```<code>M=P
M=B=P
M=P=B
M=B=P=B
</code>```

(M motor, P pulley, B bearing, = shaft)

If so I have to extend the motor shaft. What would I use for that (clamp collars, couplings?)?
What width do I need for the belts? Which belt profile (T, AT, HDT) should I use?

Update

The construction I am aiming for resembles the one which can be seen on page 6 (pdf numbering) here.

答:
"Leaving out friction I need a motor with about 0.02 Nm [of torque] and [a rated speed of] 33 rpm."

No offense, but verifying your numbers based on your spec's:

window width 1.4 m

sliding shutter weight 25 kg

max speed 0.07 m/s

max acceleration 0.035 m/s^2

pulley diameter 0.04m.

The max linear speed is equal to $r\omega$, where $\omega$ is the angular velocity in radians per second. Your pulley diameter is 0.04m, so your radius is 0.02m. This means that:

$$
v = r\omega \\
0.07 \mbox{m/s} = 0.02\mbox{m}*\omega \\
\omega = \frac{0.07}{0.02} \mbox{rad/s} \\
\omega = \frac{3.5 \mbox{rad/s}}{1}*\frac{60\mbox{s}}{1\mbox{m}}*\frac{1\mbox{rev}}{2\pi\mbox{rad}} \\
\omega = 33.4\mbox{rpm}
$$

So, your rated speed checks out. Now, the torque. If you ignore friction, then the only purpose for torque is to accelerate:

$$
\tau = I\alpha \\
$$

where $I$ is the moment of inertia, $\alpha$ is the angular acceleration is $\mbox{rad}/s^2$, and $\tau$ is the motor torque. Again, $a=r\alpha$, like $v = r\omega$, so $\alpha = a/r$. As the weight of the shutter is going to the pulley, you can consider it a point mass at radius $r$, meaning the moment of inertia $I = mr^2$.

So:

$$
\tau = I\alpha \\
\tau = (mr^2)(a/r) \\
\tau = r(ma) \\
\tau = (0.02\mbox{m})(25*0.035\mbox{kg m/s}^2) \\
\tau = 0.0175 \mbox{Nm} \\
$$

BUT - if this is for a vertical shutter, the motor has to support the weight of the shutter while it's accelerating it, so the moment of inertia is now $mgr$, or $25*9.81*0.02 = 4.9\mbox{Nm}$ - this dwarfs your acceleration requirement.

The required torque is small enough that I would suggest double checking your assumption that friction is negligible. That said, you have a rated speed and a rated torque, now you just need a rated power. For rotating systems:

$$
P = \tau\omega \\
$$

Where the previously calculated values torque and speed are $\omega = 3.5 \mbox{rad/s}$ and $\tau = 0.0175 \mbox{Nm}$, so:

$$
P = (3.5)(0.0175) \mbox{Nm/s} \\
P = 61\mbox{mW} \\
$$

So, based on your problem description, nearly any motor you can find will work, with the exception of the very smallest hobby motors. For instance, this motor has a rated speed of 120rpm, a rated torque of 0.6Nm, which is over 30x your requirement, for a rated mechanical power of about 7.5W.

A couple notes of caution, though:

These calculations make the assumptions that there is no friction and that there is no inertia between the motor and the shutter. Regarding bearings, I would probably use bushings, which are basically wear parts but are significantly less expensive and smaller than true bearings for light loads. I would definitely consider using at least one bushing to help minimize bending forces and wear on the output shaft bearing in the motor.

Without a better description (read: picture) of what your intended setup is I can't comment any further than this. In general, though, find the torque, speed, and power rating for the motor and add some performance margin and then just search the Internet. You have to finish the design before anyone here can comment specifically on it.

Title: Automatic sliding window shutter


问:
Calibrate a 2d scanner mounted on a rotary axis
A 2d laser scanner is mounted on a rotary axis. I wish to determine the transformation matrix from the center of the axis to the center of the scanner, using only the input from the scanner and the angle of rotation.

The 2d scanner itself is assumed to be calibrated, it will accurately measure the position of any object inside the plane of the laser, in regards to the scanner origin.

The rotary axis is calibrated as well, it will accurately measure the angle of its own movement.

The scanner is aligned and mounted close to the center of rotation, but the exact offset is unknown, and may drift over time.

Assume it is impractical to measure the position and orientation of the scanner directly.
I am looking for a way to determine the exact values for the 6 degrees of offset the scanner may have in relation to the axis, determined solely on the 2d information from the scanner and the rotation angle from the axis.

I am mainly interested in the 4 offsets depicted here, since the other two do not matter in regard to generating a consistent 3d point cloud from the input data.

By scanning a known calibration object, it should be possible to determine these offsets. What are the mathematical formulas for this?

What sort of calibration information is required at a minimum?
Is it for example possible to determine all parameters simply by scanning a flat surface, knowing nothing about the surface except that it is flat?

(The transformation matrix from rotation axis to world is unknown as well, but that one is trivial to determine once the transformation from axis to camera is known.)

Example

On the left the camera is placed exactly on the rotational axis.  The camera scans a planar object with reference points A B and C. Based on the laser distance measurements and the angle of the axis, this planar object can be reconstructed.

On the right, the camera has an unknown offset to the axis. It scans the same object. If the point cloud is constructed without knowing this offset, the planar surface maps to a curved surface.

Can I calculate the offset based on the surface curvature?

If I know the real-world distances and angles between A, B and C, how can I calculate the camera offsets from that? What would be the minimum number of reference points I need for all 4 offsets?

答:
If you can afford to have a small portion of your field of view obscured, you may want to consider having a fiducial object somewhere in view.

With a suitable fiducial object, scanning it as your axis rotates, you should be able to calculate the four offsets you desire.

If you cannot afford to have any of your field of view obscured under normal operation, then you may need to place your fiducial on an actuator of it's own, bringing it into view when you want to calibrate and taking it out for normal operation. The only issue here is that you limit the accuracy of your calibration by the accuracy of your fiducial actuator.

Note that if some part of your field of view is already obscured by another part of your robot, and it may be suitable to use as a fiducial, or at the very least as a mounting point for one.


问:
How to make a Raspberry Pi?
I'm currently a robotics hobbyist and am full fledged in Arduino and I have used the Raspberry Pi to make some robots and PCs. Currently, I am thinking of making my own Raspberry Pi, from scratch, on a breadboard or a PCB or something. I surfed the web quite a bit and I did not get the answer I was hoping for. By making a Pi, I mean like instead of buying an Arduino, I can make one myself by buying the Atmega328, Crystal oscillators, etc. I am asking for this because my school requires me to do a project in which I make a computer or a gaming console or something like that and I would hate to look at the disappointed face of the tester all because I just bought a Pi , an connected some devices to it. Thanks in advance!</p>

答:
You would need to take the available SPICE and ECAD drawings, and then turn them into PCB schematics using something like KiCAD or Eagle. Then you can send the PCB file to a PCB printing service, and they'll send you what you order. You'll then have to find all the components and solder them yourself - you'll need to be very good at surface mount techniques. Honestly, unless you really need a custom RasPi, and already know how to design it, it's not worth your time to build your own IMO. Just buy one.

In terms of a school project, adding components to a RasPi is still not a simple task. These things aren't plug and play, you'll need to write the software for it, and name sure that your circuits are wired up correctly. I'm sure that your teacher will still be impressed with a 'store-bought' board used in whatever project you decide.

For future reference, this is the robotics stack exchange. I'm betting that your question is going to be closed because it is mostly unrelated to robotics. However, the electrical engineering stack exchange will probably be more than happy to help you, if you're set on building your own RasPi.

Title: How to make a Raspberry Pi?


问:
How does the cliff sensors on ROOMBA work through a glass wall?
I want to use IR sensors to detect whether my dustbin is full but I want to protect it from outside dust. I am planning to use the IR sensors on Roomba.

How are they working despite a plastic wall?

Also, what is the range of the sensor?

Can they detect obstacle at about 25 cm?

Why is there a wall between the IR sensors?

Is there a reason they are positioned at certain angle?

答:
What Ben said. All Roombas including and following the 700 series have bin-full sensors that use an IR emitter and sensor that goes across the mouth of the bin.

To provide a little more detail, research a material's 'IR Transparency'. Most clear plastics and glasses are transparent to infrared, but not all. Even some opaque plastics are IR transparent, and this can make your life a little easier by making sure the light picked up by the sensor is only the IR you're shooting at it. You'll need to double check whichever materials you wish to use, and make sure that the IR beam can penetrate.

Should be able to penetrate just find, as long as you pick the right material

25cm shouldn't be an issue, but check the specs of the sensor and verify it against the log output from the roomba

Dido

Mostly to protect the sensor from debris

Mostly for mechanical reasons. It's at that angle in the 800 series roomba to make it easier to insert and remove the bin with one hand


问:
Simple equation to calculate needed motor torque
Suppose I have a DC motor with an arm connected to it (arm length = 10cm, arm weight = 0), motor speed 10rpm.

If I connect a 1Kg weight to the very end of that arm, how much torque is needed for the motor to do a complete 360° spin, provided the motor is placed horizontally and the arm is vertical?

Is there an simple equation where I can input any weight and get the required torque (provided all other factors remain the same)?

答:
The dynamic torque of actuators for robotic limbs is a topic that is thoroughly discussed in a mathematical introduction to robotic manipulation.
http://www.cds.caltech.edu/~murray/books/MLS/pdf/mls94-complete.pdf

Answering your question lead me to page 156.  The result seems to be that the torque is purely dependent on position and independent velocity (assuming steady simply planar rotation).
So by your numbers, I would expect approximately one newton-meter cosine wave at ten cycles per minute.


问:
Sphero's logic, how does it work
I'm willing to make my first robot, and I'd like to make one similar to the Sphero.

I know I have to add 2 motors in it, and make it work as a hamster ball, but I don't understand how I can make it rotate on the x axis aswell and not only on the y axis, if we assume that the y one is in front of the robot and the x one on its sides.

Any ideas?

答:
The principle lying underneath the sphero robot's design and locomotion is shifting of the centre of mass of the ball and making it unstable which makes the ball roll [1,3,4,5,6]. A controlled and calculated shifting of the centre of mass to the appropriate position can achieve desired trajectories of the ball. Apart from the above said principle, a few other principles of gyroscopic locomotion and conservation of momentum are also used [2].

To change the centre of mass, a differential drive robot [6], a pendulum [3], a three-wheeled omni wheel robot [7] are commonly placed. Even four mass particles attached to cables or ball screw mechanisms are actuated inside the sphere to make it roll [5].

From the point of view of both design and control, I would suggest the robot with three-wheeled omni wheel actuating the internal surface is a simple to implement and control. This design can certainly be improved upon by identifying the good aspects of design in the previously developed robots. For e.g., the spring mechanism used along with a castor wheel in [1] can be used to provide more friction between the wheeled robot and the sphere's internal surface. Going through the references would certainly provide a greater insight into the different designs which might elicit a novel design idea for the robot.

Once the design is finalized there is an ample literature available which can help you to model the dynamics and control its motion. Few of the papers work out on these aspects also along with the design of the robot.

References:

[1] Antonio Bicchi et. al, "Introducing the “SPHERICLE”: an Experimental  testbed for Research and Teaching in Nonholonomy." Proceedings of the 1997 IEEE
International Conference on Robotics and Automation Albuquerque, New Mexico - April 1997.

[2] QingXuan Jia et. al, "Analysis of Actuation for a Spherical Robot".2008 IEEE Conference on Robotics, Automation and Mechatronics.

[3] Erkan Kayacan et. al, "Modelling and control of a spherical rolling robot: a decoupled dynamics approach." Robotica: page 1 of 10. © Cambridge University Press 2011. (doi:10.1017/S0263574711000956)

[4] Wei-Hsi Chen et. al, "Design and implementation of a ball-driven omnidirectional spherical robot." Mechanism and Machine Theory 68 (2013) 35–48.

[5] SANG Shengju et. al, "Modeling and Simulation of a Spherical Mobile Robot." UDC 519.87 (DOI: 10.2298/CSIS1001051S)

[6] J Alves et. al, "Design and control of a spherical mobile robot." Proceedings of the Institution of Mechanical Engineers, Part I: Journal of Systems and Control Engineering September 1, 2003 vol. 217 no. 6 457-467. (doi: 10.1177/095965180321700602)

[7] Wei-Hsi Chen et. al, "Design and Implementation of an Omnidirectional Spherical Robot Omnicron." The 2012 IEEE/ASME International Conference on
Advanced Intelligent Mechatronics July 11-14, 2012, Kaohsiung, Taiwan

Title: Sphero's logic, how does it work


问:
Weird behaviour with a Create2 connected via XBEE
This is not really a problem but something strange is going on.

When Create2 is connected to a PC via the USB original connector lead, when you start-up the computer the Create2 is activated by the Baud Rate Change (BRC) pulling to ground. If I understand correctly, normal behaviour.

My Create2 is connected to a XBEE via a buck converter, I added a switch so the buck converter and the XBEE should not drain the battery continuously so as mentioned in the specs.

I followed the Bluetooth pdf for the connections, its working well for sending commands but I still just have a few problems with streaming the return data but that will be resolved.

But now, with the XBEE switched off my Create2 still activates when I start-up my PC, how is that possible, how can the BRC be pulled to ground?

There can be no communication between the PC XB and the Create2 XB since the Create2 XB is switched off, only the PC XB is switched on when starting the computer.

Its not a problem, its just that I am puzzled. Can anyone explain why this is happening?

答:
So, am I understanding this correctly that there is no physical connection between your Create 2 and your PC when going by the XBEE - only a bluetooth connection?

If you say the Create 2 XBee is switched off, then it sounds like a hardware failure of the switch on the Create 2's XBee. Not uncommon with cheaper/smaller switches, the switch just happened to fail in the 'on' position. Try switching the Xbee on the PC off and rebooting the PC, see if the signal still gets through (just to eliminate the PC XBee as the malfunction).

Pull the create 2 XBee, and check the continuity of the switch with a simple DMM (check the resistance - high for 'off', low for 'on', no change for 'broken').


答:
Since the arm is in a vertical plane, certainly, motor torque is required to counteract the gravitational torque. Since it is a simple 1DOF arm with a rotary joint, the gravitational torque is

$ \tau_{g} = mglcos(\theta) $

where m - mass of the link; l - perpendicular distance of the center of mass from the joint axis; $\theta$ - angle of rotation measured with the positive x-axis which is pointing to right

If the torque required has to be precisely calculated, then, joint frictional also has to be estimated. Generally, joint friction is assumed to be linear, although it shows a complex nonlinear behaviour at low speeds, it is a reasonable assumption to consider a linear function consisting of coulomb friction and viscous friction. Because of these two frictional terms, two new parameters arise which are generally estimated experimentally or used from the available literature.

$ \tau_{f} = b_{c} + b_{v}\dot{\theta} $

where $ b_{c} $ - coefficient of coulomb friction; $ b_{v} $ - coefficient of viscous friction

Also, the inertia of the link itself contributes to the torque generated. However, inertial torque will be zero if it rotates at a constant angular velocity.

$ \tau_{I} = I\alpha $

where, I - inertia of the link about the axis of rotation; $\alpha$ - angular acceleration of the joint

Hence, the total torque required will be

$\tau_{T} = \tau_{g} + \tau_{f} + \tau_{I} $

To do the above computations, the joint position, velocity, and acceleration trajectories have to be decided and evaluated which in robotics terminology is called as trajectory planning. The procedure of torque computation from the joint trajectories is called as inverse dynamics.

Since this was a simple 1DOF arm, the torque was evaluated with simple equations. However, for large DOF arms, for systematic computation of torque, techniques like Euler-Newton are generally used. (available in the book provided by @Drew)

Title: Simple equation to calculate needed motor torque

Body:
Suppose I have a DC motor with an arm connected to it (arm length = 10cm, arm weight = 0), motor speed 10rpm.

If I connect a 1Kg weight to the very end of that arm, how much torque is needed for the motor to do a complete 360° spin, provided the motor is placed horizontally and the arm is vertical?

Is there an simple equation where I can input any weight and get the required torque (provided all other factors remain the same)?


答:
How quickly do you want to go from stopped to 10rpm? This will define your angular acceleration.

Regarding calculations, first you should convert to standard units, so meters instead of centimeters and radians per second instead of revolutions per minute:

$$
\omega_{\mbox{rad/s}} = N_{\mbox{rpm}}*\frac{2\pi}{60} \\
\omega_{\mbox{rad/s}} = N_{\mbox{rpm}}*0.1 \\
\omega_{\mbox{rad/s}} = 1 \mbox{rad/s} \\
$$

$$
L = 0.1 \mbox{m} \\
$$

Now, the equations you'll need are:

$$
\tau_{\mbox{min}} = \tau_{\mbox{dynamic}} + \tau_{\mbox{static}_\mbox{max}} \\
$$

where

$$
\tau_{\mbox{static}_\mbox{max}} = mgL \\
$$

and

$$
\tau_{\mbox{dynamic}} = I\alpha \\
$$

where $g$ is the gravitational constant $9.81\mbox{m/s}^2$, $I$ is the moment of inertia and $\alpha$ is the angular acceleration. These can be further defined as:

$$
I = mL^2 \\
\alpha = \frac{\omega_{\mbox{desired}}}{t_{\mbox{desired}}}
$$

where $t_{\mbox{desired}}$ is how long you want the motor to take to get from stopped to full speed and $L$ and $\omega$ are your arm length and rotational speeds in meters and rad/s, respectively.

So, putting this all together:

$$
\tau_{\mbox{min}} = (mL^2)(\frac{\omega_{\mbox{desired}}}{t_{\mbox{desired}}}) + mgL
$$

The power required to achieve this torque will peak the instant before you stop accelerating, when you are at top speed. This power is given by:

$$
P = \tau \omega \\
$$

where $\tau$ is the torque calculated above and again $\omega$ is rotational speed in rad/s. Power is in Watts.

Please note this is the theoretical minimum; in reality you will need more torque (and thus more power) because the arm is not massless and your load is not a point mass, but most importantly because whatever gear box you use to get to 10rpm will introduce significant inertia and frictional losses. I would shoot for at least double whatever those calculations give you as a performance margin.

Once you have torque, speed, and power, you should be have enough specifications to purchase the correct motor.


问:
Choosing stepper motor for hand
I'm developing a robotic hand, and decided to place motors inside joints (as in picture) and I'm stuck with finding a stepper motor that can fit there. Approximate size of motor body is radius - 10mm, length - 10 mm.

Any suggestions?

答:
I have used MicroMo's stepper motors in the past.  You can find their information here:  http://www.micromo.com/products/stepper-motors/stepper-motors-datasheets

However, I don't know if a design process of "make decisions then see what fits" is the best approach.  You should determine the performance you need, then look for components, and base your architectural decision on what you find available.   You may need to relocate the motors and use some kind of mechanical transmission to get the hand performance you're looking for.   It is hard to say with such little required performance information.

Title: Choosing stepper motor for hand


问:
Choosing the state vector for an EKF
Could someone help me understand the logic behind choosing a particular state space vector for an EKF?

Context: Say there is a 4 wheeled robot that operates only in 2D. It is equipped with an inertial unit (a/g/m) and wheel encoders (I understand that these alone might not satisfy accuracy constraints, but consider this as a hypothetical case).

Now, some literature has the state as [q, x, y, vx, vy]' while a few others as [q, q_dot, x, y, vx, vy]'. My question is, what is the advantage with having certain 'rate terms' as opposed to only the normal parameters? Also, what about including bias terms in there?

How do I go about selecting an appropriate state space vector for any use-case (in general)? Is there a set of intuitive/mathematical steps to consider/follow?

Thanks!

答:
In general, I try to obey the following two rules when selecting states:

Only use the states necessary for control, and

Choose states to be measurable properties, whenever possible.

For example, on my car's dashboard I could include: suspension displacement, brake pad wear, tire wear, etc. - these are all measurable properties that are critical to operation but, provided they are within spec, they are not critical to control. The more indicators (states) I attempt to include, the more "costly" it is to monitor them. For a person, it takes time to read the gauges; for a computer, every additional matrix dimension increases the computation time for state prediction, gain calculations, etc.

Similarly, I could try to estimate fuel consumption by using a function of engine power (torque and RPM), or I could do it by monitoring fuel pump flow. In the former, fuel consumption is a function of two states, where the latter is a function of one state.

By choosing your states to be directly measurable parameters, you can use them as direct feedback, bypassing the need for observer design for that state. This in turn allows you to use reduced-order observers, which reduces both the controller design complexity for you and again the computational complexity for the controller.

Title: Choosing the state vector for an EKF


问:
Find orientation through Transformation matrix
I have a robot with 3 rotational joints that I am trying to simulate in a program I am creating. So I have 4 frames, one base frame, and each joint has a frame. I have 3 transformation functions to go from frame 1 or 2 or 3 to frame 0.

By using the transformation matrix, I want to know how much each frame has been rotated (by the X,Y and Z axis) compared with the base frame. Any suggestions?

The reason I want this is because I have made some simple 3D shapes that represent each joint. By using the DH parameters I made my transformation matrices. When ever I change my θ (it does not mater how the θ changes, it just does), I want the whole structure to update. I take the translation from the last column. Now I want to get the rotations.

答:
Based on your question, i understood that you have transformation matrices and you need to find Euler angles.

$$
        \begin{array}{ccc|c}
        r11&r12&r13&X\\
        r21&r22&r23&Y\\
        r31&r32&r33&Z\\
        \cdots&\cdots&\cdots&1
        \end{array}
$$
the first three rows and columns will give us a Rotation matrix.
You will get X,Y,Z rotation angles by comparing the above mentioned rotation matrix with
$$
        \begin{matrix}
        cos(\psi)cos(\theta)&-sin(\psi)cos(\phi) + cos(\psi)sin(\theta)sin(\phi)&sin(\psi)sin(\phi)+cos(\psi)sin(\theta)cos(\phi)\\
        sin(\psi)cos(\theta)&cos(\psi)cos(\phi)+sin(\psi)sin(\theta)sin(\phi)&-cos(\psi)sin(\phi)+sin(\psi)sin(\theta)cos(\phi)\\
        -sin(\theta)&cos(\theta)sin(\phi)&cos(\theta)cos(\phi)
        \end{matrix}
$$

I suggest to use quaternions, they will be of form  e0 + e
Here  e0 is the cos(angle/2) and e is the unit vector of axis of rotation multiplied by sin(angle/2).


答: An intuitive way to think about this is to recognize that the upper left 3x3 rotational submatrices of the 4x4 transformation matrices are really just the direction cosines of each of the unit vectors of the moving frames, with respect to the base frame.  So, for example, consider the $T_{02}$ transformation matrix.  This would be found by multiplying $T_{01} T_{12}$, which maps the second moving frame back to the global, or $0$, frame.  The first column of the upper left 3x3 of $T_{02}$ is just the cosine mapping of  $\hat x_2$ (the unit vector of the $2$ frame's $x$ axis) into its components in the $0$ frame.  Similarly, the second column contains the direction cosines of $\hat y_2$ onto the base frame, and the third does the same for $\hat z_2$.</p>

Title: Find orientation through Transformation matrix

Body:
I have a robot with 3 rotational joints that I am trying to simulate in a program I am creating. So I have 4 frames, one base frame, and each joint has a frame. I have 3 transformation functions to go from frame 1 or 2 or 3 to frame 0.

By using the transformation matrix, I want to know how much each frame has been rotated (by the X,Y and Z axis) compared with the base frame. Any suggestions?

The reason I want this is because I have made some simple 3D shapes that represent each joint. By using the DH parameters I made my transformation matrices. When ever I change my θ (it does not mater how the θ changes, it just does), I want the whole structure to update. I take the translation from the last column. Now I want to get the rotations.


问:
ROS on Raspberry Pi Model 2: UbuntuARM vs ROSBerryPi
Before I ask my question, I'd better confirm that I've read the most prominent post about running ROS on Raspberry Pi devices.

That post contains some valuable information, but it's a bit dated, and ROS support for ARM devices is much better these days. In fact, ROS 2.0 is evidently going to have excellent support for running on embedded devices like the Raspberry Pi.

I just got a Pi model 2 for my birthday, and I'm really eager to get ROS running on it so I can build a robot I've been working on, which is based on the Wild Thumper 6WD platform.

From my perspective, here are a few pros & cons regarding UbuntuARM and ROSBerryPi:

UbuntuARM

Pros:

Ubuntu is the official ROS distro and is the most well-supported ROS OS

The best documentation on the ROS wiki for running on ARM devices is written for UbuntuARM

Cons:

Raspbian (on which ROSBerryPi is based) is the official distro for Rasbperry Pi and thus has the best support for the board.

ROSBerryPi

Pros:

Raspbian (on which ROSBerryPi is based) is the official distro for Rasbperry Pi and thus has the best support for the board.
Cons:

ROS is not well supported on OS's other than Ubuntu

To use the ROSBerryPi distro, you must build ROS from source.

My question is: can anyone provide any further insight into this dilemma? If you've been running ROS on your Raspberry Pi 2 (model 2 only please; the model B+ has completely different issues, like not being well-supported by Ubuntu), what's your experience been?

Which distro would/did you choose, and why?

答:
The ROSBerryPi page is quite outdated, you actually can install prebuilt ROS Groovy binaries on Raspbian.

You will be better off installing prebuilt ROS binaries rather than building from source on your pi.

I don't have any experience with Ubuntu on the raspi but it's running great on my Odroid UX4 (similar single board computer) and ROS Jade runs just fine on that. See these instructions for how to install Ubuntu on your pi. Running Ubuntu will allow you to easily use the latest ROS distribution and packages.


问:
How to compute the error function in graph SLAM for 3D poses?
Given a pose $x_i = (t_i, q_i)$ with translation vector $t_i$ and rotation quaternion $q_i$ and a transform between poses $x_i$ and $x_j$ as $z_{ij} = (t_{ij}, q_{ij})$ I want to compute the error function $e(x_i, x_j) = e_{ij}$, which has to be minimized like this to yield the optimal poses $X^* = \{ x_i \}$:

$$X^* = argmin_X \sum_{ij} e_{ij}^T \Sigma^{-1}_{ij} e_{ij}$$

A naive approach would look like this:

$$ e_{ij} = z_{ij} - f(x_i,x_j) $$

where $z_{ij}$ is the current measurement of the transform between $x_i$ and $x_j$ and $f$ calculates an estimate for the same transform. Thus, $e_{ij}$ simply computes the difference of translations and difference of turning angles:

$$ e_{ij} = \begin{pmatrix} t_{ij} - t_j - t_i \\\ q_{ij} (q_j q_i^{-1})^{-1} \end{pmatrix} $$

Is there anything wrong with this naive approach? Am I missing something?

答:
Yes, you have an issue, and it has to do with the parameterization of rotations. As you have it, your $e_{ij}$ will be a $7\times 1$ column, but your pose has only six degrees of freedom (three for translation, three for rotation). There is actually a constraint that isn't properly represented in your optimization function (the norm of a unit quaternion must be one). This means that when you try to do the optimization, it will not "know" about this redundancy and solving for $X^*$ will actually optimize a degree of freedom that doesn't exist.

So how do we deal with this? It's a good idea to use unit quaternions because they avoid the singularities present in all minimal parameterizations (i.e., three parameter representations) of rotations. A good approach to this problem is using a dual parameterization of rotations. First, we use a singularity-free parameterization of the rotation in the state (e.g., your use of unit quaternions is fine), but we represent rotation errors using a minimal parameterization. If the differences between your measurements $z_{ij}$ and predicted measurements $f$ are relatively small, you can safely convert the error rotation to a minimal parameterization without fear of it encountering a singularity (depending on your choice of minimal parameterization).

For example, let's use a rotation vector $\mathbf{r} = \theta\mathbf{a}$ for the minimal parameterization (where $\theta$ is the angle of rotation and $\mathbf{a}$ is the axis of rotation). Your new error vector is

$$
e_{ij} = \begin{bmatrix} t_{ij} - t_j - t_i \\ \log\left(q_{ij}(q_jq_i^{-1})^{-1}\right) \end{bmatrix}
$$

where $\log(q)$ converts a quaternion to a rotation vector. Note that you should also be representing the uncertainty of your rotation measurement using a minimal parameterization (i.e., $\Sigma_{ij}$  is a $6\times 6$ matrix).

After you solve for the optimal $6 \times 1$ perturbation of the state $\Delta\mathbf{x}^*$, you need to apply it to your state by converting the rotation vector back to a unit quaternion; i.e.,

$$
q \gets q\, \exp(\Delta \mathbf{r}^*)
$$

where $\Delta \mathbf{r}^*$ is the optimal perturbation of one of the state's quaternions (i.e., it's part of $\Delta\mathbf{x}^*$), and $\exp$ converts a rotation vector to a unit quaternion.

I didn't really go into too much detail here, and skipped some mathematical rigour for the sake of keeping things brief. For more information on this approach, see the below references. This approach is not limited to rotations.

C. Hertzberg, R. Wagner, U. Frese, and L. Schröder, “Integrating generic sensor fusion algorithms with sound state representations through encapsulation of manifolds,” Information Fusion, vol. 14, no. 1, pp. 57–77, Jan. 2013.

G. Grisetti, R. Kümmerle, C. Stachniss, and W. Burgard, “A tutorial on
graph-based SLAM,” IEEE Intelligent Transportation Systems Maga- zine, vol. 2, no. 4, pp. 31–43, 2010.


问:
Detecting the presence of a person in a room
I am working on my first hobby project and I'm not very familiar with sensors yet. I am trying to build a system which detects the presence of a person in a small room with a single entrance/exit door.

The idea is when the first person enters the room, the lights turn on and any following person doesn't affect state of the lights. After the last person leaves, the lights should turn off. In a programmatic sense, the lights should turn on when present person count is greater than 0.

I have explored my options and found out that infrared sensors are usually used for this type of problem. What I am not sure is how to detect whether person has entered or left, so I would like to ask for some help with this.

答: A human inside a room can be identified by using temperature sensors. Every object has its own temperature, i.e. a human also has a certain body temperature - using this we can find the find the presence of human being inside a room.</p>


问:
Are power and torque required related in some way?
I am designing a new platform for outdoor robotics and I need to calculate the power and/or torque that is needed to move the platform. I have calculated that I need about 720 W of total power to move it (360W per motor), but I don't know how to calculate the torque that I need.

Is it really just about having the required power and ignoring the torque or is there a way to calculate it easily?

Already known parameters of the platform are:

Weight of the whole platform: 75 kg.

Number of wheels: 4.

Number of powered wheels: 4.

Diameter of wheels: 30 cm.

Number of motors: 2.

Wanted speed: 180 RPM (3 m/s).

Wanted acceleration: > 0.2 m/s^2

答:
A good presentation on how to size your motors for a mobile robot is Sizing Electric Motors for Mobile Robotics from the Central Illinois Robotics Club.

The general procedure outlined there includes the following steps:

Step One: Determine total applied force at worst case

Step Two: Calculate power requirement

Step Three: Calculate torque and speed requirement

Step Four: Find a motor that meets these requirements

Step Five: Plot motor characteristics

Since you also have an acceleration requirement, you will also need to factor that in as well.


问:
Can I control iRobot Create 2 with NI myRIO and LabVIEW codes?
I need to know if the iRobot Create 2 can be controlled with a NI myRIO that has been programmed through LabVIEW. </p>

<p>The goal is to program an autonomous robot for real-time tracking using a Kinect sensor. </p>

答:
Unfortunately, there is no "single" answer to your question. There is no USB port on the NI myRIO, so just using the cable provided by iRobot as-is is not really an option. The good news is the iRobot Create (and Roombas in general) take all of their commands via the serial 7DIN interface that is mounted on-top of Roomba. The Create 2 should have some re-programmable capabilities, Roombas will not - you need to 'live push/pull' instructions/data to/from them using an attached device like an arduino, RasPi, Tegra TK1/TX1, etc. So if you can get the NI myRIO to generate the appropriate serial commands from LabView code - something that shouldn't be too difficult - then it should be possible to control the Create/Roomba and program the Create 2. As for exactly how to do this, I am unfamiliar with the NI myRIO. It is a relatively new system, and I am not sure it really offers any benefit over something like an Arduino, RasPi, or Tegra. I can only be sure that you will need to design your own interface, as it seems like the myRIO was designed to make use of 'bare' motors and sensors, not ones already sitting behind a micro-controller.

In this particular case, I would advise against the NI myRIO and suggest you use either the nVidia Tegra TK1 or nVidia Tegra TX1. They are specifically designed to do live image processing on a mobile platform, and the drivers for using a kinect sensor has already been developed for the TK1/TX1. You can also use ROS for these boards, and that again will make your life much more simple. It still won't be a simple "put all the pieces together and press 'go" project, but you won't have to write all the code and drivers on your own. In robotics - unless the point is to do it 'new' - re-using existing code and drivers is in your best interest.


问:
How to make a stepper motor rotate and come to a position of certain degrees (say for 90 degrees) from any initial position?
I tried this code and it worked:

```<code>void loop()
{
    int y = 104;
    int x2 = vertical2.currentPosition();
    int z2 = y-x2;
    int x1 = horizontal2.currentPosition();
    int z1 = y-x1;

    horizontal2.moveTo(z1);
    horizontal2.run();

    vertical2.moveTo(z2);
    vertical2.run();
}
</code>```

However, the problem is that when the above code was placed inside a loop such as if loop, it was not working. Can anyone help me solve this problem? I am using accelStepper library for the code above.

```<code>void loop()
{
    int dummy=1;
    if(dummy==1)
    {
        int y = 104;
        int x2 = vertical2.currentPosition();
        int z2 = y-x2;
        int x1 = horizontal2.currentPosition();
        int z1 = y-x1;

        horizontal2.moveTo(z1);
        horizontal2.run();

        vertical2.moveTo(z2);
        vertical2.run();
    }
}
</code>```

答:
You're in luck.  Stepper motors do not have absolute positions.  There is no 0-degree mark, nor 90-degree mark, etc.  Everything is relative to the current step, so you don't have to query where the motor is positioned.

If you want to track the absolute position, look into position encoding motors (rotary encoders are popular).

For your case, you need to research 1 thing: how many steps does my motor complete in 1 revolution? Another way of asking this is: what is the angular resolution of my motor?

This post will take you the rest of the way: Arduino and stepper control

Where you see my code saying stepperX.step(500);, that's the command to take 500 steps.

If you want x number of degrees, you'll write the following:

```<code>numSteps = stepsPerRevolution * (desiredNumberOfDegrees / 360);
stepperX.step(numSteps);
</code>```

ContentLicense: CC BY-SA 4.0

Body:
You're in luck.  Stepper motors do not have absolute positions.  There is no 0-degree mark, nor 90-degree mark, etc.  Everything is relative to the current step, so you don't have to query where the motor is positioned.

If you want to track the absolute position, look into position encoding motors (rotary encoders are popular).

For your case, you need to research 1 thing: how many steps does my motor complete in 1 revolution? Another way of asking this is: what is the angular resolution of my motor?

This post will take you the rest of the way: Arduino and stepper control

Where you see my code saying stepperX.step(500);, that's the command to take 500 steps.

If you want x number of degrees, you'll write the following:

numSteps = stepsPerRevolution * (desiredNumberOfDegrees / 360);
stepperX.step(numSteps);


问:
How does the strategy changes in a RobCup soccer competition without connection to outside?
How is a new team strategy during a robocup competition sent to each player of a robot team? Robots in the Standard Platform League (i.e. SPL), for example, are fully autonomous and there is no connection with non-team members (except pulling from the GameControl).</p>

答:
I will refer to the Standard Platform League (SPL) and the Humanoid Leagues (HL, e.g. Kid-Size). Both are robot soccer leagues with fully autonomous robots.

In this leagues, robots can utilize WiFi communication to either broadcast packages to their team members, or listen to GameController messages.

The GameControler provides information about the game state (e.g. ready (go to position), play). Thus, the robots can use the information provided by the GameController to have a strategy according to the game state, or according to the scored goals.

Broadcasted messages by other players reveal how many players may be active / taking part. Moreover, robots can inform other team mates when they get penelized (a robot conducted an illegal action, e.g., pushing another robot).

There are more dynamical strategies used in the SPL. According to the fact whether one robot is manipulating the ball, other robots may aim for a specific position in the vicinity (supporting).

Much work is done, but since most strategies are dependent on the WiFi coverage/robustness, just a few dynamic strategies are used so far during games, sicne WiFi reliability turns out to be low during competitions.
That means, packages may need several seconds to arrive. Even the chances to play a game without WiFi are high (happens partially to the SPL finals in 2014/2015). Most teams therefore tend to use static behaviour (e.g. players have a static position and react when the ball is in their vicinity).

Therefore, some teams aim to have a strategy WiFi independent (partially relying on vision) to overcome this gaps.

Short answer here: Most times, strategy is derived from communicated messages over the WiFi.

For further reading, I would recommend the SPL team description papers under the link provided.


问:
List of books similar to Thrun's Probabilistic Robotics for robot mechanics and manipulation

What?

Put together here a list of books (like the one for C/C++ on StackOverflow) that are spiritually similar to Sebastian Thrun's Probabilistic Robotics for robotic manipulation and mechanics.

Why?

Thrun's book is a wonderful resource for implementable algorithms while also dealing with the mathematics/theory behind them. In somewhat similar vein for robotic mechanics there is "A Mathematical Introduction to Robotic Manipulation - S.Sastry, Z.Li and R.Murray" which has a lot of mathematical/theoretical content. What is missing however in this book are the algorithms concerned with how should/would one go about implementing the theoretical stuff.

Requirements

Ideally list books dealing with diverse areas of robotics.

The books have to present algorithms like what Thrun does in his book.

Algorithms presented have to be language agnostic and as much as possible not be based on packages like MATLAB in which case they should be categorized appropriately.

答:
This is my go-to book for all things manipulation.  But it covers some other topics as well.
Robotics: Modelling, Planning and Control by Bruno Siciliano, Lorenzo Sciavicco, Luigi Villani, Giuseppe Oriolo.</p>


问:
Making a car go straight
I'm trying to work a car that's being controlled by an Arduino. I'm using the following chassis: New 2WD car chassis DC gear motor, wheels easy assembly and expansion and an L298N motor driver.

The problem is that it's hard to make the car go straight. Giving the same PWM value to the motors still makes them spin in different speeds, trying to calibrate the value is hard and every time I recharge my batteries the value changes.

What are my options on making the car go straight when I want (well, sometimes I'll want to turn it around of course)?

I've thought about using an encoder but I wish to avoid that since it will complicate the whole project, is there any other viable option? and even when using an encoder, Does it means I will need to keep track all the time and always adjust the motors value continuously? is there some built-in library for that?

答:
If you're driving a car down a road, even if that road is straight, you still need to use the steering wheel occasionally to keep the car on the road. This means looking at your surroundings to determine if you're drifting, and (somewhat) constantly interfacing with the steering wheel to adjust your heading.

If you want the vehicle to go straight, you need feedback. Mark Booth gives a great answer to a similar-ish question, but there that OP wanted to go in a straight line at a speed proportional to distance remaining.

I think the way I would consider approaching the problem would be to generate a PID controller using the difference in motor speeds as the reference and feedback channel. The output of the controller would be an adjustment you would add to one motor and subtract from the other.

Consider this pseudo-code:

```<code>vehicleSpeed = <joystickYAxis>;
steeringRef = <joystickXAxis>;
leftMotorSpeed = pollEncoder(leftMotor);
rightMotorSpeed = pollEncoder(rightMotor);

steeringFbk = leftMotorSpeed - rightMotorSpeed;
</code>```

So, at this point, steeringFbk is positive if the left motor is running faster than the right motor, which would indicate you're turning right. Now, to correct this, you would want something like:

```<code>steeringError = steeringRef - steeringFbk;

setMotorSpeed(leftMotor, vehicleSpeed + steeringError);
setMotorSpeed(rightMotor, vehicleSpeed - steeringError);
</code>```

So here steeringError is now a negative number (desired - actual), so you add that to the desired vehicle speed. This means that the left motor will be set to some value slightly under the desired speed and the right motor will be set to some value slightly over. This should correct the motor speeds such that the vehicle is now traveling straight.

A couple of notes -

Now you have a means to steer the vehicle. If you set steeringRef to a positive value the vehicle will turn left, and if you set it negative it will turn right.

The code I wrote above just uses (unmodified) proportional error to drive the steering. This will probably give less-than-satisfactory results; consider instead using a PID controller:

.

```<code>steeringError = steeringRef - steeringFbk;
steeringAdjustment = PID(steeringError,kP,kI,kD);
setMotorSpeed(leftMotor, vehicleSpeed + steeringAdjustment);
setMotorSpeed(rightMotor, vehicleSpeed - steeringAdjustment);
</code>```

Now, with PID gains, you can tune the system for the desired response time, overshoot, etc.

Title: Making a car go straight

Body:
If you're driving a car down a road, even if that road is straight, you still need to use the steering wheel occasionally to keep the car on the road. This means looking at your surroundings to determine if you're drifting, and (somewhat) constantly interfacing with the steering wheel to adjust your heading.

If you want the vehicle to go straight, you need feedback. Mark Booth gives a great answer to a similar-ish question, but there that OP wanted to go in a straight line at a speed proportional to distance remaining.

I think the way I would consider approaching the problem would be to generate a PID controller using the difference in motor speeds as the reference and feedback channel. The output of the controller would be an adjustment you would add to one motor and subtract from the other.

Consider this pseudo-code:

vehicleSpeed = <joystickYAxis>;
steeringRef = <joystickXAxis>;
leftMotorSpeed = pollEncoder(leftMotor);
rightMotorSpeed = pollEncoder(rightMotor);

steeringFbk = leftMotorSpeed - rightMotorSpeed;

So, at this point, steeringFbk is positive if the left motor is running faster than the right motor, which would indicate you're turning right. Now, to correct this, you would want something like:

steeringError = steeringRef - steeringFbk;

setMotorSpeed(leftMotor, vehicleSpeed + steeringError);
setMotorSpeed(rightMotor, vehicleSpeed - steeringError);

So here steeringError is now a negative number (desired - actual), so you add that to the desired vehicle speed. This means that the left motor will be set to some value slightly under the desired speed and the right motor will be set to some value slightly over. This should correct the motor speeds such that the vehicle is now traveling straight.

A couple of notes -

Now you have a means to steer the vehicle. If you set steeringRef to a positive value the vehicle will turn left, and if you set it negative it will turn right.

The code I wrote above just uses (unmodified) proportional error to drive the steering. This will probably give less-than-satisfactory results; consider instead using a PID controller:

.

steeringError = steeringRef - steeringFbk;
steeringAdjustment = PID(steeringError,kP,kI,kD);
setMotorSpeed(leftMotor, vehicleSpeed + steeringAdjustment);
setMotorSpeed(rightMotor, vehicleSpeed - steeringAdjustment);

Now, with PID gains, you can tune the system for the desired response time, overshoot, etc.


问:
How is homotopy used in planning algorithms?
What is an intuitive understanding for homotopy?  At what stage is homotopy (I understand it as stretching or bending of path) in a planning algorithm?  Is homotopy involved, for example, while implementing an algorithm like RRT?</p>

答:
Let me put homotopy into the context of planning algorithms

Suppose you want to get from point A to point B. Clearly, the easiest way is to traverse a straight line.  But if there is an obstacle in the way of this straight line path, what should you do?  If you want to obtain the "optimal" path (e.g. traversing the least total distance to the goal), you need only to travel in straight lines around the convex hull of the obstacle.  This forms a non-smooth, piecewise linear path.

However, sometimes the "path of least traversal" is not the best path to take or may even be infeasible.  For example, what if you don't have omni-directional wheels or it's just impossible to pivot in place (e.g. you have ackermann steering).  Then, instead of traversing the straight line path along the convex hull, you need find some other optimal way to move around the obstacle.  By using homotopy, you can continuously move away from the optimal straight line path (around the obstacle) to a smoother path around the obstacle that your robot can actually take.

More generally, homotopy allows you to relax the constraints of the original problem so that you can solve an easier problem that almost gives the best solution to the original problem.  The key "trick" is to parameterize the problem so that in the limit as the parameter approaches zero, you get closer and closer to the original problem such that for any non-zero choice of the parameter, the "perturbed" problem is easier to solve. This is a very powerful tool for many problems, especially optimization problems where discreteness or non-smoothness make it very difficult to solve.