Shop OBEX P1 Docs P2 Docs Learn Events
Flip and propellerC language; RESOLVED - Page 5 — Parallax Forums

Flip and propellerC language; RESOLVED

123578

Comments

  • kwinnkwinn Posts: 8,697
    iseries wrote: »
    Need to know what these values look like before sending them to the prop. Will have to encode them so that they can be send and will have to decode them once they are received by the prop. Can't really send binary data using serial.
    ...
    ......

    Mike

    What? I send binary data by serial in many projects. Single bytes for 0-255, two bytes for 0-65535, etc. The only decoding required is picking the desired bytes out of a string of bytes.
  • While sending binary data is fine doing so sometimes lead to issues with interpreting the data. That's why we have XML and JSON.

    Mike
  • will incorporate into the program and try soon. Thanks.
  • You wrote two posts which I believe are useful, unfortunately they aren't numbered so I will refer to the dates (1) 2020-03-19-02:52 and(2) 2020-03-30-02:47. I will the first and replace the second switch statement with the second but I not sure what to do with
    void getData(void *par) {[
    char data;
    
    hope you are in good health,
  • I was thinking of you the other day. The local weather man said that the space station was going to be visible in the sky.

    So at 8:12 we went outside and low and behold there was a bright light in the sky move very quickly across the sky.

    So if you wanted to take pictures of this you would have to fine tune your scope to follow something that fast across the sky. Your current setup I don't think is taking any of that into account.

    We may need to hook this thing up to a laptop or phone and be able to program in speed and direction so you can track just about anything.

    We could use the Parallax-ESP module and hook it up to your network and be able to control it with anything in your house. That would take a lot of work though but just a thought.

    Mike
  • Now back to your code. The second example assume we don't need to run a cog at all. As the serial data comes in we will just process it right along with the normal code. The PWM and Serial functions will run in the background without any assistance.

    There is a check to see if we have serial data and if we do we process it otherwise we just continue doing what were doing.

    All is well here. Hoping to start golfing soon so we can get out of the house.

    Mike
  • In actuality if there is serial then the camera will be in suspension and so will the tracking pulse, the serial is for moving from one target to another. How does the byte from the variables get used by the statements"pwm_set(RmotorPin, 0, 0)"; and " pwm_set(DmotorPin, 0, 0);".
  • From what I have gathered so far is that when you push a button on the remote it causes a I2C data stream to come into the Arduino board which right now consumes it. What we want to do is change it to send a serial byte to the Propeller chip which will intern generate the PWM pulse to the motors. When the serial data stops the motors stop.

    So the pwm_set(Motor, 0, 0) stop the pulses from being generated and thus stops the motors.

    I have read that some of the newer telescopes come with GPS and software so that once the telescope is setup they can input into the computer what they want to look at the telescope automatically moves it to the correct position knowing the location with the date and time. No more guessing at what star your looking at.

    Mike
  • when you push a button on the remote The internal arduino generates a pulse with one of four speeds and then transmits that signal to the propeller which passes that pulse to the pin 17 or pin 19 with the corresponding direction bit,pin 18 or pin 20. Shouldn't need the pwm_set(motor, 0, 0). to stop the pulse.

    Don't really care for the"go-to" systems. I'm old school. (1950)
  • The problem is that it doesn't just generate a pulse. It generates a continues stream of pulses every 2ms until you tell it to stop. This means the motor will continue to run even if you don't have a button pushed.

    So when you release the button we need some way of detecting that so we can stop the pulses.

    Mike
  • I am going to send you the existing files for the hand controller. I hope this gives a better idea of what's going on here.
  • Can a get a picture of the remote control that this program is attached to.

    Mike
  • no picture available have schematic and wire diagram. sending soon.
  • Looking at the program it looks like a 5 button unit with a one being the mode switch for speed control.

    When a button is pushed it sends a signal every 50mil seconds until you release it at which point it sends an all stop.

    Rather than using all the case statements I built a table.
    /**
     * @brief mode value 1 - 4
     * @brief direction 0 - none, 1 - west, 2 - north, 3 - east, 4 - south, 5 - reset
     */
    
    int RMotorValue[5][6] = {{0, 0, 0, 0, 0, -1}, // not used
                        {0, 100, 0, 100, 0, -1}, //mode 1
                        {0, 150, 0, 150, 0, -1}, //mode 2
                        {0, 200, 0, 200, 0, -1}, //mode 3
                        {0, 250, 0, 250, 0, -1}};//mode 4
    
    int DMotorValue[5][6] = {{0, 0, 0, 0, 0, -1}, // not used
                        {0, 0, 75, 0, 75, -1},   //mode 1
                        {0, 0, 100, 0, 100, -1}, //mode 2
                        {0, 0, 150, 0, 150, -1}, //mode 3
                        {0, 0, 200, 0, 200, -1}};//mode4
    
    
    void setup() {
      int mode, directionFlag;
    
      mode = 2;
      directionFlag = 3; // west
    
      RmotorPin = RMotorValue[mode][directionFlag];
      DmotorPin = DMotorValue[mode][directionFlag];
      
    
    }
    

    From the table values I see that the motors are set run at 50% to almost 100% with the DMotor running a little slower.

    If this moved the scope to fast I can see why. It might be simpler to use a starting value and then just multiple a mode factor which is really a speed factor being 1 slowest and 4 fastest.

    It looks like there are some path problems with the board layout. It looks like 5Volts is connected to ground on the Nano.

    Mike
  • The problem with the + to GND was due to the socket footprint which I redid. I don't wish to change the program for the hand controller so the question still is can I use the values in the serial to set the pwm.
  • Yes, the problem will be they are not scaled on the propeller.

    Here is the program to process the data. I don't like processing binary data but that what is being sent.
    #include "simpletools.h"
    #include "fdserial.h"
    
    
    #define RMOTOR 17
    #define RDIRECT 18
    #define DMOTOR 19
    #define DDIRECT 20
    #define FDRX 0
    #define FDTX 1
    
    fdserial *fd;
    char Buffer[32];
    int i;
    
    
    int main()
    {
     
      memset(Buffer, 0, sizeof(Buffer));  // clear the buffer
       
      fd = fdserial_open(FDRX, FDTX, 0, 115200);
    
      pwm_start(2000); // two millisceond pulse width
      
      low(RDIRECT);
      low(DDIRECT);
      pwm_set(RMOTOR, 0, 0); // full stop
      pwm_set(DMOTOR, 1, 0); // 0 - 2000 microseconds.
      i = 0;
      
      while(1)
      {
        while (fdserial_rxCount(fd) > 0)
        {
          Buffer[i++] = fdserial_rxChar(fd);
          Buffer[i] = 0;
        }      
        
        if (i > 0)
        {
          if (i == 4)
          {
            set_output(RDIRECT, Buffer[1]);
            set_output(DDIRECT, Buffer[3]);
            pwm_set(RMOTOR, 0, Buffer[0]); // 0 - 250
            pwm_set(DMOTOR, 0, Buffer[2]); // 0 - 200
          }
          i = 0;
        }
      }  
    }
    

    Mike
  • You know with my tank hardware you could move the telescope in any direction at varies speeds because it uses a gimbal and in two direction at the same time from your easy chair with one hand tied behind your back. Well I guess you would still have to look in the telescope to see if it's pointing at the right thing although you could project your camera on a TV screen.

    Mike
  • bbrienbbrien Posts: 561
    edited 2020-04-09 02:18
    Your'e right on the second part, I have a "live video feed" camera connected to a recording device(second video camera with a hard dick drive)., as well as a 7" monitor. I want to use your last post in conjunction with your" New approach". It successfully built , Now to test.
  • Just a suggestion, but if you haven't work with motors before or PWM you may want to get a servo and test your code out on that before you hook it up to something you could brake that's hard to replace.

    I would suggest one of these servos: Parallax 360.

    This unit works a little different than the motor driver does but still uses a PWM pulse to determine the speed.

    Just a thought.

    Mike
  • Iv'e been working with arduinos for several years now but they run too fast, maybe to high a frequency, and the motors are dc geared clock motors at 9 volts. I 'm trying to get the arduino to output on serial but I get no output on the serial monitor so I'm starting to look at I2C using the ard. as a slave.
  • iseriesiseries Posts: 1,435
    edited 2020-04-18 11:20
    According to the documentation pin 1 is transmit which is also hooked to the USB port on the Nano. So serial is already working and just needs to be connected. Since they share the USB port they both work at the same time.

    So pin1 on the Nano is hooked to pin 0 on the propeller and pin 1 on the propeller is hooked to pin 0 on the Nano based on the program I put together earlier otherwise whatever pins you want to use on the Propeller. Arduino can use other pins using software called soft serial otherwise these are the pin designed for serial data. The Propeller on the other hand can use any pins for serial data and you can choose which ones they are.

    Based on your schematic it would be pin 2 on J2 is transmit and pin 3 is receive which is not used at this time since the software does not return any data. Also both unit must share a ground pin otherwise there is no voltage reference and no signal. They don't need to share power.

    In my Tank project it uses two 6 volt dc geared motors to run the tracks and I have no issues with controlling the speed of the motors. I could have used a Nano to do the same thing it's just a matter of coding.

    The point here is use a setup that is not the final goal so you can play with the environment and see what works and what doesn't before you tackle the big project and get it wrong and possible break something.

    Mike

    PS:
    I just took a closer look at the Nano specs and this is a 5Volt unit and not a 3.3 volt unit. So you can't hook a Propeller pins to this unit because the volt coming out of the pins is too high. A resistor needs to be added between the pins to level shift the voltage from the Nano down to 3.3 volts on Propeller.
  • My problem right now is my nano is not outputting any info to the serial monitor and it worked when I used I2C. Right now my program is written for a arduino master.
  • I look at the documentation of the I2C and I am lost, I want to set up the master to poll or request the arduino to send four bytes of values to the master and the packets may be continuous.(see post number 1).
  • I2c is more complex then serial is in that the values sent determine what happens.

    I2C is based on one unit being the master. The master must generate the clock. The data line on the other hand is bidirectional and can go either way. So most devices require the master to send an address with bit number 0 set to 1 for read and 0 for write.

    So you need to send the address value with bit 0 set to 1 and then clock the data as 4 8 bit bytes or one 32 bit value.

    The problem is I don't know if the keypad is the master or some other device.

    Arduino has this exact configuration explained along with the code here: Tutorial MasterReader.

    Mike
  • The master will have to be the flip board since the propellers can only be masters as someone has told me. The arduino will have to become a slave even though it was written as the master. It has five buttons on the keypad , four directional and one for the speed. The original code sent four bytes of data.
    Wire.beginTransmission(address);
    Wire.write(RmotorPinI2C);
    Wire.write(RdirPinI2C);
    Wire.write(DmotorPinI2C);
    Wire.write(DdirPinI2C);
    Wire.endTransmission);
    
  • I think I see why your serial data is not working.

    There should only be on Serial.begin(115200) in the setup section. This starts up serial with the correct baud rate.

    In your code you have it as 11500 which will not work.

    For the serial routine it should be as fallows:
     void sendSerialData()
       {
         Serial.write(RmotorPin);
         Serial.write(RdirPin);
         Serial.write(DmotorPin);
         Serial.write(DdirPin);
       }
    

    This should work to output the serial data on the screen and out to the Propeller, but remember this is binary data and will look like garbage on the screen.

    You could change the Serial.write to Serial.print to see the values on the screen to test.

    Mike
  • Making the Propeller the master is not going to work. The problem is that the Arduino is scanning the buttons every 50 milliseconds and it is in control of that. The Propeller on the other hand must ask for data from the Arduino but it maybe old data or there maybe lost data as it may have scanned in between the requests. Losing the release for example will cause the telescope to continue moving.

    We would have to turn the Arduino code into a keyboard program where it would store the events such as key up and key down and then be able to pass them along without loss of these events like a keyboard buffer. This will require some changes to the Arduino code.

    Mike
  • Using some parts I had laying around I put together this hardware to show how the Propeller can move to servos using a push button control similar to what you are trying to build.

    While the servos work differently compared to DC motors they are similar in how they move based on the PWM pulse applied to them.

    Here is a video of the working code: Push Button Controller.
    #include "simpletools.h"
    
    #define UPDOWN 0
    #define LEFTRIGHT 16
    #define SW1 15
    #define SW2 8
    #define SW3 14
    #define SW4 9
    #define SW5 13
    #define SW6 10
    #define LED12 12
    #define LED34 11
    
    int ud = 1220;
    int lr = 1220;
    int sd = 10;
    int i;
    int p;
    
    int main()
    {
      pwm_start(20000);
      pwm_set(UPDOWN, 0, ud);
      pwm_set(LEFTRIGHT, 1, lr);
    
     
      while(1)
      {
        i = input(SW1) | input(SW2) << 1 | input(SW3) << 2 | input(SW4) << 3 | input(SW5) << 4 | input(SW6) << 5;
        if ((i & 1) == 0)
          ud += sd;
        if ((i & 2) == 0)
          ud -= sd;
        if ((i & 8) == 0)
          lr -= sd;
        if ((i & 32) == 0)
          lr += sd;
        if ((i & 16) == 0)
        {
          if (p == 0)
            sd += 10;
          if (sd > 40)
            sd = 10;
          p = 1;
        }
        else
          p = 0;
        
        switch (sd)
        {
          case 10 : high(LED12);
               high(LED34);
          break;
          case 20 : high(LED12);
               low(LED34);
          break;
          case 30 : low(LED12);
               high(LED34);
          break;
          case 40 : low(LED12);
               low(LED34);
          break;
          default:
          break;
        }
     
        if (ud > 2450)
          ud = 2450;
        if (ud < 450)
          ud = 450;
        if (lr > 2450)
          lr = 2450;
        if (lr < 450)
          lr = 450;
        pwm_set(UPDOWN, 0, ud);
        pwm_set(LEFTRIGHT, 1, lr);
         
        pause(50);
      }  
    }
    

    The servos receive a pulse every 20 milliseconds with the pulse lasting not more than 2450 microseconds. DC motors don't work this way. With DC motors the pulse determines the amount of power delivered to the motor and voltage determining what direction they move in.

    Mike
  • bbrienbbrien Posts: 561
    edited 2020-04-20 22:00
    cannot use servos in the current setup as I would have to manufacture a whole new gearbox assembly. It would be too costly to attempt anything like that. I have to use it the way it is designed. You can go to MEADE INSTRUMENTS.COM and look at a LX200 which is similar to the LX50.
  • The purpose of the demonstration was to show that the Propeller can do all the things your project needs to do.

    1) Get data from push buttons.
    2) Light LED's based on push buttons to determine speed.
    3) Control the PWM output to two motors (servos) at varying speeds.

    The program could be modified to control two DC motors as well.

    Mike
    1920 x 1080 - 550K
Sign In or Register to comment.