CM-510 as a multiple sensor dynamixel item (updated 21/03/2014)

This entry is part 3 of 3 in the series Programming Robotis Bioloid hardware

[UPDTATE 21/03/2014] TossModeJCA v6.5. More information and examples at (I) Reading sensors connected to Robotis CM-510. Here you have the source files.

New functions added:

#define F_GET_BATTERY_MILLIVOLTS 6
Get the current battery voltage

#define F_SET_BATTERY_LOW_LEVEL_THRESHOLD 20
Set low battery warning (two red led will be on, PLAY and AUX)

#define F_SET_BATTERY_VERY_LOW_LEVEL_THRESHOLD 21
Set VERY low battery warning, all leds on

Apart from toss commands to Dynamixel devices, All the functions CM-510 could perform are:

#define F_NO_FUNCTION  0
No function, only to initialize values

#define F_GET_SENSOR_VALUE_RAW  1
Read sensor value

#define F_GET_TWO_DMS_SENSOR_VALUES 2
[Experimental] Read 2 sensor values in one query and one answer

#define F_GET_MULTIPLE_SENSOR_VALUE 3
[Experimental] Read several sensor values in one query and one answer

#define F_GET_SENSOR_VALUE_FILTERED  4
Read sensor value, avoiding maximum and minimum values

#define F_SET_SENSOR_VALUES_TO_FILTER 5
Number of readings that will be filtered

#define F_GET_BATTERY_MILLIVOLTS 6
Get the current battery voltage

#define F_SET_BATTERY_LOW_LEVEL_THRESHOLD 20
Set low battery warning (two red led will be on, PLAY and AUX)

#define F_SET_BATTERY_VERY_LOW_LEVEL_THRESHOLD 21
Set VERY low battery warning, all leds on

#define F_BEEP 8
If there is a buzzewr it beep, if no buffer it blinks

#define F_DO_SENSOR_SCAN 9
[Experimental!!!] Using servo ID 13 runds from 300 to 700 reading and return servo por where max value read

#define F_SET_VALUE_DMS1Port 11
Set the port for the first sensor

#define F_SET_VALUE_DMS2Port 12
Set the port for the second sensor

[UPDATE 7/11/13: CM_510 TossModeJCA updated to v5.8. Several parameters error fix and somewhat faster]

My main Bioloid project is to build a robot that will have some interesting (non easily predictable but reasonable) behaviours. AntOne 3.6 is the last version:

AntOne 3.6 is based on a PDA that has the software for the behaviour and a CM-510 (ATMega 2561) that control the hardware (servos and sensors). But I discovered that standard CM-510 firmware has no command to get sensor values, so I programmed another with that function. But then I thought that it would be interesting to embed some perception functions in the CM-510.

This is a general diagrama:

Single controller

Single controller

Updated 23/2/2013

The new hex file v4.3 (the old CM-510 firmware)

Now it supports new functions, as:

– Toss Mode (up) now can read from Dynamixel and write to serial and, as the previous version, read from serial and write to Dynamixel, it allows to….
– receive from zigbee and send the data to the Dynamixel bus
– read raw sensor values
– averaged sensor values when F_SET_SENSOR_VALUES_TO_FILTER is set < 5, not including the min and the max when >= 5
– CM-510 beep
– sensor scan (still in development)

#define F_NO_FUNCTION 0
#define F_GET_SENSOR_VALUE_RAW 1
#define F_GET_TWO_DMS_SENSOR_VALUES 2
#define F_GET_MULTIPLE_SENSOR_VALUE 3
#define F_GET_SENSOR_VALUE_FILTERED 4
#define F_SET_SENSOR_VALUES_TO_FILTER 5

#define F_BEEP 8
#define F_DO_SENSOR_SCAN 9
#define F_SET_VALUE_DMS1 11
#define F_SET_VALUE_DMS2 12

C# example os use:

       private void B_ReadPort_Click(object sender, EventArgs e)
        {
            byte function = (byte)NUD_Function.Value;
            byte portId = (byte)NUD_Port.Value;

            if (portId &amp;lt; 0 || portId &amp;gt; 6)
                portId = 1;

            string strPortId=portId.ToString();

            if (function == 1 || function == 4)
            {
                short portValue = cm510.getSensorValue(function, portId);
                string str = portValue.ToString();

                TB_PortValue.Text = str;
            }
            else
            {
                if (function == 2)
                {
                    byte[] parameters = new byte[3];
                    parameters[0] = function;
                    parameters[1] = Convert.ToByte(TB_DMS1_ID.Text);
                    parameters[2] = Convert.ToByte(TB_DMS2_ID.Text);

                    short[] values = new short[3];
                    cm510.getMultipleSensorValue(parameters, values);
                    //cm510.getTwoSensorValue(function, Convert.ToByte(TB_DMS1_ID.Text), Convert.ToByte(TB_DMS2_ID.Text), values);

                    if (values.Length &amp;gt;= 2)
                    {
                        TB_DMS1_PortValue.Text = values[1].ToString();
                        TB_DMS2_PortValue.Text = values[2].ToString();
                    }
                }
                else
                {
                    if (function == 3)
                    {
                        byte[] parameters = new byte[3];
                        parameters[0] = function;
                        parameters[1] = Convert.ToByte(TB_DMS1_ID.Text);
                        parameters[2] = Convert.ToByte(TB_DMS2_ID.Text);

                        short[] values = new short[3];
                        cm510.getMultipleSensorValue(parameters, values);

                        if (values.Length &amp;gt;= 2)
                        {
                            TB_DMS1_PortValue.Text = values[1].ToString();
                            TB_DMS2_PortValue.Text = values[2].ToString();
                        }
                    }
                    else
                    {
                        if (function == 11)
                        {
                            TB_DMS1_ID.Text = strPortId;
                        }
                        else
                        {
                            if (function == 12)
                            {
                                TB_DMS2_ID.Text = strPortId;
                            }
                        }
                    }
                }
            }
        }

Series Navigation<< Learning scurves with AX-12

10 comments on “CM-510 as a multiple sensor dynamixel item (updated 21/03/2014)

  1. jesse says:

    I am unable to get you firmware loaded onto the CM-510. I’m using the Roboplus Terminal to try to transmit the file. With the CM-510 power off I connect with the terminal program, hold Shift-3 to get into the boot loader and then choose ‘Transmit File’ from the ‘Files’ menu to transmit the TossModeJCA.hex file. While the terminal echos the file being transmitted there are numerous lines claiming that there is a “Bad Command”. I would have included the output from the terminal, but they’ve used a control that apparently doesn’t allow text selection. Any help you could provide would be great.

  2. jose says:

    I think you missed the load command, typing “l” and [Enter] before ‘Transmit file” You can see it at

    http://support.robotis.com/en/techsupport_eng.htm#software/embeded_c/cm510_cm700/programming/bootloader/program_install.htm

  3. jesse says:

    Thank you, that was indeed the problem. Works as advertised now. Thanks again.

    • jose says:

      I think that you would need this example:

             
      private static int getSensorValueCommand(byte[] buffer, byte function, byte port)
              {
                  int pos = 0;
                  buffer[pos++] = 0xff;   // header
                  buffer[pos++] = 0xff;   // header
                  buffer[pos++] = idCM510;   // CM510 ID=200            
                  buffer[pos++] = 0x04;   // length
                  buffer[pos++] = 0x02;   // instruction 2 = read            
                  buffer[pos++] = function;    // function = 1
                  buffer[pos++] = port;    // port
                  byte checksum = Util.checkSumatory(buffer, pos);
                  buffer[pos++] = checksum;
      
                  return pos;
              }
      
  4. Nikolai says:

    Hi Jose,

    thanks for all the Bioloid samples on your site! I am trying to control dynamixels via CM-510 from my PC (via a serial link to USB2Dynamixel connected to PC). I wonder if I need a “special” firmware for this or if the standard Robotis firmware has a “toss mode”? Do you I need to reflash teh firmware to have this toss mode or not?
    Thanks!

    • jose says:

      Hi, Nikolai

      The standard Robotis firmware already has the Toss Mode, then you can connect your PC to the CM-510 (or CM-5) with the serial cable. If you don’t havea serial port in your PC you can use the USB2Dynamixel as USB to serial converter, REMEMBER to change the USB2Dynamixel little switch!

      But if you have a USB2Dynamixel you only need the CM-510 for powering your Dynamixels, using the USB2Dynamixel for sending the commands to them 🙂

  5. Aurelien says:

    Hi, the link for the firmware is dead. Any chance of update? 😉 Thanks!

%d bloggers like this: